Skip to content

Latest commit

 

History

History
56 lines (48 loc) · 2.55 KB

README.md

File metadata and controls

56 lines (48 loc) · 2.55 KB

"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