https://github.com/100nm/python-injection
Fast and easy dependency injection framework.
https://github.com/100nm/python-injection
async async-python decorators decorators-python dependency-injection fastapi mypy python type-hints typed
Last synced: 23 days ago
JSON representation
Fast and easy dependency injection framework.
- Host: GitHub
- URL: https://github.com/100nm/python-injection
- Owner: 100nm
- Created: 2023-07-13T15:11:15.000Z (over 2 years ago)
- Default Branch: prod
- Last Pushed: 2025-04-30T10:01:53.000Z (9 months ago)
- Last Synced: 2025-04-30T11:24:31.582Z (9 months ago)
- Topics: async, async-python, decorators, decorators-python, dependency-injection, fastapi, mypy, python, type-hints, typed
- Language: Python
- Homepage:
- Size: 796 KB
- Stars: 14
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-dependency-injection-in-python - python-injection - Dead-simple dependency injection framework for Python. [🐍, MIT License]. (Software / DI Frameworks / Containers)
README
# python-injection
[](https://github.com/100nm/python-injection)
[](https://pypi.org/project/python-injection)
[](https://pypistats.org/packages/python-injection)
[](https://github.com/astral-sh/ruff)
Documentation: https://python-injection.remimd.dev
## Installation
⚠️ _Requires Python 3.12 or higher_
```bash
pip install python-injection
```
## Quick start
Simply apply the decorators and the package takes care of the rest.
```python
from injection import injectable, inject, singleton
@singleton
class Printer:
def __init__(self):
self.history = []
def print(self, message: str):
self.history.append(message)
print(message)
@injectable
class Service:
def __init__(self, printer: Printer):
self.printer = printer
def hello(self):
self.printer.print("Hello world!")
@inject
def main(service: Service):
service.hello()
if __name__ == "__main__":
main()
```