Skip to content

Commit

Permalink
update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
lesnik512 committed May 17, 2024
1 parent 6a79a88 commit b1ef89f
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
```

0 comments on commit b1ef89f

Please sign in to comment.