Skip to main content

dynamic, declarative data transformations with automatic code generation

Project description

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 codecov Tests status Docs status PyPI Downloads Python versions

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

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

Built-in reducers are exposed as c.ReduceFuncs.*:

  • Value reducers: Array, ArrayDistinct, ArraySorted, Average, Correlation, Count, CountDistinct, Covariance, First, FirstN, Last, LastN, Max, MaxRow, Median, Min, MinRow, Mode, Percentile, PopulationStdDev, PopulationVariance, StdDev, Sum, SumOrNone, TopK, Variance
  • Dict reducers: Dict, DictArray, DictArrayDistinct, DictCount, DictCountDistinct, DictFirst, DictFirstN, DictLast, DictLastN, DictMax, DictMin, DictSum, DictSumOrNone

Dict reducers aggregate into dictionaries whose values are reduced per key. For reducer arguments, defaults, None handling, and examples, see Aggregations.

You can also define custom reducers with c.reduce by passing any two-argument reduce function.


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

Uploaded Source

Built Distributions

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

convtools-1.17.1-cp314-cp314t-win_amd64.whl (104.9 kB view details)

Uploaded CPython 3.14tWindows x86-64

convtools-1.17.1-cp314-cp314t-musllinux_1_2_x86_64.whl (112.1 kB view details)

Uploaded CPython 3.14tmusllinux: musl 1.2+ x86-64

convtools-1.17.1-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (112.4 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

convtools-1.17.1-cp314-cp314t-macosx_11_0_arm64.whl (101.6 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

convtools-1.17.1-cp314-cp314t-macosx_10_15_x86_64.whl (101.3 kB view details)

Uploaded CPython 3.14tmacOS 10.15+ x86-64

convtools-1.17.1-cp310-abi3-win_amd64.whl (104.4 kB view details)

Uploaded CPython 3.10+Windows x86-64

convtools-1.17.1-cp310-abi3-musllinux_1_2_x86_64.whl (106.1 kB view details)

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

convtools-1.17.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (106.1 kB view details)

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

convtools-1.17.1-cp310-abi3-macosx_11_0_arm64.whl (101.2 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

convtools-1.17.1-cp310-abi3-macosx_10_9_x86_64.whl (100.8 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: convtools-1.17.1.tar.gz
  • Upload date:
  • Size: 148.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for convtools-1.17.1.tar.gz
Algorithm Hash digest
SHA256 b810c9b58e5f7f524e2c90ef0f63e6838747df9d9c3826e3fbaeaff79bdf720e
MD5 83a9037398bec87150c5cfe82d62126d
BLAKE2b-256 80b2349e298f7cc7c318820a326a6977b404ea0bf84f9b7c67f1a6df6724c5f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for convtools-1.17.1.tar.gz:

Publisher: pytest.yml on westandskif/convtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file convtools-1.17.1-cp314-cp314t-win_amd64.whl.

File metadata

  • Download URL: convtools-1.17.1-cp314-cp314t-win_amd64.whl
  • Upload date:
  • Size: 104.9 kB
  • Tags: CPython 3.14t, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for convtools-1.17.1-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 f741e3631515b64dbaf86491fbc842031f7c22ee7e9f94578878e0e9ee17cfc1
MD5 f9c29e98c338f1f2b59b4bca287120a8
BLAKE2b-256 ca53bd29959cbb322da7482e9e16725d231dee27c8c64323b52e08a51a0e5da5

See more details on using hashes here.

Provenance

The following attestation bundles were made for convtools-1.17.1-cp314-cp314t-win_amd64.whl:

Publisher: pytest.yml on westandskif/convtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file convtools-1.17.1-cp314-cp314t-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for convtools-1.17.1-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d7180567797305323cbbd1235c8596155504d29aa7a2402bc46de41b9fdd05e6
MD5 4288d001034fc154afb458ab7b4222b9
BLAKE2b-256 f4d4554543322ed2088605bcd21173e27d23c07bc1ca93114e2a819e72c71049

See more details on using hashes here.

Provenance

The following attestation bundles were made for convtools-1.17.1-cp314-cp314t-musllinux_1_2_x86_64.whl:

Publisher: pytest.yml on westandskif/convtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file convtools-1.17.1-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for convtools-1.17.1-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 6815fe24bdef1f019696c16c396d964fe93be4cc83cf7218ed306779fc8ef93b
MD5 c7706fb486855a63ce8703d8020406b4
BLAKE2b-256 b5bd334516c07f076dd0773f5cdba205205ee4869975fe91ae3f4967231a0d51

See more details on using hashes here.

Provenance

The following attestation bundles were made for convtools-1.17.1-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: pytest.yml on westandskif/convtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file convtools-1.17.1-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for convtools-1.17.1-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 32929081b090ea919b6bbac75833611e6993d147fb64e3597d1ba13e8278a4f3
MD5 b850f229a42e5c9b18ddf4a4288013bd
BLAKE2b-256 7154bf697ebdd49c121a465137b1bcafdf39747e58671feca5bb8729b86db0fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for convtools-1.17.1-cp314-cp314t-macosx_11_0_arm64.whl:

Publisher: pytest.yml on westandskif/convtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file convtools-1.17.1-cp314-cp314t-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for convtools-1.17.1-cp314-cp314t-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 1751879b5ce554f9c1df6c43d6759ee20d59b604917238ccced7135c35ba6be1
MD5 51bc9f32ae264ca24524a629d2d43925
BLAKE2b-256 ce4e905908595b42f08e8c93264c6a66ec723ce0636b8b6327dab974420d5e2a

See more details on using hashes here.

Provenance

The following attestation bundles were made for convtools-1.17.1-cp314-cp314t-macosx_10_15_x86_64.whl:

Publisher: pytest.yml on westandskif/convtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: convtools-1.17.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 104.4 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for convtools-1.17.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2d0043d60eba4af5e207c664b428579b2a95f3ff029b15beb897ff056a4f28ed
MD5 3e099d4098b401ecb593c390e8a41df3
BLAKE2b-256 59dcf7964a649fe825d7e2112304a5f9877a37be7acb4bcebdf7a0e974d6c3fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for convtools-1.17.1-cp310-abi3-win_amd64.whl:

Publisher: pytest.yml on westandskif/convtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for convtools-1.17.1-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1741a9ae7f301024301611022a964012049a1d79bb9af82fdd81da31cf6e4cdf
MD5 353b50b97c8646d1734cc3ad4078194d
BLAKE2b-256 1dae66384cbbef06ee1e44bda0f18bca32861434e0c45b04fbe8929e510851c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for convtools-1.17.1-cp310-abi3-musllinux_1_2_x86_64.whl:

Publisher: pytest.yml on westandskif/convtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file convtools-1.17.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for convtools-1.17.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 24000c6557c0ac287d5b381519b31d8422d09affaf34829abc8601e8bd09a3be
MD5 b92ee82e6c34c2fd8ff9de05a5d42591
BLAKE2b-256 2b39d3801ae97763093fb0369cb0d9251497ee7bb8a192810c0673de953c2e63

See more details on using hashes here.

Provenance

The following attestation bundles were made for convtools-1.17.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: pytest.yml on westandskif/convtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for convtools-1.17.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 32ac3fc96d4ca5e05b8d73b245688e7b9ee7f35b36e1c0520635447a0f21f579
MD5 6df706f03e9df732c5f7409a6e07ada9
BLAKE2b-256 9a56bc35a244080eaf5558d3ea8414aaed04c8ebfb9daef0be9f2fdfa0fabd30

See more details on using hashes here.

Provenance

The following attestation bundles were made for convtools-1.17.1-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: pytest.yml on westandskif/convtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for convtools-1.17.1-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a6b8da00700b841b0777c57e546e6f93fd5da26217091d10452d0c0f89d2242a
MD5 e440c2936b17015dbd3efcd9a87cd150
BLAKE2b-256 db358ef76f2e840bf5fcf9b3bf266f89b1dc2a4dc9628962b994cee5096df3ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for convtools-1.17.1-cp310-abi3-macosx_10_9_x86_64.whl:

Publisher: pytest.yml on westandskif/convtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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