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.2.1.tar.gz (17.1 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.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mnemoreg-0.2.1.tar.gz
  • Upload date:
  • Size: 17.1 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.1.tar.gz
Algorithm Hash digest
SHA256 fed1639ae2e8a36385b0f21b558caaa563d5338933847dbdfe4ea9c728ff700f
MD5 33a915e6b67a68b6ccd83bfa16299f38
BLAKE2b-256 c0cdffff4e33815ad7c7fc55c9b69bb950c11f41ddbcde7517d555825b32b10b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mnemoreg-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 42d8dda88ae43b126ac2cdc072f9c3ccdf889af61f78427273362ae14be9fd8d
MD5 e3dc9de27803f39938b0ad6c305257b4
BLAKE2b-256 2b9686037bd711d6232bdfba9eb6a6cbd53327c04411d0a6292c51cab74e7e67

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