Skip to content

Latest commit

 

History

History
73 lines (47 loc) · 2.26 KB

File metadata and controls

73 lines (47 loc) · 2.26 KB

PythonGRPC

Python backend for image manipulation and processing. Data transmission and communication using gRPC

  1. Prerequisites
  2. Generate gRPC Code (Python)
  3. Run Python server
  4. Build Python server
  5. Deploy and start with electron app

Prerequisites

  • Python > 3.5
  • pip > 9.01

PyCharm Setup

  • setup a virtual environment and specify an appropriate interpreter
  • create run configuration
  • for debug purposes: specify environment variables for run config:
  GRPC_VERBOSITY=DEBUG
  GRPC_TRACE=api,client_channel_routing,cares_resolver

Update pip

python -m pip install --upgrade pip (need admin rights)

install packages

  pip install -r requirements.txt     // for installing dependencies
  
  pip freeze > requirements.txt       // update requirements after after installing new packages

Generate gRPC Code (Python)

  • Protos are located in python/protos
  • to generate code (greet_pb2_grpc and greet_pb2), use the terminal command:
  python -m grpc_tools.protoc -I . --python_out=. --grpc_python_out=. ./generated_services/*.proto --pyi_out=.
  • this creates the grpc code in generated_services/

  • REMARK: python does not allow to generate files in another directory than the proto file (see gitHub discussion)

  • REMARK: the __pyi_out flag generates metaclasses for message types(see StackOverflow issue). This is not necessary for protobuf to work, but for python auto-completion

  • import files using:

      from generated_services import greet_pb2, greet_pb2_grpc

Run Python server

open Terminal and run python main.py from inside python folder

server serves on port 50051, defined in main.py

implementation follows example from official documentation

Service is implemented in service/interactionProcessingService.py

Build Python server

TODO: How to build an executable ?

Deploy and start with electron app

TODO: Deployment / Packaging und auto-(re)start