A lightweight Dependency Injection (DI) container for Python
Project description
Pynjector
A lightweight Dependency Injection (DI) container for Python that allows automatic resolution of dependencies based on constructor type hints.
🚀 Features
- Simple and intuitive API
- Automatic dependency resolution based on type hints
- Supports binding classes, factory functions, and pre-initialized instances
- Inspired by C#'s dependency injection approach
📦 Installation
Install via pip:
pip install pynjector
Install via poetry:
poetry add pynjector
🎯 Usage
from src.pynjector import DIContainer
class Database:
def query(self) -> str:
return "Data from Database"
class Service:
def __init__(self, db: Database):
self.db = db
def get_data(self) -> str:
return self.db.query()
# Create the pynjector
container = DIContainer()
# Register dependencies
container.bind(Database)
# Resolve a service instance
service = container.resolve(Service)
print(service.get_data()) # Output: "Data from Database"
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pynjector-0.1.3.tar.gz
(7.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pynjector-0.1.3.tar.gz.
File metadata
- Download URL: pynjector-0.1.3.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75dc9ba28c7abd4c54d53755738fef8d82f548e43789d7ad1cbc1441a48ff125
|
|
| MD5 |
935f424f306189af244811fef9413b90
|
|
| BLAKE2b-256 |
88a0905c4b5a6a18e70137e6d6cde814b6a3ec75a038af956579a64911c766f9
|
File details
Details for the file pynjector-0.1.3-py3-none-any.whl.
File metadata
- Download URL: pynjector-0.1.3-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
532534f00f205eb7c751718cfeae822a74b446b48c26ff152467c4f0a981a7d9
|
|
| MD5 |
95ec86788981f3237cd764275307f0a6
|
|
| BLAKE2b-256 |
7ca4624b1027c67bbd5e7ea58cd725f6e341382b2c776f76de4d51c536819f0c
|