Skip to main content

qx-grpc

gRPC server factory and interceptor suite for the Qx framework — RequestContext propagation, Prometheus metrics, and Result-to-gRPC-status mapping.

What lives here

  • qx.grpc.create_grpc_server — builds an async gRPC server with the standard Qx interceptor stack pre-installed. Accepts a list of servicer registrations and optional port configuration.
  • qx.grpc.RequestContextInterceptor — extracts request_id, correlation_id, tenant_id, and OTel trace context from incoming gRPC metadata and populates RequestContext via contextvars, matching the behaviour of RequestContextMiddleware in qx-http.
  • qx.grpc.MetricsInterceptor — records per-method request counts and durations as Prometheus metrics.
  • qx.grpc.ExceptionInterceptor — catches ErrorException (and unexpected exceptions) and converts them to the appropriate gRPC StatusCode using status_from_error.
  • qx.grpc.status_from_error — maps Qx Error subclasses to gRPC status codes (NotFoundError → NOT_FOUND, ConflictError → ALREADY_EXISTS, ValidationError → INVALID_ARGUMENT, etc.).
  • qx.grpc.abort_with_error — convenience helper that calls status_from_error and raises the appropriate grpc.aio.AbortError.

Usage

from qx.grpc import create_grpc_server
import grpc
from myapp.grpc import user_pb2_grpc, UserServicer

server = create_grpc_server(
    port=50051,
    metrics=metrics,
    servicers=[
        (user_pb2_grpc.add_UserServiceServicer_to_server, UserServicer(container)),
    ],
)

await server.start()
await server.wait_for_termination()

Servicer using the Mediator

from qx.grpc import abort_with_error
from qx.cqrs import Mediator

class UserServicer(UserServiceServicer):
    def __init__(self, container: Container) -> None:
        self._mediator = container.resolve_sync(Mediator)

    async def GetUser(self, request, context):
        result = await self._mediator.send(GetUserQuery(user_id=UUID(request.user_id)))
        if not result.is_success:
            abort_with_error(context, result.error)
        return UserResponse(id=str(result.value.id), email=result.value.email)

Design rules

  • Interceptors mirror the HTTP middleware stack so gRPC and HTTP endpoints have identical observability and context propagation behaviour.
  • status_from_error is the single mapping point between Qx errors and gRPC statuses — extend it for domain-specific status codes rather than mapping in individual servicers.
  • This package is a V2 scope item; the API is stable but the servicer helpers are intentionally thin. Heavy gRPC-specific logic belongs in the service layer, not the framework.

Metadata

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

Built distribution (wheel)

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

Total release size: 18.9 kB

Release files / qx_grpc-1.1.0.tar.gz

Download URL qx_grpc-1.1.0.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
aa3e1a6ce0f4cc506f85d0b638c65cb9fbf672310175379bd4953d57f5578ae0
BLAKE2b-256 checksum
How to use checksums
0358573711fa07da849dc476864bfed35706e5e5dc60fd706effd997df86f4b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

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

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

Security for qx-grpc 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