Skip to main content

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

Project description

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.2.0.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.2.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mnemoreg-0.2.0.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.2.0.tar.gz
Algorithm Hash digest
SHA256 511ca005edc344e3b3d1be426a7d2b504b25b9353166bfab0270b7738d849181
MD5 d92768ed08ae5780fd91e8f791dd372c
BLAKE2b-256 1102d16f09ab9a98118d02d79e54343feb8b6b2fe4f053c7749d5c415cad0533

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mnemoreg-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cab34219880935d28f46f631295378740284d8959644d43109567f0194236596
MD5 7b6cb56a5ab9dced3c222159ce51e9b7
BLAKE2b-256 b632096c2a7a4a887c30f26f09ddac80e4a129c441a7c405a5004aa8d003623f

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