Skip to main content

qx-http

FastAPI integration layer for the Qx framework — envelope responses, DI bridge, Result-to-HTTP error mapping, middleware, and health probes.

What lives here

  • qx.http.setup_qx_app — one-call FastAPI application factory. Mounts routers, installs middleware, registers exception handlers, and attaches the DI container.
  • qx.http.Inject — FastAPI Depends-compatible DI bridge. Resolves any registered type from the container for use in route function signatures.
  • qx.http.scope_dep — Depends factory that opens a per-request DI scope, shared across all dependencies in the same request.
  • qx.http.unwrap — extracts the value from a Result[T], raising an ErrorException (translated to HTTP by the exception handler) on failure.
  • qx.http.envelope_success / envelope_failure — build the standard {"success": true, "data": ..., "metadata": ...} response shape.
  • qx.http.ApiResponse / ApiError / ApiMetadata — Pydantic models for the response envelope.
  • qx.http.RequestContextMiddleware — populates RequestContext (request_id, correlation_id, trace_id, tenant_id) from incoming headers for every request.
  • qx.http.MetricsMiddleware — records request duration and status-code counters via Prometheus.
  • qx.http.make_probes_router — /healthz (liveness) and /readyz (readiness) endpoints backed by HealthRegistry.
  • qx.http.install_exception_handlers — maps ErrorException subclasses to HTTP status codes (DomainError → 422, NotFoundError → 404, ConflictError → 409, etc.).

Usage

from fastapi import APIRouter, Depends
from qx.http import Inject, envelope_success, scope_dep, setup_qx_app, unwrap
from qx.cqrs import Mediator
from qx.di import Scope

router = APIRouter(prefix="/users")

@router.post("", status_code=201)
async def create_user(
    cmd: CreateUserCommand,
    mediator: Mediator = Inject(Mediator),  # noqa: B008
    scope: Scope = Depends(scope_dep),      # noqa: B008
) -> dict:
    result = await mediator.send(cmd, scope=scope)
    return envelope_success(unwrap(result))


def build_app() -> FastAPI:
    return setup_qx_app(
        settings=settings,
        container=container,
        routers=[router],
        metrics=metrics,
        health=health,
    )

Response envelope

All successful responses follow:

{
  "success": true,
  "data": { ... },
  "metadata": { "page": 1, "page_size": 20, "total": 57 }
}

All error responses follow:

{
  "success": false,
  "error": { "code": "user.not_found", "message": "User 123 not found", "details": {} }
}

Design rules

  • Inject(T) is syntactic sugar for Depends(lambda: container.resolve(T, scope=...)). The scope is shared within a request via FastAPI's dependency deduplication on scope_dep.
  • Do not use from __future__ import annotations in route files — FastAPI reads annotations at runtime for OpenAPI schema generation and body parsing.
  • Runtime imports (not under TYPE_CHECKING) are required for any type used as a FastAPI body parameter, Inject target, or Pydantic field.

Metadata

Release files for qx-http 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-http 1.1.0
File Size Uploaded Provenance Actions
qx_http-1.1.0.tar.gz 10.9 kB Without provenance Details for qx_http-1.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 23.5 kB

Release files / qx_http-1.1.0.tar.gz

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

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

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

Security for qx-http 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.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

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