This is an async Python gRPC consumer that connects to the SISSync service and listens for Person and Course events, mirroring the TypeScript example in consumers/ts/src/main.ts.
consumers/
python/
generated/ # gRPC-generated Python code from proto/eduapi.proto
main.py # The async consumer script
requirements.txt # Python dependencies
README.md # This file
- Python 3.11+ (recommended)
- gRPC server running at
localhost:50051(e.g., mock-sis)
-
Create and activate the virtual environment:
python3.11 -m venv venv source venv/bin/activate -
Install dependencies:
pip install -r requirements.txt
-
(Re)generate gRPC code (if
proto/eduapi.protochanges):python3 -m grpc_tools.protoc -I ../../proto --python_out=generated --grpc_python_out=generated ../../proto/eduapi.proto
Fix import issue in generated code: After regenerating, you may need to fix the import in
generated/eduapi_pb2_grpc.pyto avoidModuleNotFoundError. Run:sed -i '' 's/^import eduapi_pb2 as eduapi__pb2$/from . import eduapi_pb2 as eduapi__pb2/' consumers/python/generated/eduapi_pb2_grpc.py
Ensure
generated/__init__.pyexists:touch consumers/python/generated/__init__.py
Make sure your gRPC server is running at localhost:50051.
python3 main.py- The consumer will concurrently listen for both Person and Course events.
- It logs received events and displays running counts.
- Handles stream resets as well.
Note:
- If you change the proto file, always regenerate the gRPC code as shown above.
- This consumer is fully async and uses
grpc.aiofor non-blocking streaming. - For questions or issues, check your Python version and ensure all dependencies are installed in your virtual environment.