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
Built Distribution
Close
Hashes for python_injection-0.10.8.post0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4467548a828e307204a811f6ad0cfcd20025a0a201ef7688bc7c67d58c5d2d2 |
|
MD5 | dd1a2879a7008c01cb3c8ac8ea9c660d |
|
BLAKE2b-256 | 5817d040cfb07aaeaffc1a01735d08e524255b7e8f0ffbf58b4e85f109b1c778 |
Close
Hashes for python_injection-0.10.8.post0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1e85b56231b5f53fbc5cca5e39f30eb17b07aaebf6af892171187aafae93569 |
|
MD5 | 9551472bd38d3b00d14150766b70d896 |
|
BLAKE2b-256 | c33c0a776010263262daa542124cfb6da782e17ebe4396e6e21a3772ce02c7c4 |