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.8.tar.gz
(14.5 kB
view details)
Built Distribution
File details
Details for the file python_injection-0.10.8.tar.gz
.
File metadata
- Download URL: python_injection-0.10.8.tar.gz
- Upload date:
- Size: 14.5 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 | 880cb577ec691b91eb6c4a55700e41ab1de09336869de04b6be42cf5eacb8b92 |
|
MD5 | 8deef6f3ec59e8aa41ccbdb539770761 |
|
BLAKE2b-256 | 2d75fe5bc2a877a2180ea39a37afa25d2a75f8a54795d3fbfbcda7aa50f4a808 |
File details
Details for the file python_injection-0.10.8-py3-none-any.whl
.
File metadata
- Download URL: python_injection-0.10.8-py3-none-any.whl
- Upload date:
- Size: 19.0 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 | b56cc7b0fe0ce4038dad1d90ff59661134c540c8dc67b23195d1a99274b55ffd |
|
MD5 | ba18d9d8da7714a0e33159de8cea2452 |
|
BLAKE2b-256 | 08a31a3971230016e4d29b464b20efba4b3f91d37ce050081b96bd3c54b40a9e |