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.11.0.tar.gz
(14.9 kB
view details)
Built Distribution
File details
Details for the file python_injection-0.11.0.tar.gz
.
File metadata
- Download URL: python_injection-0.11.0.tar.gz
- Upload date:
- Size: 14.9 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 | fb9691a9c8aae576693fcfb30c333ae81391458959a3816ab0b5d79b87afb570 |
|
MD5 | 8372910f1e64a155b48a8a9c84af78ed |
|
BLAKE2b-256 | b5ab7820627b98b6de117dfbc2423586063e1e708e72a4208d7e539eebd8ff45 |
File details
Details for the file python_injection-0.11.0-py3-none-any.whl
.
File metadata
- Download URL: python_injection-0.11.0-py3-none-any.whl
- Upload date:
- Size: 19.7 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 | afd6adbda8560f0e9541959b77f78440bdedf37954c4f12bfe84d014650c8798 |
|
MD5 | a98306744643b6174b4b8f5ea48c76e3 |
|
BLAKE2b-256 | 61fae37c14bbefd8588e2e20bf52f237270d3cc33dd4d4ccd51d019e08af152f |