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)
$ 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 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.1.0.tar.gz (24.5 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.1.0-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: blackbull_protobuf-0.1.0.tar.gz
  • Upload date:
  • Size: 24.5 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.1.0.tar.gz
Algorithm Hash digest
SHA256 0ddd7b40c3fdd5f494f59f78dc582b330a6d1defcf6e2c53e9e1c93e2e7a53e2
MD5 a6f9f24439474b5f271f368553f8f833
BLAKE2b-256 07e0dd6d30edbe773df3cd076c597d4d8b4225accaa874d630c6884d6d5c0dc3

See more details on using hashes here.

Provenance

The following attestation bundles were made for blackbull_protobuf-0.1.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.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for blackbull_protobuf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 16ab288aa5c21ffff5cda5a86d95b6e563d5512d33123ca5fadf23af8246be48
MD5 9ec4f0115467789d1b4f4d0d3e52997c
BLAKE2b-256 e49fdd1fb9904f60667580cdefc472d3711d2cbb3fef71fdaf34e4eecb88902c

See more details on using hashes here.

Provenance

The following attestation bundles were made for blackbull_protobuf-0.1.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