Fast and easy dependency injection framework.
Project description
python-injection
Fast and easy dependency injection framework.
Installation
⚠️ Requires Python 3.12 or higher
pip install python-injection
Motivations
- Easy to use
- No impact on class and function definitions
- Easily interchangeable dependencies (depending on the runtime environment, for example)
- No prerequisites
Quick start
Simply apply the decorators and the package takes care of the rest.
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()
Resources
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
python_injection-0.10.11.tar.gz
(14.6 kB
view details)
Built Distribution
File details
Details for the file python_injection-0.10.11.tar.gz
.
File metadata
- Download URL: python_injection-0.10.11.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 437d0d9a316c01e6d19541c2c368be918bec8b7b219f3334a22b59bd6610a2a8 |
|
MD5 | aa2370db12007d574d6dd49e171a5af4 |
|
BLAKE2b-256 | 66ed101bd792212dd9139748e4d029f5a720b60bd41a9e6d6b5b6fb9b77a2e00 |
File details
Details for the file python_injection-0.10.11-py3-none-any.whl
.
File metadata
- Download URL: python_injection-0.10.11-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 695d330fae4df9439e4e15fbe87ab683981accfa4526c1568c34498248e79918 |
|
MD5 | 34db31b86c7a088e8d65e9c7b861d31e |
|
BLAKE2b-256 | 78120b41eff50da927bbb31d46ba4ab514f97cf46b3bd816e49474970871759a |