A minimal template to start with a Python GRPC Server w/ Protobuf, Conda. Example used from grpc repository.
python | pip | grpcio | grpcio-tools |
---|---|---|---|
3.7 | 19.3.1 | 1.25.0 | 1.25.0 |
(1) First install the environment described in section: Install.
(2) Compile client/server-side code with the following command:
make proto
(3) To test: Run python -m src.main
and python -m src.greeter_client
in two separat python shells.
(4) Normally, you would start the service by running python -m src.main
.
Package | Description |
---|---|
grpc |
GRPC Utils & Server |
models |
Model Definitions |
proto |
Generated Protobuf files |
services |
Implementation of the Protobuf API |
store |
Global Service Store |
Use one of the following options to use the template:
- Use this template as described here.
- Clone this template
git clone https://github.com/chryb/python-package-template.git
and remove git within the dictionaryrm -rf .git
.
- Install Python3 and pip3
- Install Miniconda
- (Update) To update conda run
conda update conda
Run this command to create the environment:
conda env create -f environment.yml --prefix ./env
To activate the created environment:
conda activate ./env
To deactivate the actual environment:
conda deactivate
To update the environment, all you need to do is update the contents of your environment.yml
file accordingly and then run the following command:
conda env update --prefix ./env --file environment.yml --prune
To list all installed packages in the environment run conda list
To list all conda environments run conda env list
or conda info --envs
To remove the environment just remove the .env
dictionary.
For more information see the conda documentation.
Don't forget to start with activating the environment with conda activate ./env
.
Linting the package is powered by flake8. Just run flake8 src/
to lint the project or flake8 src/file.py
to lint a specific file.
Run tests by using pytest with pytest -q tests/test.py
.