Python typed object schema validation
Project description
typedi
Simple typed dependency injection container.
To install from python package index simply type (no dependencies):
pip install typedi
Or, if you don't want to bring a dependency inside a project simply copy and paste typedi.py
inside your project
Usage
Containers
typedi comes with a default shared container, to add or retrieve instances from it import it anywhere you need - usually in some initialization/bootstrapping logic.
from typedi import container
Or you could also create your own DI containers:
from typedi import Container
my_container = Container()
Instance bindings, "user-managed singletons"
from typedi import container
class MyClass:
pass
instance = MyClass()
container.bind_to_instance(MyClass, instance)
# anywhere else
from typedi import container
instance = container.get_instance(MyClass)
Class bindings
from typedi import container
class MyClass:
pass
instance = MyClass()
container.register_class(MyClass)
# anywhere else
from typedi import container
auto_instantiated_instance = container.get_instance(MyClass)
Class bindings with inheritance
from typedi import container
class MyClass:
pass
class ChildOfMyClass(MyClass):
pass
instance = MyClass()
container.bind_to_class(MyClass, ChildOfMyClass)
# anywhere else
from typedi import container
auto_instantiated_instance = container.get_instance(MyClass) # type: ChildOfMyClass
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
typedi-0.1.tar.gz
(2.4 kB
view details)
Built Distribution
typedi-0.1-py3-none-any.whl
(3.4 kB
view details)
File details
Details for the file typedi-0.1.tar.gz
.
File metadata
- Download URL: typedi-0.1.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 457707370a4c2742b843d3f500236b42bb1cf91adac2f4135cfb292ab94a6f57 |
|
MD5 | c77ca395615e209317354a2b39c82888 |
|
BLAKE2b-256 | e180a1a9712e1317f528d6ba22f2f3491ca87240294a903123cd32bacd142433 |
File details
Details for the file typedi-0.1-py3-none-any.whl
.
File metadata
- Download URL: typedi-0.1-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32e380bcdf736767a74e786dd44f97f14a2e086b2af19592e98e317e3976beed |
|
MD5 | 0fdaf85e642c127df5bc74118c6a1bd8 |
|
BLAKE2b-256 | 251b601250dc48798400f5adf523c8b96e7feafa363ecb02bbfd7933dcbc2edb |