gRPC for Python
gRPC is a high-performance, open-source RPC framework that uses HTTP/2 for transport. The 'grpcio' package provides the core gRPC functionality for Python, enabling developers to build efficient and scalable services. The current version is 1.78.0, with regular updates to enhance performance and address issues.
Warnings
- breaking Python 2.7 support was removed on January 1, 2020.
- gotcha Generated Python code from .proto files may have absolute imports, causing import errors in certain project structures.
- gotcha Installation issues may arise due to setuptools version conflicts.
Install
-
pip install grpcio -
pip install grpcio-tools
Imports
- grpc
import grpc
- grpc_tools
import grpc_tools
Quickstart
import grpc
from concurrent import futures
# Define the server
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
# Add your service implementations here
# Start the server
server.add_insecure_port('[::]:50051')
server.start()
server.wait_for_termination()