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.4.tar.gz
(14.1 kB
view details)
Built Distribution
File details
Details for the file python_injection-0.10.4.tar.gz
.
File metadata
- Download URL: python_injection-0.10.4.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95e3dd737f2d5d3be69326270ec9341754d68972d71816edec7945c17e04d17a |
|
MD5 | 42b444363a7fb76e2282886cd5976b0e |
|
BLAKE2b-256 | 5280303bea3a3dd51822664e7b6565c048923bc2751f75f701b6bc54cd7f7748 |
File details
Details for the file python_injection-0.10.4-py3-none-any.whl
.
File metadata
- Download URL: python_injection-0.10.4-py3-none-any.whl
- Upload date:
- Size: 18.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 904d536a24c267498b5504a58e9004be532f32e46e069bf9d9479bbe0ba4a963 |
|
MD5 | b7c5fb6ea3de3766afa2a3d4c6c232ab |
|
BLAKE2b-256 | e66010d9a773745b58c0a7135b6ddf092521282a781076500ac44d9fd9fd434a |