fastgrpc2
A FastAPI-style developer experience for gRPC — pydantic-first, async, and typed.
Write an async handler that takes a plain Pydantic request and returns a Pydantic response.
fastgrpc2 derives the protobuf contract from your annotations, (de)serializes over real
gRPC/HTTP-2, injects your dependencies, and never makes you touch grpc.aio, a _pb2 stub,
or a hand-written .proto. It's a thin layer on top of the grpc.aio C-core.
Documentation: https://fastgrpc.ru
Install
pip install fastgrpc2
Requires Python 3.10+. Pulls in grpcio, protobuf, and pydantic.
Example
Server:
from pydantic import BaseModel, Field
from fastgrpc2 import Context, GrpcApp, GrpcError, GrpcService, StatusCode, TLS
class GetOrderRequest(BaseModel):
order_number: str = Field(min_length=1)
class OrderReply(BaseModel):
order_number: str
status: str
service = GrpcService("Orders")
@service.unary("GetOrder")
async def get_order(request: GetOrderRequest, ctx: Context) -> OrderReply:
if not request.order_number:
raise GrpcError(StatusCode.INVALID_ARGUMENT, "order_number required")
return OrderReply(order_number=request.order_number, status="paid")
app = GrpcApp(
"orders",
address="0.0.0.0:50051",
tls=TLS(cert="server.crt", key="server.key"),
)
app.add_service(service)
# import asyncio; asyncio.run(app.run())
Client:
from fastgrpc2 import Channel, GrpcClient, TLS
class OrderClient(GrpcClient):
service = "Orders"
get_order = GrpcClient.unary("GetOrder", GetOrderRequest, OrderReply)
async with Channel("orders.internal:50051", tls=TLS(ca="ca.crt"), default_timeout=5.0) as ch:
client = OrderClient(ch)
reply = await client.get_order(GetOrderRequest(order_number="A-100"))
print(reply.status) # -> "paid"
Features
- All four call types —
@service.unary/unary_stream/stream_unary/stream_stream, inferred from the handler signature. - Pydantic ↔ protobuf contracts — plain models just work (field numbers follow
declaration order); pin them with
Annotated[..., ProtoField(n)]when a contract is public and must stay stable. Validated on decode; scalars, nested models,list,Optional(proto3 presence),Enum,datetime/date; anything without a clean proto mapping falls back to a JSON carrier, so a model never fails to register. - Schema, the way Swagger serves OpenAPI —
app.enable_reflection()letsgrpcurl,grpcuiand Postman read the schema off a running server, andpython -m fastgrpc2 export module:app -o contract.protowrites the.protofor consumers in other languages and for diffing in CI. - Context — metadata, deadline, trailers, and peer, kept out of the message body.
- Errors —
GrpcError+ the fullStatusCodeenum + richgoogle.rpc-style details. - Client — a reusable
Channeland a typedGrpcClient; per-calltimeout/metadata. - Security — fail-closed explicit
TLS/MTLS/Insecure; bearer credentials are rejected on plaintext channels and redacted from representations. - DI & middleware —
Dependswithdependency_overrides, and interceptors. - Ops —
enable_health()(grpc.health.v1), gracefulstop(grace), lifespan,Compression, bounded messages/metadata/concurrency, method-scopedRetryPolicy,Keepalive, and deadline propagation across service hops. - Testing — an in-process
TestClient.
Performance
fastgrpc2 is a thin layer: the transport is the gRPC C-core, the codec is protobuf upb (C),
and validation is pydantic-core (Rust). The framework adds single-digit % over a hand-written
grpc.aio servicer running the identical handler. Its ceiling is Python's grpc.aio —
ergonomics at low cost, not the throughput of compiled languages. See the
benchmarks.
License
MIT © Ruslan Kiradiev
Metadata
Release files for fastgrpc2 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastgrpc2-0.5.0.tar.gz | 49.4 kB | Without provenance | Details for fastgrpc2-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastgrpc2-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for fastgrpc2-0.5.0-py3-none-any.whl |
Total release size: 88.4 kB
Release files / fastgrpc2-0.5.0.tar.gz
| Download URL | fastgrpc2-0.5.0.tar.gz |
|---|---|
| Size | 49.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9c6359251fe22c0634bb03f37583ad23c8a5269d877f7cff9b797aa263036502
|
|
BLAKE2b-256 checksum How to use checksums |
226ad5481bbc69f10f9058231b4564e82899de7b9066fe404ba6ef85cf0568a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / fastgrpc2-0.5.0-py3-none-any.whl
| Download URL | fastgrpc2-0.5.0-py3-none-any.whl |
|---|---|
| Size | 39.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
16681c60e178586ecdd6259797b55afca984b8e4a983d368d13bb44a9c6f2ff0
|
|
BLAKE2b-256 checksum How to use checksums |
9c27765320031e1ca9cca8f009b0e40a363e1480cc7bd0de5c7729cd31477ef3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Security for fastgrpc2 0.5.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.