Skip to main content

qx-di

Async dependency-injection container for the Qx framework. Supports SINGLETON, SCOPED, and TRANSIENT lifetimes with full async lifecycle, generic-aware resolution, and decorator-based registration.

What lives here

  • qx.di.Container — resolves, caches, and scopes dependencies. Supports register_singleton, register_scoped, register_transient, register_instance, and override.
  • qx.di.Scope — per-request child scope. Scoped registrations live exactly as long as their scope.
  • qx.di.Lifetime — SINGLETON / SCOPED / TRANSIENT enum.
  • qx.di.singleton / scoped / transient — class decorators that embed registration metadata without touching the class interface.
  • qx.di.scan — discover and register all decorated classes in a package tree.
  • qx.di.injectable — low-level decorator for explicit key/lifetime/factory overrides.

Usage

from qx.di import Container, Scope, scoped, singleton, scan

@singleton()
class Database:
    def __init__(self, url: str) -> None: ...

@scoped(key=UserRepository)
class PgUserRepository(UserRepository):
    def __init__(self, db: Database) -> None: ...

container = Container()
scan(container, "myapp.infrastructure")
container.register_instance(str, "postgresql+asyncpg://...")

async with container.scope() as scope:
    repo = await container.resolve(UserRepository, scope=scope)

Design rules

  • Annotation-driven — _call_factory inspects get_type_hints() to resolve constructor parameters. No manual wiring for the common case.
  • Scope propagation — pass the active Scope into mediator.send() and it threads through all transient factory resolutions so that SCOPED dependencies (e.g. UnitOfWork) are reachable from handlers.
  • Cycle detection — circular dependencies raise ResolutionError at first resolution, not at registration time.
  • Override — container.override(key, instance) replaces any registration; used in tests to swap real infrastructure for fakes.
  • No reflection at module-import time. scan() defers all class inspection to the first resolve() call.

Metadata

Release files for qx-di 1.1.0

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

Source distribution (sdist)

Source distribution for qx-di 1.1.0
File Size Uploaded Provenance Actions
qx_di-1.1.0.tar.gz 12.6 kB Without provenance Details for qx_di-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qx-di 1.1.0
File Interpreter ABI Platform Actions
qx_di-1.1.0-py3-none-any.whl Python 3 none any Details for qx_di-1.1.0-py3-none-any.whl

Total release size: 26.2 kB

Release files / qx_di-1.1.0.tar.gz

Download URL qx_di-1.1.0.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7df4b3a6b64fc5dca00c10074fee383398eabccf93f2d7ca61e83ca03f00412c
BLAKE2b-256 checksum
How to use checksums
d613da9027e2a6004db7c5d28312e9d29ec8af7274dab93d1188e4741d3ff357
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / qx_di-1.1.0-py3-none-any.whl

Download URL qx_di-1.1.0-py3-none-any.whl
Size 13.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f57d30ae1ffe76889011689ffa715b0b9e5f1766c0c4d70eef47861b48bce1d
BLAKE2b-256 checksum
How to use checksums
1cbf2389a0fb31aa80611aaf9be40320f2c5187900a5f57ef1d473d11ead5bb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Security for qx-di 1.1.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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