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.2.tar.gz
(5.1 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.2.tar.gz.
File metadata
- Download URL: pynjector-0.1.2.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a3fdf63c3a65a8e63f2e03daba5ea1aada7c51eb2e2aa4d2afff418f6c0fb91
|
|
| MD5 |
93a6bad7378f6ca15fb6d3344cfefae3
|
|
| BLAKE2b-256 |
5a4f0af92af54b485ff54393c51448d143a6a0d72073b7d65acfbc8a24bea72a
|
File details
Details for the file pynjector-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pynjector-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.1 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 |
6f2055adf2304f6caafb226e549d9958911bc58679036fd569e9e1d0e6d4aaeb
|
|
| MD5 |
1561b5a245ffd65fae30d57079c0185e
|
|
| BLAKE2b-256 |
a52d36cf2fc9cfe98965edc26ad41c5b4dcf96a21277acd3dcfbea32da8d9419
|