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.3.tar.gz
(14.0 kB
view details)
Built Distribution
File details
Details for the file python_injection-0.10.3.tar.gz
.
File metadata
- Download URL: python_injection-0.10.3.tar.gz
- Upload date:
- Size: 14.0 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 | 952a602ceb6c9e14c742bf51d0e768056d4bd225b778d34fe37c297f7aaed1f9 |
|
MD5 | edc33a9a1c284281e69b6ef702775937 |
|
BLAKE2b-256 | 1db99642c39a7a0046f9433b93aa28f9b2344947074659807e8485a65215ec4b |
File details
Details for the file python_injection-0.10.3-py3-none-any.whl
.
File metadata
- Download URL: python_injection-0.10.3-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 | 49b0d807dbdfaeb25951dec4db998511e2201a9a99c60cd3a8b01477dc5aeb53 |
|
MD5 | 6c7f5e6dd4275ce31bba53abfd570a9d |
|
BLAKE2b-256 | 0fff186a714bcd8b7d8f8a70f9918a7180526da8ad270457cd924ae730689973 |