Skip to main content

spryx-di

CI PyPI Python License

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

Metadata

Release files for spryx-di 3.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spryx-di 3.0.6
File Size Uploaded Provenance Actions
spryx_di-3.0.6.tar.gz 159.0 kB With provenance Details for spryx_di-3.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spryx-di 3.0.6
File Interpreter ABI Platform Actions
spryx_di-3.0.6-py3-none-any.whl Python 3 none any Details for spryx_di-3.0.6-py3-none-any.whl

Total release size: 181.7 kB

Release files / spryx_di-3.0.6.tar.gz

Download URL spryx_di-3.0.6.tar.gz
Size 159.0 kB
Tags Source
SHA-256 checksum
How to use checksums
07cd8c2c74cc894366f14674797852083cb22dc2814d1178653e3fdeb0db67b1
BLAKE2b-256 checksum
How to use checksums
bfac21221ef1c9504b653576cfe8326795f0fce0dbffc7e9e96bf1cd8e08acef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 7, 2026.

Transparency log

Release files / spryx_di-3.0.6-py3-none-any.whl

Download URL spryx_di-3.0.6-py3-none-any.whl
Size 22.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
97f6b695fc959ba9434c7792c4252d9785fdbd4a44b56da2887836577f425f4d
BLAKE2b-256 checksum
How to use checksums
4e9965690778c4de0cf3e14928557549293a75cdc1f7aefe48681a8b9425ccd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 7, 2026.

Transparency log

Security for spryx-di 3.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for spryx_di-3.0.6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 7, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page