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.4.tar.gz
(9.8 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.4.tar.gz.
File metadata
- Download URL: pynjector-0.1.4.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a0f346a9cb923a5958ba6225fedc46427d31ea414c8b8ae6cebceabc781d39d
|
|
| MD5 |
27022bd72a66561cb33efcf9578e77e2
|
|
| BLAKE2b-256 |
17a7c13576add0485315f63488f8923639c863a6795fc084e302ccfe32348f73
|
File details
Details for the file pynjector-0.1.4-py3-none-any.whl.
File metadata
- Download URL: pynjector-0.1.4-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
893beda18a12df10e2c1f04329c2acb550bbb284b6d19faf2edae212cd3b5315
|
|
| MD5 |
c933dff3aa3000286ecedcf72e284e6e
|
|
| BLAKE2b-256 |
5d6a73039d581ee8b7f12889a5a024f7ce454379a4a7de2ecbd628c3f6f6a790
|