You can install requirements for running the examples with executing the following command on the root directory of this repository:
uv sync
You can run the Connecpy ASGI application using servers such as uvicorn.
Example uvicorn command : uv run uvicorn --port 3000 server:app
You can run the Connecpy WSGI application using the following command :
uv run wsgi_server.py
After server has started, you can make request using the example client with the following command :
uv run async_client.py
or uv run client.py
Example output :
size: 12
color: "black"
name: "bowler"
The example server and client makes use of code generated by protoc-gen-connecpy
plugin. You can find the code in .
folder. To generate the code yourself for haberdasher
, use the steps given below:
- Install
protoc-gen-connecpy
plugin using steps given here - Generate code for
haberdasher
using connecpy plugin :uv run python -m grpc_tools.protoc --python_out=. --pyi_out=. --connecpy_out=. -I . haberdasher.proto
orprotoc --python_out=. --pyi_out=. --connecpy_out=. -I . haberdasher.proto
- python_out : The directory where generated Protobuf Python code needs to be saved.
- pyi_out : The directory where generated Python stub code for Protobuf Messages needs to be saved.
- connecpy_out : The directory where generated Connecpy Python server and client code needs to be saved.
Connecpy does not support gRPC. However, you can use the same service code to run a gRPC server and client.
grpc_server.py
uses the same service code as server.py
.
You can run the gRPC server using the following command :
uv run grpc_server.py
After gRPC server has started, you can make request using the example client with the following command :
uv run grpc_client.py
uv run python -m grpc_tools.protoc --python_out=. --pyi_out=. --grpc_python_out=. -I . haberdasher.proto
- python_out : The directory where generated Protobuf Python code needs to be saved.
- pyi_out : The directory where generated Python stub code for Protobuf Messages needs to be saved.
- grpc_python_out : The directory where generated gRPC Python server and client stub code needs to be saved.