From b1ef89fba634e75edf2f950f3eab4d82f5799dce Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Sat, 18 May 2024 00:59:45 +0300 Subject: [PATCH] update README.md --- README.md | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 9c25449..2d2e073 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,17 @@ "That Depends" == -[![GitHub issues](https://img.shields.io/github/issues/modern-python/that-depends)](https://github.com/modern-python/that-depends/issues) -[![GitHub forks](https://img.shields.io/github/forks/modern-python/that-depends)](https://github.com/modern-python/that-depends/network) -[![GitHub stars](https://img.shields.io/github/stars/modern-python/that-depends)](https://github.com/modern-python/that-depends/stargazers) +[![PyPI version](https://badge.fury.io/py/that-depends.svg)](https://pypi.python.org/pypi/that-depends) +[![Supported versions](https://img.shields.io/pypi/pyversions/that-depends.svg)](https://pypi.python.org/pypi/that-depends) +[![downloads](https://img.shields.io/pypi/dm/that-depends.svg)](https://pypistats.org/packages/that-depends) [![GitHub license](https://img.shields.io/github/license/modern-python/that-depends)](https://github.com/modern-python/that-depends/blob/main/LICENSE) +[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/modern-python/that-depends/python-package.yml)](https://github.com/modern-python/that-depends/actions) +[![Doc](https://readthedocs.org/projects/that-depends/badge/?version=latest&style=flat)](https://that-depends.readthedocs.io) +[![GitHub stars](https://img.shields.io/github/stars/modern-python/that-depends)](https://github.com/modern-python/that-depends/stargazers) This package is dependency injection framework for Python, mostly inspired by `python-dependency-injector`. +📚 [Documentation](https://that-depends.readthedocs.io) + It is production-ready and gives you the following: - Fully-async simple DI framework with IOC-container. - Python 3.10-3.12 support. @@ -15,31 +20,38 @@ It is production-ready and gives you the following: - Zero dependencies. - Overriding dependencies for tests. -# Main characteristics: -1. Fully async -> means every dependency resolving is async, so you should construct with `await` keyword: -```python -from tests.container import DIContainer +# Projects with `That Depends`: +- [fastapi-sqlalchemy-template](https://github.com/modern-python/fastapi-sqlalchemy-template) - FastAPI template with sqlalchemy2 and PostgreSQL +- [litestar-sqlalchemy-template](https://github.com/modern-python/litestar-sqlalchemy-template) - LiteStar template with sqlalchemy2 and PostgreSQL -async def main(): - some_dependency = await DIContainer.independent_factory() +# Main decisions: +1. By default, dependency resolving is async: +```python +some_dependency = await DIContainer.dependent_factory() ``` -2. No wiring for injections in function arguments -> achieved by decision that only one instance of container is supported +2. Sync resolving is also possible, but will fail in case of async dependencies: +```python +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() +``` +3. No wiring for injections in function arguments -> achieved by decision that only one instance of container is supported ```python from tests import container from that_depends import Provide, inject - @inject async def some_function( - independent_factory: container.SimpleFactory = Provide[container.DIContainer.independent_factory], + simple_factory: container.SimpleFactory = Provide[container.DIContainer.simple_factory], ) -> None: - assert independent_factory.dep1 + assert simple_factory.dep1 ``` # Quickstart ## Install - ```bash pip install that-depends ```