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.12.tar.gz
(14.7 kB
view details)
Built Distribution
File details
Details for the file python_injection-0.10.12.tar.gz
.
File metadata
- Download URL: python_injection-0.10.12.tar.gz
- Upload date:
- Size: 14.7 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 | d07c17c0281a14b0bd45bfd615e71219253a2260540fa20b417700aa7804111c |
|
MD5 | 68ef70438e774e79af50a34e02adb4bf |
|
BLAKE2b-256 | f2204d1f2e3ccaa24ed0d183be48dcac85d398995865957e47bf8e0a8a9814f7 |
File details
Details for the file python_injection-0.10.12-py3-none-any.whl
.
File metadata
- Download URL: python_injection-0.10.12-py3-none-any.whl
- Upload date:
- Size: 19.1 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 | 2d9e4540e097819fcf8d8785b4af72ed16a893c4f0dd58edbf8535ec1533d1b7 |
|
MD5 | 17bbf72ac6fab57037aaca622337d079 |
|
BLAKE2b-256 | 94df2320d568229a0ad6a56742014d2d6388c71daa87b9f54801820fcc5da7d8 |