Skip to main content

Protobuf integration for the BlackBull ASGI framework's gRPC support: servicer adapter, server reflection, health checking, and rich error details.

Project description

blackbull-protobuf

Protobuf integration for the BlackBull ASGI framework's gRPC support: object-typed servicers, server reflection, health checking, and rich error details.

BlackBull's core gRPC layer (blackbull.grpc) is deliberately protobuf-free — handlers exchange raw message bytes. This package adds everything whose payloads are protobuf on the wire, as a separate installable so the protobuf runtime never enters the framework's dependency metadata and can version independently.

pip install 'blackbull[protobuf]'      # or: pip install blackbull-protobuf

Object-typed handlers (add_servicer)

Write servicers against your generated *_pb2 messages. The adapter reflects over the service descriptor, wires every implemented method onto a GrpcServiceRegistry with the right streaming shape, and does FromString/SerializeToString at the boundary:

from blackbull import BlackBull
from blackbull.grpc import GrpcServiceRegistry
from blackbull_protobuf import add_servicer
import helloworld_pb2

class Greeter:                       # duck-typed; a generated
    async def SayHello(self, request, context):        # <Service>Servicer
        return helloworld_pb2.HelloReply(               # base also works
            message=f'Hello, {request.name}!')

    async def SayManyHellos(self, request, context):   # server-streaming
        for i in range(3):
            yield helloworld_pb2.HelloReply(message=f'{request.name} #{i}')

app = BlackBull()
registry = GrpcServiceRegistry()
add_servicer(registry, Greeter(), helloworld_pb2)
app.enable_grpc(registry)
app.run(port=8443, cert='cert.pem', key='key.pem')

All four RPC shapes are supported — unary, server-streaming (async generator), client-streaming (request_iter of messages), and bidirectional. The raw-bytes registry path is untouched; both styles coexist on one registry.

Server reflection

grpcurl / grpc_cli / Postman work without local .proto files:

from blackbull_protobuf import enable_reflection
enable_reflection(registry)   # serves both grpc.reflection.v1 and v1alpha

Both reflection package versions are registered — v1alpha for older clients and v1 for the newer ones that probe it first — so every client generation resolves the endpoint on the first request.

$ grpcurl -insecure localhost:8443 list
$ grpcurl -insecure localhost:8443 describe helloworld.Greeter
$ grpcurl -insecure -d '{"name": "world"}' localhost:8443 helloworld.Greeter/SayHello

Health checking

The standard grpc.health.v1.Health service (Check + Watch) behind a settable status map — the Kubernetes / load-balancer probe surface:

from blackbull_protobuf import enable_health, HealthService

health = enable_health(registry)
health.set('helloworld.Greeter', HealthService.SERVING)
health.set('helloworld.Greeter', HealthService.NOT_SERVING)   # during drain

Rich error details

Attach structured google.rpc details that ride the grpc-status-details-bin trailer, decoded on a grpcio client by grpc_status.rpc_status.from_call:

from google.rpc import error_details_pb2
from blackbull.grpc import GrpcStatus
from blackbull_protobuf import abort_with_details

bad = error_details_pb2.BadRequest()
bad.field_violations.add(field='name', description='must not be empty')
abort_with_details(context, GrpcStatus.INVALID_ARGUMENT,
                   'name is required', [bad])

Design notes

  • The vendored grpc.health.v1 / grpc.reflection.v1alpha / grpc.reflection.v1 descriptors are embedded as serialized FileDescriptorProtos and loaded into a private descriptor pool — no generated code (so no protoc↔runtime version-lock), and no duplicate-file collision when the host application also imports grpcio-health-checking / grpcio-reflection gencode.
  • Reflection describes every service registered through this package and lists raw-bytes services too (they have no descriptors to describe).
  • Requires BlackBull ≥ 0.51.0 (the error-path trailing-metadata contract that grpc-status-details-bin rides on).

Development

pip install -e '.[testing]'
python -m pytest tests/ -q
python scripts/gen_descriptors.py     # after touching protos/

License: Apache-2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

blackbull_protobuf-0.2.0.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

blackbull_protobuf-0.2.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file blackbull_protobuf-0.2.0.tar.gz.

File metadata

  • Download URL: blackbull_protobuf-0.2.0.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for blackbull_protobuf-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e8e715e87c669c689956a014e57fa58c4b910753bb5984418b7cdd5ced77c186
MD5 350d602e4c6bf92193e47919099f9ec3
BLAKE2b-256 78779732af99dfd2f877b20a7b61b7ab13f06b220be58c58fcdf40cd2f02705e

See more details on using hashes here.

Provenance

The following attestation bundles were made for blackbull_protobuf-0.2.0.tar.gz:

Publisher: publish.yml on TOKUJI/blackbull-protobuf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file blackbull_protobuf-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for blackbull_protobuf-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 44c08ebf2ce75a59e2123869c254732f3c42275ed11ee1ca2eaf2040ba30c3b7
MD5 40b16be5b89861d815c196ecf2a1aa1e
BLAKE2b-256 6b3f4f7951888456789c3b13bcb9c42963f5cea6cf941246ca68eb19fb84737b

See more details on using hashes here.

Provenance

The following attestation bundles were made for blackbull_protobuf-0.2.0-py3-none-any.whl:

Publisher: publish.yml on TOKUJI/blackbull-protobuf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page