Lightweight type-based dependency injection for Python modular monoliths
Project description
spryx-di
Lightweight dependency injection for Python modular monoliths.
- NestJS-inspired modules with providers, exports, and imports
- Type-based auto-wiring via
__init__type hints - Module boundary enforcement at boot time
- Zero runtime dependencies
- Zero intrusion in domain code
Install
pip install spryx-di
Quick Example
from spryx_di import ClassProvider, Module, ApplicationContext
identity_module = Module(
name="identity",
providers=[
ClassProvider(provide=UserRepository, use_class=PgUserRepository),
ClassProvider(provide=UserReader, use_class=PgUserReader),
],
exports=[UserReader],
)
orders_module = Module(
name="orders",
providers=[
ClassProvider(provide=OrderRepository, use_class=PgOrderRepository),
],
imports=[identity_module],
)
ctx = ApplicationContext(modules=[identity_module, orders_module])
handler = ctx.resolve(CreateOrderHandler) # auto-wired from type hints
Handlers declare dependencies via __init__ — no decorators, no DI imports:
class CreateOrderHandler:
def __init__(self, repo: OrderRepository, reader: UserReader) -> None:
self._repo = repo
self._reader = reader
Features
| Feature | Description |
|---|---|
ClassProvider, FactoryProvider, ValueProvider, ExistingProvider |
Typed providers — use_class, use_factory, use_value, use_existing with Scope.SINGLETON (default) or TRANSIENT |
Module |
Declarative providers, exports, imports, on_destroy |
ApplicationContext |
Composes modules with boundary enforcement and boot-time validation |
forward_ref() |
Circular module dependencies without Python import errors |
| Lifecycle | on_destroy per module, auto-close managed instances, await ctx.shutdown() |
| FastAPI | Inject(), ScopedInject(), configure(), request scope middleware |
| Testing | override() context manager, Container with fakes |
Documentation
https://spryx-ai.github.io/spryx-di
Development
make install # deps + pre-commit hooks
make check # lint + typecheck + tests
make docs # serve docs locally
License
MIT
Project details
Release history Release notifications | RSS feed
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 spryx_di-1.2.0.tar.gz.
File metadata
- Download URL: spryx_di-1.2.0.tar.gz
- Upload date:
- Size: 147.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b95d1d162ad5aefe29627eb2ac037232ad060605d7c27b9fc275ea74ad93efa
|
|
| MD5 |
25b48139da532ffa3481464d9b5fa320
|
|
| BLAKE2b-256 |
329b9691a89fdb0ab19a2a6e98dcef719cfc192c1406e6142342c03e188e604b
|
Provenance
The following attestation bundles were made for spryx_di-1.2.0.tar.gz:
Publisher:
release.yml on Spryx-AI/spryx-di
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spryx_di-1.2.0.tar.gz -
Subject digest:
4b95d1d162ad5aefe29627eb2ac037232ad060605d7c27b9fc275ea74ad93efa - Sigstore transparency entry: 1243627662
- Sigstore integration time:
-
Permalink:
Spryx-AI/spryx-di@4f9249da7b19fef0ea45c1176445dd9de4ae362f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Spryx-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4f9249da7b19fef0ea45c1176445dd9de4ae362f -
Trigger Event:
push
-
Statement type:
File details
Details for the file spryx_di-1.2.0-py3-none-any.whl.
File metadata
- Download URL: spryx_di-1.2.0-py3-none-any.whl
- Upload date:
- Size: 18.2 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 |
1452c2ab2dbd3d869e4f6fca35837672723a38de627e6a441ec3d9a04b4df6a1
|
|
| MD5 |
30c04178d23649f03490382e7f531d7a
|
|
| BLAKE2b-256 |
34f5e478146fe9f5f144f297e50c09089e6fe5c0b9fe1e6913c261a32f03f025
|
Provenance
The following attestation bundles were made for spryx_di-1.2.0-py3-none-any.whl:
Publisher:
release.yml on Spryx-AI/spryx-di
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spryx_di-1.2.0-py3-none-any.whl -
Subject digest:
1452c2ab2dbd3d869e4f6fca35837672723a38de627e6a441ec3d9a04b4df6a1 - Sigstore transparency entry: 1243627669
- Sigstore integration time:
-
Permalink:
Spryx-AI/spryx-di@4f9249da7b19fef0ea45c1176445dd9de4ae362f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Spryx-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4f9249da7b19fef0ea45c1176445dd9de4ae362f -
Trigger Event:
push
-
Statement type: