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.5.tar.gz
(14.5 kB
view details)
Built Distribution
File details
Details for the file python_injection-0.10.5.tar.gz
.
File metadata
- Download URL: python_injection-0.10.5.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9147635bec174238589f1e78fe2f6f3323c3882c3b97e9c545eef6d3071f5d7 |
|
MD5 | a98d1160fd5b2c2b179533979fc91f2c |
|
BLAKE2b-256 | 0b843109f6252e7c9b0d8a3b79996c4e339126e372272689af73548608b9999c |
File details
Details for the file python_injection-0.10.5-py3-none-any.whl
.
File metadata
- Download URL: python_injection-0.10.5-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b76e91835536455f763cbcedeca69d112b340e9d37c232f3641ea2cb7157e214 |
|
MD5 | 3280361151f25c69dd7bc4277e819a25 |
|
BLAKE2b-256 | 6ffff2319cf983febcedeb50504849d7990bb68b7c56813cfb0050c3909f7b65 |