Skip to main content

A Python package for reducing mapping-like objects using reducer objects, implemented in Rust.

Project description

dict-sourcer

Build for PyPi

docker run --rm -v "$(pwd)":/ci quay.io/pypa/manylinux2014_x86_64 /ci/build.sh pypi_publish.sh

or

python setup.py sdist bdist_wheel

export TWINE_USERNAME=__token__
export TWINE_PASSWORD=<password>

twine upload target/wheels/*

Notice

When upgrading version should be changes in:

  • setup.py
  • Cargo.toml
  • pyproject.toml

Example use

from event_sourcer import reduce_dict

class SumReducer:
    def init(self):
        return 0
    def update(self, acc, value):
        return acc + value
    def finalize(self, acc):
        return acc

class AvgReducer:
    def init(self):
        return (0, 0)  # (total, count)
    def update(self, acc, value):
        total, count = acc
        return (total + value, count + 1)
    def finalize(self, acc):
        total, count = acc
        return total / count if count else None

# Any object supporting __getitem__ will work; here we use dicts.
def generate_objects():
    yield {"a": 1, "b": 4}
    yield {"a": 1, "c": 4}

reducers = {
    "a": SumReducer(),
    "b": AvgReducer(),
    "c": AvgReducer(),
    "d": SumReducer(),
}

result = reduce_dict(generate_objects(), reducers)
print(result)

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

dict_sourcer-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (239.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

File details

Details for the file dict_sourcer-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for dict_sourcer-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c6ba1ca330bf10e11ed37b21aaa246adaaa7f69cde99d166827d6c23932a5240
MD5 8e984b4fbf7d59aa4c243b10bbc0e127
BLAKE2b-256 b535157009e1e5ab3350a15e722841e7080f8452f21bb331aff1702c12a8dec8

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