Decorator-based registry for objects with arbitrary payloads
Project description
decorated_registry
Implementation of generalised registries for Python.
Allows you to seamlessly create registries of tests, modules, DSLs and RPCs.
Supports arguments and fully typed.
Example
from typing import List, Type
from dataclasses import dataclass
from decorated_registry import Registry, ConstructorPayloadFactory
# framework/abstract.py
@dataclass
class ModuleConfig:
init_priority: int = -1
class Module:
pass
# framework/registry.py
application_module: Registry[ModuleConfig, Type[Module]] = Registry(
payload_factory=ConstructorPayloadFactory(dict)
)
# authentication_mod/impl.py
@application_module
class AuthenticationModule(Module):
pass
# database_mod/impl.pu
@application_module(init_priority=2)
class DatabaseSessionModule(Module):
pass
# framework/app.py
def load_modules() -> List[Module]:
rtn = []
# ensure modules are loaded in the order given by `ModuleConfig.priority`
modules_priority = sorted(application_module.items, key=lambda x: x.payload.init_priority)
for x in modules_priority:
module_cls: Type[Module] = x.value
module = module_cls()
rtn.append(module)
return rtn
# framework/main.py
def main():
modules = load_modules()
if __name__ == '__main__':
main()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file decorated_registry-0.0.2.tar.gz
.
File metadata
- Download URL: decorated_registry-0.0.2.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e239e849626bcc8ddb9324bcc2478d2b73f0469b14a013b02d558ab650f39660 |
|
MD5 | 808d1cf8a54e04531599563b9a2030de |
|
BLAKE2b-256 | db98c821f02070e43dff92eb2a9d4e5814a70622ba0f56d192cead01b793625e |
File details
Details for the file decorated_registry-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: decorated_registry-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbe0414ada9f273b77943bf05507d9bffaf575cf1909c1f3dd9d6c9f1b86d21d |
|
MD5 | ab79cff96857e3c5c877ad3569dce127 |
|
BLAKE2b-256 | a827d391903026e40576cae23b31843f0f7fa915eb8da270b18b3f746064d046 |