Metadata-Version: 2.4
Name: convtools
Version: 1.14.8
Summary: dynamic, declarative data transformations with automatic code generation
Author-email: Nikita Almakov <nikita.almakov@gmail.com>
Maintainer-email: Nikita Almakov <nikita.almakov@gmail.com>
License: The MIT License (MIT)
        
        Copyright (c) 2021 Nikita Almakov
        
        Copyright (c) 2020 iTechArt Group
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: homepage, https://github.com/westandskif/convtools
Project-URL: documentation, https://convtools.readthedocs.io/en/latest/
Project-URL: repository, https://github.com/westandskif/convtools
Project-URL: changelog, https://github.com/westandskif/convtools/blob/master/docs/CHANGELOG.md
Keywords: etl,converters,codegen,convtools
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Code Generators
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: astunparse==1.6.3; python_version < "3.9"
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Requires-Dist: pytest-benchmark; extra == "test"
Provides-Extra: lint
Requires-Dist: black; extra == "lint"
Requires-Dist: flake8; extra == "lint"
Requires-Dist: isort; extra == "lint"
Requires-Dist: mypy; extra == "lint"
Requires-Dist: pylint; extra == "lint"
Provides-Extra: doc
Requires-Dist: markdown-include; extra == "doc"
Requires-Dist: mdx-truly-sane-lists; extra == "doc"
Requires-Dist: mkdocs; extra == "doc"
Requires-Dist: mkdocs-exclude; extra == "doc"
Requires-Dist: mkdocs-material; extra == "doc"
Requires-Dist: pygments; extra == "doc"
Requires-Dist: pymdown-extensions; extra == "doc"
Dynamic: license-file

# convtools — write transformations as expressions, run them as Python

**convtools** lets you declare data transformations in plain Python, then
compiles them into tiny, optimized Python functions at runtime. You keep your
data in native iterables (lists, dicts, generators, CSV streams)—no heavy
container required.

[![License](https://img.shields.io/github/license/westandskif/convtools.svg)](https://github.com/westandskif/convtools/blob/master/LICENSE.txt)
[![codecov](https://codecov.io/gh/westandskif/convtools/branch/master/graph/badge.svg)]( https://codecov.io/gh/westandskif/convtools)
[![Tests status](https://github.com/westandskif/convtools/workflows/tests/badge.svg)](https://github.com/westandskif/convtools/actions/workflows/pytest.yml)
[![Docs status](https://readthedocs.org/projects/convtools/badge/?version=latest)](https://convtools.readthedocs.io/en/latest/?badge=latest)
[![PyPI](https://badge.fury.io/py/convtools.svg)](https://pypi.org/project/convtools/)
[![Twitter](https://img.shields.io/twitter/url?label=convtools&style=social&url=https%3A%2F%2Ftwitter.com%2Fconvtools)](https://twitter.com/convtools)
[![Downloads](https://static.pepy.tech/badge/convtools)](https://pepy.tech/project/convtools)
[![Python versions](https://img.shields.io/pypi/pyversions/convtools.svg)](https://pypi.org/project/convtools/)

### Why pick convtools?

  * **Stay in Python.** Compose transformations as expressions: pipes, filters,
  joins, group‑bys, reducers, window functions, and more. Then call
  `.gen_converter()` to get a real Python function.
  * **Stream‑friendly.** Works directly on iterators and files; the Table
  helper processes CSV‑like data without loading everything into memory.
  * **Powerful aggregations.** Rich reducers (Sum, CountDistinct, MaxRow,
  ArraySorted, Dict*, TopK…) with per‑reducer `where` filters and defaults.
  Nested aggregations are first‑class.
  * **Debuggable & inspectable.** Print the generated code with `debug=True` or
  set global options via `c.OptionsCtx`. Works with `pdb`/`pydevd`.
  * **Plays nicely with Pandas/Polars.** It’s not a DataFrame; it’s a
  code‑generation layer. Use it when you want lean, composable transforms over
  native Python data.

____

### Installation

```
pip install convtools
```

## Documentation

**[convtools.readthedocs.io](https://convtools.readthedocs.io/en/latest/)**


## Group by example

```python
from convtools import conversion as c

input_data = [
    {"a": 5, "b": "foo"},
    {"a": 10, "b": "foo"},
    {"a": 10, "b": "bar"},
    {"a": 10, "b": "bar"},
    {"a": 20, "b": "bar"},
]

conv = (
    c.group_by(c.item("b"))
    .aggregate(
        {
            "b": c.item("b"),
            "a_first": c.ReduceFuncs.First(c.item("a")),
            "a_max": c.ReduceFuncs.Max(c.item("a")),
        }
    )
    .pipe(
        c.aggregate({
            "b_values": c.ReduceFuncs.Array(c.item("b")),
            "mode_a_first": c.ReduceFuncs.Mode(c.item("a_first")),
            "median_a_max": c.ReduceFuncs.Median(c.item("a_max")),
        })
    )
    .gen_converter()
)

assert conv(input_data) == {
    'b_values': ['foo', 'bar'],
    'mode_a_first': 10,
    'median_a_max': 15.0
}

```

##### Built-in reducers like `c.ReduceFuncs.First`
    * Sum
    * SumOrNone
    * Max
    * MaxRow
    * Min
    * MinRow
    * Count
    * CountDistinct
    * First
    * Last
    * Average
    * Median
    * Percentile
    * Mode
    * TopK
    * Array
    * ArrayDistinct
    * ArraySorted

    DICT REDUCERS ARE IN FACT AGGREGATIONS THEMSELVES, BECAUSE VALUES GET REDUCED.
    * Dict
    * DictArray
    * DictSum
    * DictSumOrNone
    * DictMax
    * DictMin
    * DictCount
    * DictCountDistinct
    * DictFirst
    * DictLast

    AND LASTLY YOU CAN DEFINE YOUR OWN REDUCER BY PASSING ANY REDUCE FUNCTION
    OF TWO ARGUMENTS TO ``c.reduce``.

---


### When should I reach for convtools?

* You need **composable transforms** over native Python data
(lists/dicts/generators/CSV), not a DataFrame.
* You want to **express business rules declaratively** and generate fast,
readable Python functions.
* You need **aggregations/joins/pipes** that you can **reuse** across scripts
and services.

---

### Contributing

* Star the repo and share use‑cases in Discussions -- it really helps.

* To report a bug or suggest enhancements, please open [an
issue](https://github.com/westandskif/convtools/issues) and/or submit [a pull
request](https://github.com/westandskif/convtools/pulls).

* **Reporting a Security Vulnerability**: see the [security
policy](https://github.com/westandskif/convtools/security/policy).
