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.v1alphadescriptors are embedded as serializedFileDescriptorProtos 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 importsgrpcio-health-checking/grpcio-reflectiongencode. - 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-binrides 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ddd7b40c3fdd5f494f59f78dc582b330a6d1defcf6e2c53e9e1c93e2e7a53e2
|
|
| MD5 |
a6f9f24439474b5f271f368553f8f833
|
|
| BLAKE2b-256 |
07e0dd6d30edbe773df3cd076c597d4d8b4225accaa874d630c6884d6d5c0dc3
|
Provenance
The following attestation bundles were made for blackbull_protobuf-0.1.0.tar.gz:
Publisher:
publish.yml on TOKUJI/blackbull-protobuf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
blackbull_protobuf-0.1.0.tar.gz -
Subject digest:
0ddd7b40c3fdd5f494f59f78dc582b330a6d1defcf6e2c53e9e1c93e2e7a53e2 - Sigstore transparency entry: 2145719689
- Sigstore integration time:
-
Permalink:
TOKUJI/blackbull-protobuf@6f5c9adb3ce6044efe6bdcd2f476c74b7ea41d7f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/TOKUJI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6f5c9adb3ce6044efe6bdcd2f476c74b7ea41d7f -
Trigger Event:
push
-
Statement type:
File details
Details for the file blackbull_protobuf-0.1.0-py3-none-any.whl.
File metadata
- Download URL: blackbull_protobuf-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16ab288aa5c21ffff5cda5a86d95b6e563d5512d33123ca5fadf23af8246be48
|
|
| MD5 |
9ec4f0115467789d1b4f4d0d3e52997c
|
|
| BLAKE2b-256 |
e49fdd1fb9904f60667580cdefc472d3711d2cbb3fef71fdaf34e4eecb88902c
|
Provenance
The following attestation bundles were made for blackbull_protobuf-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on TOKUJI/blackbull-protobuf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
blackbull_protobuf-0.1.0-py3-none-any.whl -
Subject digest:
16ab288aa5c21ffff5cda5a86d95b6e563d5512d33123ca5fadf23af8246be48 - Sigstore transparency entry: 2145719694
- Sigstore integration time:
-
Permalink:
TOKUJI/blackbull-protobuf@6f5c9adb3ce6044efe6bdcd2f476c74b7ea41d7f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/TOKUJI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6f5c9adb3ce6044efe6bdcd2f476c74b7ea41d7f -
Trigger Event:
push
-
Statement type: