{"id":19500030,"url":"https://github.com/anuprshetty/py_grpc","last_synced_at":"2026-04-16T05:04:30.163Z","repository":{"id":177135504,"uuid":"447456766","full_name":"anuprshetty/py_grpc","owner":"anuprshetty","description":"gRPC implementation in Python.","archived":false,"fork":false,"pushed_at":"2024-02-27T02:28:07.000Z","size":452,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-08T10:10:52.034Z","etag":null,"topics":["flask","grpc","load-testing","locust","multithreading","protobuf","python","rest-api","shell-script"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anuprshetty.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-01-13T03:59:23.000Z","updated_at":"2024-05-10T13:09:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"fa0be873-7dbc-4a09-b7cf-184466d188e3","html_url":"https://github.com/anuprshetty/py_grpc","commit_stats":null,"previous_names":["anuprshetty/py_grpc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anuprshetty%2Fpy_grpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anuprshetty%2Fpy_grpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anuprshetty%2Fpy_grpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anuprshetty%2Fpy_grpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anuprshetty","download_url":"https://codeload.github.com/anuprshetty/py_grpc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240747857,"owners_count":19851158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flask","grpc","load-testing","locust","multithreading","protobuf","python","rest-api","shell-script"],"created_at":"2024-11-10T22:07:16.253Z","updated_at":"2026-04-16T05:04:28.811Z","avatar_url":"https://github.com/anuprshetty.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Py_gRPC\n\ngRPC implementation in Python.\n\n## Locust Tool - Load Testing Report\n\n- **gRPC load testing report:**\n  ![grpc_load_test_report](media/grpc_load_test_report.png)\n- **REST load testing report:**\n  ![rest_load_test_report](media/rest_load_test_report.png)\n\n## Requirements\n\n- Python 3.6.15\n\n## Project Setup and Execution\n\n- clone py_grpc project\n- cd py_grpc\n- python -m venv venv\n- source venv/bin/activate\n- pip install -r requirements.txt\n\n### gRPC\n\n- In REST call --\u003e request_message --\u003e HTTP payload --\u003e TCP payload --\u003e etc.\n- But In gRPC call --\u003e request_message --\u003e TCP payload --\u003e etc.\n- So when a grpc_request_message reaches server (TCP payload), the expectation is GRPC service should directly get this TCP payload and proceed.\n- But now what's happening is grpc_request_message reaches server (TCP payload). Server passes it to uwsgi which thinks that it's a http protocol payload and tries to unpack it. This might be the reason for failure.\n\n### Unary gRPC\n\nThis is a simple gRPC which works like a normal function call. It sends a single request declared in the .proto file to the server and gets back a single response from the server.\n\n### Unary gRPC Setup and Execution\n\n- [OPTIONAL] python -m grpc_tools.protoc --proto_path=./protobufs ./protobufs/unary.proto --python_out=./unary_grpc --grpc_python_out=./unary_grpc\n- In one terminal --\u003e python ./unary_grpc/unary_server.py\n- In another terminal --\u003e python ./unary_grpc/unary_client.py\n\n### Bidirectional gRPC\n\nBoth gRPC client and the gRPC server use a read-write stream to send a message sequence. Both operate independently, so gRPC clients and gRPC servers can write and read in any order they like, i.e. the server can read a message then write a message alternatively, wait to receive all messages then write its responses, or perform reads and writes in any other combination.\n\nNOTE: gRPC guarantees the ordering of messages within an individual RPC call. In the case of Bidirectional streaming, the order of messages is preserved in each stream.\n\n### Bidirectional gRPC Setup and Execution\n\n- [OPTIONAL] python -m grpc_tools.protoc --proto_path=./protobufs ./protobufs/bidirectional.proto --python_out=./bidirectional_grpc --grpc_python_out=./bidirectional_grpc\n- In one terminal --\u003e python ./bidirectional_grpc/bidirectional_server.py\n- In another terminal --\u003e python ./bidirectional_grpc/bidirectional_client.py\n\n## REST and gRPC Dual Mode\n\nThis POC shows working simultaneously with both REST and gRPC services listening at different ports in the same application.\n\n### Advantages of REST and gRPC Dual Mode POC\n\n- Decouples core business logic and data communication logic (SOAP, REST, gRPC, etc.).\n- Application can be extended to any type of data communication format with minimal changes without affecting business logic.\n- Generalizing application structure (standardization) which brings many possibilities and helps in many scenarios like...\n  - Supporting many data communication formats at a time.\n  - Migrating from one data communication format to another with minimal effort, taking one chunk at a time. No need to convert all services to another format in one go. Which helps in backward compatibility for older data communication format without affecting the application functionalities.\n\n## Load Testing using Locust Tool\n\nLocust tool is used to perform load testing on the application via both REST and gRPC communication.  \n**Based on the Locust performance reports, I found that performance of gRPC communication is much better than the performance of REST communication.**\n\n**Reports Path:** _rest_grpc_dual_mode/tests/load_tests/reports/_\n\n### Locust Commands\n\n- [OPTIONAL] python -m grpc_tools.protoc --proto_path=./protobufs ./protobufs/rest_grpc_dual_mode.proto --python_out=./rest_grpc_dual_mode/tests/load_tests/grpc/generated --grpc_python_out=./rest_grpc_dual_mode/tests/load_tests/grpc/generated\n- [For REST] locust -f rest_grpc_dual_mode/tests/load_tests/rest/rest_load_test.py --host \u003chttp://localhost:5000\u003e --users \u003cMAX_USERS\u003e --spawn-rate \u003cNO_OF_USERS_TO_ADD_PER_SEC\u003e\n- [For gRPC] locust -f rest_grpc_dual_mode/tests/load_tests/grpc/grpc_load_test.py --host \u003chttp://localhost:50051\u003e --users \u003cMAX_USERS\u003e --spawn-rate \u003cNO_OF_USERS_TO_ADD_PER_SEC\u003e\n\n## References\n\n- [Implementing gRPC In Python](https://www.velotio.com/engineering-blog/grpc-implementation-using-python)\n- [gRPC documentation](https://grpc.io/docs/what-is-grpc/)\n- [Python gRPC documentation](https://grpc.io/docs/languages/python/)\n- [Python gRPC API reference](https://grpc.github.io/grpc/python/)\n- [Protocol Buffers](https://developers.google.com/protocol-buffers)\n- [gRPC Motivation and Design Principles](https://www.grpc.io/blog/principles/)\n- [BloomRPC tool - GUI Client for GRPC Services](https://appimage.github.io/BloomRPC/)\n- [Werkzeug - Werkzeug is a comprehensive WSGI web application library](https://werkzeug.palletsprojects.com/en/2.0.x/)\n- [Locust Tool](https://locust.io/)\n- [Locust Documentation](http://docs.locust.io/en/stable/#)\n- [Locust - Testing non-HTTP systems (gRPC)](https://docs.locust.io/en/latest/testing-other-systems.html#)\n- [gRPC benchmarking and load testing tool](https://ghz.sh/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanuprshetty%2Fpy_grpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanuprshetty%2Fpy_grpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanuprshetty%2Fpy_grpc/lists"}