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.1.tar.gz
(12.7 kB
view details)
Built Distribution
File details
Details for the file python_injection-0.10.1.tar.gz
.
File metadata
- Download URL: python_injection-0.10.1.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90850cd892538e7e4193396e6d32eac5094baa2cb385c624fe4ba853923e229e |
|
MD5 | ce28a75187e0da21bf83a00be8f5ab68 |
|
BLAKE2b-256 | a268f0488f5488e459ad40946566865468259f50ad62a0b3e0b29c2ff27ebd62 |
File details
Details for the file python_injection-0.10.1-py3-none-any.whl
.
File metadata
- Download URL: python_injection-0.10.1-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 685246e8d498d1dda5fdf380580028b89c17184be031c4178c2d6ba566e5580a |
|
MD5 | ecea283eb1071b89668ee75fed165f1d |
|
BLAKE2b-256 | 7a56d104a74ed08977fb8dc2e8dc66245e772e44151c6cfc8a506381cb424399 |