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.9.tar.gz
(14.6 kB
view details)
Built Distribution
File details
Details for the file python_injection-0.10.9.tar.gz
.
File metadata
- Download URL: python_injection-0.10.9.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 | f64bfedfa9d6c681eb43a672325eed5c55028bf0be06661da0ea836208ffe7e2 |
|
MD5 | 69504249c40df37a8d025e1acc9ac1cf |
|
BLAKE2b-256 | fa3acd59bb5b07d825c3eb76ee1d49dbf20f92e9651989797b6be87588e260bf |
File details
Details for the file python_injection-0.10.9-py3-none-any.whl
.
File metadata
- Download URL: python_injection-0.10.9-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 | e5fe30901113c431a50fbda2fa0a6e1a34a2e868b9c91ef87d42e51b4038ca23 |
|
MD5 | 7f6c00371e55d0e5dc2abd0b89c9f33b |
|
BLAKE2b-256 | 4c18906c5f5f3d65b50e4b6e6af865a68a2381e5c0d5069059e66bcd522764c5 |