You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

dict-sourcer

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dict-sourcer

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

0.3.0
pipPyPI
Maintainers
1

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)

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts