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

Uploaded Python 3

File details

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

File metadata

  • Download URL: mnemoreg-0.1.8.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.8.tar.gz
Algorithm Hash digest
SHA256 e7baeeaa4ea1c4d7f27ffe003cb859c5188426e04e1b9cb2919c74f04aeba6eb
MD5 13f51f5d554f0053c7be9a9eb50cbd73
BLAKE2b-256 6d8d4bbba54788fa4ffc737fb212669f94ef92ece8128dc28927ffbcb1b4553a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mnemoreg-0.1.8-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.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 5bbe4034b23033a624de77befb7a86fc5830dfbdaed578eedbe2013516c33435
MD5 bb1fca243c094dd3e50b1e53e3e969fe
BLAKE2b-256 55efd2558359d631f5d8ffa7ed30e895060827dc00cb96697ab70cd327db7962

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