A lightweight Dependency Injection 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
🎯 Usage
from 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 container
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.0.tar.gz
(3.7 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.0.tar.gz.
File metadata
- Download URL: pynjector-0.1.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4988cfbf1d97414cace49c573a71e9d75171c4d824da46cbf99c6cbf544d28c0
|
|
| MD5 |
3a522bdbdd1a622f38cb8c9ce4bfde20
|
|
| BLAKE2b-256 |
f40146c09c054c8a9fe0be6e548d49069aff3205104e0abd5fb3629cb04dacd6
|
File details
Details for the file pynjector-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pynjector-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.2 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 |
f9327f369611b71946a5cc05beda639ec6ed20c8cfd02c60e60b5020eb045ee3
|
|
| MD5 |
584f5bc4eaa605cf09b90a1f5198c60c
|
|
| BLAKE2b-256 |
cf0a52361c90d50555a6ff955e806df2d3e19251310b7e42afa4c06a3869de99
|