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.5.post0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f2707f03046c7f0ce40974baf19e816e29aff456b1b336b9d6488f28988ea08 |
|
MD5 | cc09aeac1b03089ee724c3a456e1b368 |
|
BLAKE2b-256 | eab33e964e877768c1c14266cdae30995a4151582290b0625f21fb9585634d0e |
Close
Hashes for python_injection-0.10.5.post0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64792ff9364741a39a37d837b722a6bdc758bf04ce6ba25d4da07ff63272eede |
|
MD5 | 38ea42ea8c7364213e03a43d07ece642 |
|
BLAKE2b-256 | bbfcf1623e1370a4824b39cf14b57473f8394666c0c38ec4aa8133f9ffeeb59d |