Skip to main content

dynamic, declarative data transformations with automatic code generation

Project description

convtools

convtools is a Python library that simplifies data transformation by allowing you to define them in a declarative way. It then generates the necessary Python code in the background, saving you time and effort.

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.

Contributing

The best way to support the development of convtools is to spread the word!

Also, if you already are a convtools user, we would love to hear about your use cases and challenges in the Discussions section.

To report a bug or suggest enhancements, please open an issue and/or submit a pull request.

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.14.3.tar.gz (132.2 kB view details)

Uploaded Source

Built Distributions

convtools-1.14.3-cp310-abi3-win_amd64.whl (97.6 kB view details)

Uploaded CPython 3.10+ Windows x86-64

convtools-1.14.3-cp310-abi3-musllinux_1_2_x86_64.whl (98.7 kB view details)

Uploaded CPython 3.10+ musllinux: musl 1.2+ x86-64

convtools-1.14.3-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (98.9 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

convtools-1.14.3-cp310-abi3-macosx_11_0_arm64.whl (94.1 kB view details)

Uploaded CPython 3.10+ macOS 11.0+ ARM64

convtools-1.14.3-cp310-abi3-macosx_10_9_x86_64.whl (93.8 kB view details)

Uploaded CPython 3.10+ macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: convtools-1.14.3.tar.gz
  • Upload date:
  • Size: 132.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for convtools-1.14.3.tar.gz
Algorithm Hash digest
SHA256 26dca320b0897b9df93c2b182ef39af09497ccfe9e464f1b36381a289d72a9a6
MD5 4b6f140e5888f6e27519720869e3444e
BLAKE2b-256 547a0d449f843759b1f4e6e76a617ef8434c280d468b8c2522f9dbe72181396a

See more details on using hashes here.

File details

Details for the file convtools-1.14.3-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for convtools-1.14.3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c55aa8c6b64cfb68999c4d6c9c9c8ec82411360e2b5cf79ef5f0473b98026388
MD5 7b6171e96f902da61a561bfcb223d194
BLAKE2b-256 4407660489b42c0fec36b221a68e52cc4841fdc9c7e73b3d0cc535c5208990b9

See more details on using hashes here.

File details

Details for the file convtools-1.14.3-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for convtools-1.14.3-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5f0ab03ba803965f05d88d8fa436b7a63fe605669f52ccbab1036c8d0cfd83a7
MD5 783a9140760b1118add4975488c66eda
BLAKE2b-256 abd038bad37b61f2d00c297e076442bd67314475ba191131774f1ecc158fb507

See more details on using hashes here.

File details

Details for the file convtools-1.14.3-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for convtools-1.14.3-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e4ee09a175529a080135870003fc732f72e45ca5793d1e91a37d288aec3fa5f3
MD5 18e28fb32874b106e3d0c5bcff9cb503
BLAKE2b-256 5a4e0d10e307031ea20789db9734cc9d9dc9bd94f48f096c7de57c4c359e65f8

See more details on using hashes here.

File details

Details for the file convtools-1.14.3-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for convtools-1.14.3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7256ec584bcc76fa459215cd4a4cc0af70b17d900d74956ebb2a70dc8d7b5bc4
MD5 4898f256cf239f6f46034e201f14e894
BLAKE2b-256 706c0564f9d51d819ff3f217a9208adb1902fb836f0e76a0f274d36a2e629ded

See more details on using hashes here.

File details

Details for the file convtools-1.14.3-cp310-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for convtools-1.14.3-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ab06079c3461d6bb3202591b9e4c01bf40d02e6aaa0ebd5ed0f791a4956a1cb6
MD5 70b3c8ac4621a9aa0ff7a25c12d18f83
BLAKE2b-256 9a37d46e305182e5df878f55bf8a4814fda3f6e587810469ccb860a46b2b461d

See more details on using hashes here.

Supported by

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