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")
Metadata
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)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| python_fast_grpc-0.3.4.tar.gz | 17.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|
Security for python-fast-grpc 0.3.4
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.