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.2.tar.gz
(12.9 kB
view hashes)
Built Distribution
Close
Hashes for python_injection-0.10.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2dca7997bdb918e132e5de90c82ca3b6f6dd33aac61ec67a11521afe66e664a8 |
|
MD5 | 5f0a0ef38c499fb6092b58a31661d731 |
|
BLAKE2b-256 | 43ca102913e22ec262cb4ce047302d0527c92993780e89f9a6b3121ed66acc28 |