For revisit, go to check the Python Basic tutorial and Sample Code.
The gRPC is the open source version of Stubby from Google, it uses Protocol Buffer as both its Interface Definition Language (IDL) and as its underlying message interchange format.
gRPC clients and servers can run and talk to each other in a variety of environments and can be written in any of gRPC’s supported languages. So, for example, you can easily create a gRPC server in Java with clients in Go, Python, or Ruby.
Core Concepts for gRPC. There are regular and stream request/response types, they can be combined in any form, for example:
1 | service Greeter { |
The comments in proto service definition will be translated to docstring in generated code, for example:
1 | // import definition. |
As above shows, write message and service in .proto file.
Basic tutorial for Python, run within the python virtualenv, for example:
1 | virtualenv -p python3 grpc |
Required python modules for gRPC:
1 | # Install gRPC. |
After finished the proto file definition:
1 | # Command help |
When finishes the basic codelab, here are many different patterns and usages to create client-server applications.
TIPS: Using Python
typing
to indicate the parameters type in service method to make it clear.
NOTE: In basic tutorial for asynchronous pattern, it uses Python
asyncio
as implementation.
For gRPC authentication in Python, please see ALTS authentication.