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.10.tar.gz
(14.7 kB
view details)
Built Distribution
File details
Details for the file python_injection-0.10.10.tar.gz
.
File metadata
- Download URL: python_injection-0.10.10.tar.gz
- Upload date:
- Size: 14.7 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 | c3dc8146bf73d2fbf58602af2324fc33b0f3c10597caf343b8ef23a1092f8d69 |
|
MD5 | e2800fd1d2e4697cab82e8d2ad1fab71 |
|
BLAKE2b-256 | 2f9425750e51190261a69398251a4903e363978e618b9cbc410969bd59d81345 |
File details
Details for the file python_injection-0.10.10-py3-none-any.whl
.
File metadata
- Download URL: python_injection-0.10.10-py3-none-any.whl
- Upload date:
- Size: 19.2 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 | e624a0517518c251e86ecda7bb431883986ca3bedf933c98ef14a3a11286f001 |
|
MD5 | f975424d342ce3644b2e2c62b29fcfdb |
|
BLAKE2b-256 | 9be46fce711c9c602b1734ee912b67423fd43fea765bdcba031f98a2b59ea02c |