A powerful and type-safe dependency injection/IoC library for Python
Project description
inversipy
A powerful and type-safe dependency injection/IoC (Inversion of Control) library for Python 3.12+.
Features
- Type annotation-based - Dependencies resolved using Python type hints
- Pure classes - No container coupling; classes remain framework-agnostic
- Zero runtime dependencies - Pure Python
- Async-first - First-class support for async dependencies and factories
- Module system - Organize dependencies with public/private access control
- Multiple scopes - Singleton, Transient, and Request
- Named dependencies - Multiple implementations with named disambiguation
- Collection injection - Register and inject multiple implementations with
InjectAll - Optional dependencies -
T | Noneparameters resolve toNonewhen unregistered - Container freezing - Lock the container after configuration
- Validation - Catch configuration errors at startup
- FastAPI integration -
@injectdecorator for route handlers - Full type safety - Strict MyPy support with
py.typedmarker
Installation
pip install inversipy
Quick Start
from inversipy import Container, Scopes
class Database:
def query(self, sql: str) -> list:
return ["result"]
class UserRepository:
def __init__(self, db: Database) -> None:
self.db = db
def get_users(self) -> list:
return self.db.query("SELECT * FROM users")
class UserService:
def __init__(self, repo: UserRepository) -> None:
self.repo = repo
def list_users(self) -> list:
return self.repo.get_users()
# Create container and register dependencies
container = Container()
container.register(Database, scope=Scopes.SINGLETON)
container.register(UserRepository)
container.register(UserService)
# Validate and freeze
container.validate()
container.freeze()
# Resolve dependencies
service = container.get(UserService)
users = service.list_users()
Documentation
Full documentation is available at the documentation site.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE file for details.
Similar Projects
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
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 inversipy-0.3.0.tar.gz.
File metadata
- Download URL: inversipy-0.3.0.tar.gz
- Upload date:
- Size: 136.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c61fbda6cdb0e7037b963d0dc2c5c943e6971c135eac64300c05c258412c6790
|
|
| MD5 |
c2513f6285f9e2f6b7e8500e199d2177
|
|
| BLAKE2b-256 |
a56f5532f71a5e2979fcedcf0734a4aec6443eb27f6e8f950dc480159340b114
|
Provenance
The following attestation bundles were made for inversipy-0.3.0.tar.gz:
Publisher:
publish.yml on mottetm/inversipy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
inversipy-0.3.0.tar.gz -
Subject digest:
c61fbda6cdb0e7037b963d0dc2c5c943e6971c135eac64300c05c258412c6790 - Sigstore transparency entry: 1049910825
- Sigstore integration time:
-
Permalink:
mottetm/inversipy@8ff1c24e611d1f4403ea314978be0be9cdd9b5a0 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/mottetm
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8ff1c24e611d1f4403ea314978be0be9cdd9b5a0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file inversipy-0.3.0-py3-none-any.whl.
File metadata
- Download URL: inversipy-0.3.0-py3-none-any.whl
- Upload date:
- Size: 30.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10b2613346e2f0ebd9eb97e6b90116d3f72df6dda4b259797da2c367db0b60c4
|
|
| MD5 |
1af64da5c94e6512184782f9bc769b52
|
|
| BLAKE2b-256 |
393039fb72bc9696d6006c35c29c22496963bbdf9e13697678576932458d3ed3
|
Provenance
The following attestation bundles were made for inversipy-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on mottetm/inversipy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
inversipy-0.3.0-py3-none-any.whl -
Subject digest:
10b2613346e2f0ebd9eb97e6b90116d3f72df6dda4b259797da2c367db0b60c4 - Sigstore transparency entry: 1049910861
- Sigstore integration time:
-
Permalink:
mottetm/inversipy@8ff1c24e611d1f4403ea314978be0be9cdd9b5a0 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/mottetm
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8ff1c24e611d1f4403ea314978be0be9cdd9b5a0 -
Trigger Event:
push
-
Statement type: