Skip to main content

Rapid fast development of gRPC services with Pydantic models

Project description

PyPI - Downloads

FastGRPC

Lightweight framework for building gRPC services with a FastAPI-like developer experience.

FastGRPC compiles Python async callables into a generic gRPC service at runtime, supports unary and streaming handlers, dependency injection, and gRPC reflection for easy discovery and testing.

Features

  • Register async Python callables as gRPC RPCs with a decorator.
  • Support for unary, client-streaming, server-streaming and bidirectional streaming handlers.
  • Simple dependency injection via Depends(...) (similar to FastAPI).
  • Automatic compilation of request/response schemas into dynamic gRPC handlers.
  • gRPC reflection support for easier testing and tooling integration.

Quickstart

  1. Install dependencies (example using uv and pip):

    pip install fastgrpcio
    
    uv add fastgrpcio
    
  2. Define schemas and a context for your RPCs (see fastGRPC/schemas.py and fastGRPC/context.py).

  3. Create an app, register handlers and run the server.:

    • Define schemas:
     class ResponseSchema(BaseGRPCSchema):
         response: str | None
     
     class RequestSchema(BaseGRPCSchema):
         request: str
    
    • Define the app

      from fastgrpcio.fast_grpc import FastGRPC
      app = FastGRPC(app_name="HelloApp", app_package_name="test_app")
      

Register handlers using the decorator:

# unary unary handler example
 @app.register_as("unary_unary")
 async def unary_unary(data: RequestSchema, context: GRPCContext) -> ResponseSchema:
     return ResponseSchema(response=f"Hello, {data.request or "Unknown"}!")
   # client streaming handler example
@app.register_as("client-streaming")
async def client_streaming(
    data: AsyncIterator[RequestSchema], context: GRPCContext) -> ResponseSchema:

    requests: list[str] = []
    async for item in data:
        requests.append(item.request or "Unknown")

    joined = ", ".join(requests)
    return ResponseSchema(response=joined)
     # server streaming handler example
    @app.register_as("server_streaming")
    async def server_streaming(data: RequestSchema, context: GRPCContext) -> AsyncIterator[ResponseSchema]:
        for i in range(2):
            yield ResponseSchema(response=f"Goodbye count {i+1}")
# bidirectional streaming handler example
@app.register_as("bidi_streaming")
async def bidi_streaming(data: AsyncIterator[RequestSchema], context: GRPCContext) -> AsyncIterator[ResponseSchema]:

    async for item in data:
        yield ResponseSchema(response=f"Echo: {item.request}")
  • Start the server:

    asyncio.run(app.serve())
    

Handler types supported

  • Unary: single request -> single response
  • Client streaming: async iterator request -> single response
  • Server streaming: request -> async iterator responses
  • Bidirectional streaming: async iterator request -> async iterator responses

Dependencies

FastGRPC integrates a simple Depends(...) mechanism (see examples) to inject values into handler signatures. Use synchronous functions or callables that return values needed by handlers.

Reflection and discovery

gRPC reflection is enabled by default so tools like Evans, grpcurl, and Protobuf-backed clients can discover the compiled service and RPC definitions at runtime.

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

fastgrpcio-0.1.2.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

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

fastgrpcio-0.1.2-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file fastgrpcio-0.1.2.tar.gz.

File metadata

  • Download URL: fastgrpcio-0.1.2.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.12

File hashes

Hashes for fastgrpcio-0.1.2.tar.gz
Algorithm Hash digest
SHA256 86173880251d014ffde87fb0f1e504e2b93077e87e03155b8108f9e2e5619595
MD5 1744679d7c5d850cfb99c9ac73427876
BLAKE2b-256 32ecf94794923b06e031fa3038ecd1f9c542f73f9b76c70c5d6af9e3b97b0724

See more details on using hashes here.

File details

Details for the file fastgrpcio-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: fastgrpcio-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.12

File hashes

Hashes for fastgrpcio-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5c72cce11543b5dcf6e8280b36e39ff10ff4135369b9a203463f267b4e7d126c
MD5 ae8dd6039687a9a5f7a0ec079fae65b2
BLAKE2b-256 cc4798b5d40bae37d337205e6d7c15d42e028e2d2978a0a39355f7dd15ddbe2c

See more details on using hashes here.

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