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
File details
Details for the file python_injection-0.10.12.post0.tar.gz
.
File metadata
- Download URL: python_injection-0.10.12.post0.tar.gz
- Upload date:
- Size: 14.6 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 | 74e3e3dc94c32fef3220bd9892db1c395eadec3e7201c05533d9516ba246e39a |
|
MD5 | 21bbfa392d74514819fb51afbf22f98d |
|
BLAKE2b-256 | 09d19097c9492a23df4758957cb817c1b7fd85fb7c6e7fe1c3bde1e642d264c8 |
File details
Details for the file python_injection-0.10.12.post0-py3-none-any.whl
.
File metadata
- Download URL: python_injection-0.10.12.post0-py3-none-any.whl
- Upload date:
- Size: 19.2 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 | 47a4b0099ff65b5ab0e92f400f4ebc09b81175f4e95cc02a5e6270703240c413 |
|
MD5 | 77c25fdb6cc3eeadac1f886cd1b34c52 |
|
BLAKE2b-256 | b2c7237f74ecffb9e7bd6a056421aa055beb588722b09adf4f2372668f1d333a |