Skip to main content

Rapid fast development of gRPC services with Pydantic models

Project description

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.0.tar.gz (9.9 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.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fastgrpcio-0.1.0.tar.gz
Algorithm Hash digest
SHA256 37ee1c038ac6d7036bb8f46bede684d213ec541252b91f1c5036223447889c6a
MD5 5732b923446fec110cf0f25a927b708e
BLAKE2b-256 33b15067df96884b6d2c3f562dd2b1d52f14bab48ecd95ef72bc6585c84ee858

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for fastgrpcio-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e22c5493bce32f48debecb94977cf627c01db068129235452abf24dc6d7df2d2
MD5 342b2582fe5a34804486857155145d8f
BLAKE2b-256 8e44a0343a44bdaca87a16283494c5a1700f30e3242f7d5e54cdc38695d5b2bc

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