Skip to main content

FastGRPC

🚀 Build gRPC services in Python 3.9+ as easily as FastAPI.

Installation

Require Python 3.9+

pip install python-fast-grpc

A Simple Example

Define a gRPC service:

from pydantic import BaseModel
from fast_grpc import FastGRPC

app = FastGRPC()

class HelloRequest(BaseModel):
    name: str

class HelloReply(BaseModel):
    message: str

@app.unary_unary()
async def say_hello(request: HelloRequest) -> HelloReply:
    return HelloReply(message=f"Greeter SayHello {request.name}")

if __name__ == '__main__':
    app.run()

Client Test:

import grpc
import fast_grpc_pb2 as pb2
import fast_grpc_pb2_grpc as pb2_grpc

channel = grpc.insecure_channel("127.0.0.1:50051")
stub = pb2_grpc.FastGRPCStub(channel)
response = stub.SayHello(pb2.HelloRequest(name="FastGRPC"))
print("Client received: ", response)

Use Middleware

@app.middleware()
async def middleware(call_next, request, context):
    print("before request")
    response = await call_next(request, context)
    print("after request")
    return response

@app.middleware(is_server_streaming=True)
async def middleware(call_next, request, context):
    print("before streaming request")
    async for response in call_next(request, context):
        yield response
    print("after streaming request")

Service

Use Service for modular design, similar to FastAPI's router.

from fast_grpc import Service
srv = Service(name="Greeter")

@srv.unary_unary()
async def say_again(request: HelloRequest) -> HelloReply:
    return HelloReply(message=f"Greeter SayHello {request.name}")

Pb2Service

Use Pb2Service if you're working with generated *_pb2.py and *_pb2_grpc.py files.

import greeter_pb2
import greeter_pb2_grpc
srv = Pb2Service("Greeter", pb2_module=greeter_pb2, pb2_grpc_module=greeter_pb2_grpc)

@srv.unary_unary()
async def say_again(request: HelloRequest) -> HelloReply:
    return HelloReply(message=f"Greeter SayHello {request.name}")

Generate Clients Using Pydantic

Automatically generate a Pydantic-based gRPC client from .proto files:

from fast_grpc.proto import proto_to_python_client
proto_to_python_client("fast_grpc.proto")

Release files for python-fast-grpc 0.3.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-fast-grpc 0.3.4
File Size Uploaded
python_fast_grpc-0.3.4.tar.gz 17.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-fast-grpc 0.3.4
File Interpreter ABI Platform
python_fast_grpc-0.3.4-py3-none-any.whl Python 3 none any Details

Total release size: 37.9 kB

Release files / python_fast_grpc-0.3.4.tar.gz

Download URL python_fast_grpc-0.3.4.tar.gz
Size 17.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f3f0530fc9614300df0caa71af826cefd953cc957aa850e7acfaef692efae129
BLAKE2b-256 checksum
How to use checksums
59c6e14c19520af71df830e56b5215190bc91dc569bff79696c4db4ae8fdc059
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.9.6 Darwin/24.6.0

Release files / python_fast_grpc-0.3.4-py3-none-any.whl

Download URL python_fast_grpc-0.3.4-py3-none-any.whl
Size 20.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5efcf4453fa764047c44565072eed0333a19d7f8ff07933112f4c0a1988c5371
BLAKE2b-256 checksum
How to use checksums
dd4f54d9bd3323002a092e9487d00da4670c2e55805f019b23a774141bdd9f0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.9.6 Darwin/24.6.0

Release history Release notifications | RSS feed

This release

0.3.4 This release

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page