Skip to main content

dynamic, declarative data transformations with automatic code generation

Project description

convtools

convtools is a specialized Python library designed for defining data transformations dynamically using a declarative approach. It automatically generates custom Python code for the user in the background.

ChatGPT's take on it :)

Introducing ConvTools, the revolutionary Python library for dynamic data
transformations! With its declarative approach, transforming data has never
been easier. Say goodbye to manual coding, ConvTools automatically
generates the code for you, saving you time and effort. Whether you're
working with large datasets or need to make real-time updates, ConvTools is
the solution you've been searching for. Get ready to experience the power
of efficient and effortless data transformation!

License codecov Tests status Docs status PyPI Twitter Downloads Python versions


Installation

pip install convtools

Documentation

convtools.readthedocs.io

Group by example

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``.

What's the point if there are tools like Pandas / Polars?

  • convtools doesn't need to wrap data in a container to provide functionality, it simply runs the python code it generates on any input
  • convtools is lightweight (though optional black is highly recommended for pretty-printing generated code out of curiosity)
  • convtools fosters building pipelines on top of iterators, allowing for stream processing
  • convtools supports nested aggregations
  • convtools is a set of primitives for code generation, so it's just different.

Reporting a Security Vulnerability

See the security policy.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

convtools-1.1.1.tar.gz (57.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

convtools-1.1.1-py3-none-any.whl (64.8 kB view details)

Uploaded Python 3

File details

Details for the file convtools-1.1.1.tar.gz.

File metadata

  • Download URL: convtools-1.1.1.tar.gz
  • Upload date:
  • Size: 57.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.3

File hashes

Hashes for convtools-1.1.1.tar.gz
Algorithm Hash digest
SHA256 f29ade10f91303d865ff44838c1a229cfea04e65e9ce5a9b53f7e7b5a9aac025
MD5 66ba2c8dc1ea69571291704f67672dea
BLAKE2b-256 622477c60ef73fe388333b75a4a62b50b34909553c1c211450d2a61f2926f9fc

See more details on using hashes here.

File details

Details for the file convtools-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: convtools-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 64.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.3

File hashes

Hashes for convtools-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 46ffd2a45fdbed319bc7311c643f7cc19bab9dc53055d0e4bdc28abcd7775c88
MD5 94aa89b3bc22aa20b0ecf11bf00a7153
BLAKE2b-256 c306963091c1d1a2d5a366edc0fb3e5582b2ea141644eb24b0468e2069c300b6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page