Skip to content

Commit 102a93e

Browse files
authored
Python Streaming: Codelab in README.md (#33)
1 parent e1e54df commit 102a93e

File tree

12 files changed

+627
-105
lines changed

12 files changed

+627
-105
lines changed

codelabs/grpc-python-getting-started/README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,26 @@ cd grpc-codelabs/
3737
### Python3
3838

3939
For this codelab, we require python 3.9 or higher, but recommend python 3.11. System-specific
40-
instructions can be found in Python documentation: [Python Setup and Usage]
41-
(https://docs.python.org/3/using/index.html).
40+
instructions can be found in Python documentation: [Python Setup and Usage](https://docs.python.org/3/using/index.html).
4241

4342
### Pip3
4443

45-
We recommend using the latest pip, see [Installation - pip]
46-
(https://pip.pypa.io/en/stable/installation/). In some OS distributions, `ensurepip` is not
47-
available out-of-box. On Debian/Ubuntu, you may need to run.
44+
We recommend using the latest pip, see [Installation - pip](https://pip.pypa.io/en/stable/installation/).
45+
In some OS distributions, `ensurepip` is not available out-of-box. On Debian/Ubuntu, you may need
46+
to run.
4847

4948
```sh
5049
sudo apt-get install python3-pip
5150
```
5251

53-
If necessary, upgrade your version of pip:
52+
If necessary, upgrade your version of pip:
5453

5554
```sh
5655
python3 -m ensurepip --upgrade
5756
```
5857

5958
If your python installation is owned by the system, pip will be installed in the user directory. If
60-
you may see a warning like this, ensure the pip directory is in PATH:
59+
you may see a warning like this, ensure the pip directory is in `$PATH`:
6160

6261
```
6362
WARNING: The scripts pip3 and pip3.9 are installed in '/Users/sergiitk/Library/Python/3.9/bin' which is not on PATH.
@@ -109,7 +108,7 @@ Our first step is to define the gRPC *service* and the method *request* and *res
109108

110109
Let’s start by defining the messages and service in `route_guide.proto`.
111110

112-
### Define proto messages
111+
### Define Proto Messages
113112

114113
Our `.proto` file contains protocol buffer message type definitions for all the request and response
115114
types used in our service methods.
@@ -135,7 +134,7 @@ message Feature {
135134
}
136135
```
137136

138-
### Define RouteGuide service
137+
### Define RouteGuide Service
139138

140139
To define a service, you specify a named `service` in your `.proto` file:
141140

@@ -160,7 +159,7 @@ rpc GetFeature(Point) returns (Feature) {}
160159

161160
> [!TIP]
162161
> For the complete .proto file, see
163-
> [completed/protos/route_guide.proto](https://github.com/grpc-ecosystem/grpc-codelabs/blob/main/codelabs/grpc-python-getting-started/completed/protos/route_guide.proto)
162+
> [`completed/protos/route_guide.proto`](https://github.com/grpc-ecosystem/grpc-codelabs/blob/main/codelabs/grpc-python-getting-started/completed/protos/route_guide.proto)
164163
165164
## Generating client and server code
166165

@@ -172,8 +171,8 @@ First, install the grpcio-tools package:
172171
pip install --require-virtualenv grpcio-tools
173172
```
174173

175-
If you see `ERROR: Could not find an activated virtualenv (required)`, please follow the section
176-
[Activate virtual environment](#activate-virtual-environment), then cd into `start_here`.
174+
If you see `ERROR: Could not find an activated virtualenv (required)`, please
175+
[activate virtual environment](#activate-virtual-environment), then cd into `start_here`.
177176

178177
Use the following command to generate the Python code:
179178

@@ -253,7 +252,7 @@ so that clients can actually use your service:
253252
def serve():
254253
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
255254
route_guide_pb2_grpc.add_RouteGuideServicer_to_server(RouteGuideServicer(), server)
256-
listen_addr = "[::]:50051"
255+
listen_addr = "localhost:50051"
257256
server.add_insecure_port(listen_addr)
258257
print(f"Starting server on {listen_addr}")
259258
server.start()
@@ -330,7 +329,7 @@ Run the server:
330329
python route_guide_server.py
331330
```
332331

333-
From a different terminal, [Activate virtual environment](#activate-virtual-environment), then run
332+
From a different terminal, [activate virtual environment](#activate-virtual-environment), then run
334333
the client:
335334

336335
```sh

codelabs/grpc-python-getting-started/completed/route_guide_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def GetFeature(self, request, context):
4848
def serve():
4949
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
5050
route_guide_pb2_grpc.add_RouteGuideServicer_to_server(RouteGuideServicer(), server)
51-
listen_addr = "[::]:50051"
51+
listen_addr = "localhost:50051"
5252
server.add_insecure_port(listen_addr)
5353
print(f"Starting server on {listen_addr}")
5454
server.start()

0 commit comments

Comments
 (0)