FastAPI-like developer experience for gRPC: pydantic-first, async, built on grpc.aio
Project description
fastgrpc2
FastAPI-подобная эргономика для gRPC. Pydantic на входе и выходе, вся механика
grpc.aio — внутри. Сестра fastkafka2: тот же стиль App /
группа / декораторы / lifespan, но для gRPC.
Стек — чистый Python на grpc.aio (C-ядро gRPC + upb + pydantic-core). Это
тонкий эргономичный слой, не новый транспорт: потолок = grpc.aio, цена —
FastAPI-стиль, а не скорость компилируемых языков.
Пример
Сервер:
from pydantic import BaseModel
from fastgrpc2 import GrpcApp, GrpcService, Context, Depends, GrpcError, StatusCode
class GetOrderRequest(BaseModel):
order_number: str
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")
app.add_service(service)
# await app.run()
Клиент:
from fastgrpc2 import GrpcClient, Channel
class OrderClient(GrpcClient):
service = "Orders"
get_order = GrpcClient.unary("GetOrder", GetOrderRequest, OrderReply)
async with Channel("127.0.0.1:50051", default_timeout=5.0) as ch:
client = OrderClient(ch)
reply = await client.get_order(GetOrderRequest(order_number="A-100"))
print(reply.status) # -> "paid"
Статус (v0.2) — v1-скоуп закрыт, всё проверено прогоном
- 4 типа вызовов:
@service.unary/unary_stream/stream_unary/stream_stream. - codec pydantic↔protobuf: динамические дескрипторы;
bool/int/float/str/bytes, вложенныеBaseModel,list[...],Optional[...](с proto3-presence). Не поддержанное (enum/dict/datetime/Union) — явныйTypeError, не заглушка. export_proto()— .proto-контракт из моделей.- Context: metadata, deadline (
time_remaining), trailing-metadata, peer. - Metadata multimap; GrpcError + StatusCode + rich-детали (
BadRequest/ErrorInfo, черезgrpc-status-details-bin). - Клиент:
Channel(переиспользуемый) + типизированныйGrpcClient, per-calltimeout/metadata. - Безопасность:
TLS/MTLS/Insecure/BearerToken. - Интерсепторы (pre-hook auth/логирование),
Depends+dependency_overrides. - Lifespan, graceful
stop(grace),run(). enable_health()(grpc.health.v1),TestClient(in-process).- Ручки:
Compression,max_send_bytes/max_recv_bytes,RetryPolicy,Keepalive; deadline-propagation по цепочке.
Проверочные прогоны (из корня пакета): smoke_test.py (вызовы/presence/rich-errors),
features_test.py (TestClient/health/bearer/overrides), tls_test.py (mTLS),
config_test.py (compression/size/interceptor/deadline), bench.py (клей-налог
над голым grpc.aio — единицы %).
Later (не v1): write()/done_writing() для bidi-клиента, server reflection, OTel, Connect/gRPC-Web, отмена-propagation, полный набор 10 google.rpc деталей с google-namespace type_url.
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 fastgrpc2-0.2.1.tar.gz.
File metadata
- Download URL: fastgrpc2-0.2.1.tar.gz
- Upload date:
- Size: 20.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57fb37fa717d8d186cc799938531f93a6de21c650dc37e6c8fb96b4e2611d55a
|
|
| MD5 |
0b5c8e5ef7ea4e511f134e05c1f03612
|
|
| BLAKE2b-256 |
aa28a91d2d41bc7f50854bf8b862d1095f6e600516f9b8bd76dfc7aaaf8f600f
|
File details
Details for the file fastgrpc2-0.2.1-py3-none-any.whl.
File metadata
- Download URL: fastgrpc2-0.2.1-py3-none-any.whl
- Upload date:
- Size: 24.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b6dd709af9411f8609589d88c00b821db770f4261c2343da5d8fe2f63496871
|
|
| MD5 |
6eaeebad103f5d9ca2b2656c9fc1caa9
|
|
| BLAKE2b-256 |
a49082d48c28aa375396c161bb6be35d153abed2b11eeefc2f866402dfabb858
|