Skip to content

DI-framework, inspired by python-dependency-injector, but without wiring. Python 3.12 is supported

License

Notifications You must be signed in to change notification settings

veriff-saulvargas/that-depends

 
 

Repository files navigation

"That Depends"

PyPI version Supported versions GitHub license GitHub Actions Workflow Status Doc GitHub stars

This package is dependency injection framework for Python, mostly inspired by python-dependency-injector.

📚 Documentation

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:

Main decisions:

  1. By default, dependency resolving is async:
some_dependency = await DIContainer.dependent_factory()
  1. 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()
  1. 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

About

DI-framework, inspired by python-dependency-injector, but without wiring. Python 3.12 is supported

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%