Skip to main content

Memoizer

API

A Memoizer can be used as a factory for creating objects of a certain class. It exposes a constructor and 2 methods

  • memoizer = Memoizer(SomeClass)
  • memoizer.get(*args, **kwargs)
    • If memoizer has never seen the given arguments, it creates SomeClass(*args, **kwargs) and returns it.
    • If memoizer has seen the given arguments before, it returns the same instance that it returned the last time.
  • memoizer.forget(*args, **kwargs)
    • Makes memoizer forget that is has seen the given arguments.

Usage

The original application was for a MeasurementQueue class that processes incoming sensor data from many sensors, where the sensor ID's were not known ahead of time:

queue_manager = Memoizer(MeasurementQueue)

for sensor_id, data in event_stream():
    queue = queue_manager.get(sensor_id)
    queue.push(data)

When the first measurement comes in for a given sensor_id, a new MeasurementQueue will be created and returned for that sensor. On subsequent events with the same sensor ID, the same MeasurementQueue instance will be used to process the data.

Installation

pip install classmemo

The only dependencies are Python 3.6 and the frozendict package.

Contributing

  • Ensure the tests pass: pytest .
  • Format the code with black . -t py36

Metadata

Release files for classmemo 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for classmemo 1.0.2
File Size Uploaded Provenance Actions
classmemo-1.0.2.tar.gz 2.0 kB Without provenance Details for classmemo-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for classmemo 1.0.2
File Interpreter ABI Platform Actions
classmemo-1.0.2-py2.py3-none-any.whl Python 2, Python 3 none any Details for classmemo-1.0.2-py2.py3-none-any.whl

Total release size: 5.6 kB

Release files / classmemo-1.0.2.tar.gz

Download URL classmemo-1.0.2.tar.gz
Size 2.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9e4004e86b40f674bf25bea03d265d0bddaa20d4798d8eb4e6403c884f069630
BLAKE2b-256 checksum
How to use checksums
dd532fb4feb120f2b29f7205cee13c162a2ceec5e4ce0f26ee76d5d750aecfb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.4

Release files / classmemo-1.0.2-py2.py3-none-any.whl

Download URL classmemo-1.0.2-py2.py3-none-any.whl
Size 3.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
22d6e454d31f92372d0339bdbc94b5deae2b775c6e7942b4cb13c7ffdc2c1716
BLAKE2b-256 checksum
How to use checksums
f5de2f7a2fd3643b830ecf45e14bf317043c531d5c3ae0f1dda7511ab4d4b68e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.4

Security for classmemo 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page