Simple Dependency Injection framework
Project description
"That Depends"
This package is dependency injection framework for Python, mostly inspired by python-dependency-injector
.
It is production-ready and gives you the following:
- Fully-async simple DI framework with IOC-container.
- Python 3.10-3.12 support.
- Full coverage by types annotations (mypy in strict mode).
- FastAPI and Litestar compatibility.
- Zero dependencies.
- Overriding dependencies for tests.
Projects with That Depends
:
- fastapi-sqlalchemy-template - FastAPI template with sqlalchemy2 and PostgreSQL
- litestar-sqlalchemy-template - LiteStar template with sqlalchemy2 and PostgreSQL
Main decisions:
- By default, dependency resolving is async:
some_dependency = await DIContainer.dependent_factory()
- Sync resolving is also possible, but will fail in case of async dependencies:
sync_resource = DIContainer.sync_resource.sync_resolve() # this will work
async_resource = DIContainer.async_resource.sync_resolve() # this will fail with RuntimeError
# but this will work
async_resource = await DIContainer.async_resource()
async_resource = DIContainer.async_resource.sync_resolve()
- No wiring for injections in function arguments -> achieved by decision that only one instance of container is supported
from tests import container
from that_depends import Provide, inject
@inject
async def some_function(
simple_factory: container.SimpleFactory = Provide[container.DIContainer.simple_factory],
) -> None:
assert simple_factory.dep1
Quickstart
Install
pip install that-depends
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
that_depends-1.7.1.tar.gz
(7.1 kB
view hashes)
Built Distribution
Close
Hashes for that_depends-1.7.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 632afc61bde84151dc5723a40dda94908df39ef5df67917e60a2f83ec7c11ae3 |
|
MD5 | 6ee8180bf6805f4448de4353a1940a3b |
|
BLAKE2b-256 | 708a049a356fadb95f34664c2add12d4f70ece26bebd7ddf97d50e3cd88dda82 |