Skip to main content

A tiny thread-safe registry mapping for simple plugin/registry use-cases.

Project description

CI and Publish

mnemoreg

mnemoreg is a tiny thread-safe registry mapping useful for registering callables and other values by string keys. It's intentionally small and suitable for embedding in other projects. It has no dependencies beyond the Python standard library.

Table of Contents

Installation

You can install mnemoreg via pip:

pip install mnemoreg

Usage

Here is a simple example of how to use mnemoreg:

from mnemoreg import Registry

r = Registry[str, int]()
r["one"] = 1
print(r["one"])  # 1


@r.register("plus")
def plus(x):
    return x + 1


print(r["plus"](4))  # 5

You can also skip the explicit register key argument and in that case the function name will be used as the key:

@r.register()
def multiply(x, y):
    return x * y
print(r["multiply"](3, 4))  # 12

You can serialize the registry to a dictionary and recreate it later:

data = r.to_dict()
new_r = Registry.from_dict(data)
print(new_r["one"])  # 1
print(new_r["plus"](10))  # 11

See tests/ for more usage examples.

Implementation Notes

mnemoreg uses a threading lock to ensure thread safety during registry modifications. The internal storage is a simple dictionary mapping string keys to values of a generic type. See mnemoreg/core.py for implementation details.

License

mnemoreg is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

Contact

For questions or suggestions, please open an issue on the GitHub repository.

Project details


Download files

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

Source Distribution

mnemoreg-0.1.9.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

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

mnemoreg-0.1.9-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file mnemoreg-0.1.9.tar.gz.

File metadata

  • Download URL: mnemoreg-0.1.9.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for mnemoreg-0.1.9.tar.gz
Algorithm Hash digest
SHA256 2b9c33f5715c61f2ef156b5d8f7726d44f1f247212343a88d1faecdeadb6ce02
MD5 96fc1d61a656ee8c737edf55d7add54f
BLAKE2b-256 2c89494ea759c732bd22de3180e6e72bd11a8cfe5d2f46243fa5515cf46e3cf3

See more details on using hashes here.

File details

Details for the file mnemoreg-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: mnemoreg-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for mnemoreg-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 5d7fcacaade6f762c98cfeca1ad90e74dfdeca9e9d75e2d1a16e561696ef780f
MD5 c5728fe38eecc251da72955a02d2423b
BLAKE2b-256 2fd0d1d683b865b0c22483287608cb8d0655328348f124d75c480df96a420fad

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