Skip to content

Latest commit

 

History

History
58 lines (45 loc) · 2.36 KB

README.md

File metadata and controls

58 lines (45 loc) · 2.36 KB

Connecpy Examples

Requirements

You can install requirements for running the examples with executing the following command on the root directory of this repository:

uv sync

Running server (ASGI)

You can run the Connecpy ASGI application using servers such as uvicorn. Example uvicorn command : uv run uvicorn --port 3000 server:app

Running server (WSGI)

You can run the Connecpy WSGI application using the following command : uv run wsgi_server.py

Running client

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"

Generated code

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:

  1. Install protoc-gen-connecpy plugin using steps given here
  2. Generate code for haberdasher using connecpy plugin : uv run python -m grpc_tools.protoc --python_out=. --pyi_out=. --connecpy_out=. -I . haberdasher.proto or protoc --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.

gRPC Examples

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.

Runnning gRPC server

You can run the gRPC server using the following command : uv run grpc_server.py

Running gRPC client

After gRPC server has started, you can make request using the example client with the following command : uv run grpc_client.py

Generated code

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.