aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/python/route_guide/README.md
diff options
context:
space:
mode:
authorGravatar Nathaniel Manista <nathaniel@google.com>2015-09-08 21:34:33 +0000
committerGravatar Nathaniel Manista <nathaniel@google.com>2015-09-10 16:09:17 +0000
commit061d288f559f786c1541f56192303314a61e5489 (patch)
tree3ddf30b2aef7cc3111176d4986c410ccad8c21e1 /examples/python/route_guide/README.md
parentf65d3c11023cd39b73c8832947889f656f2427a3 (diff)
Beta Python documentation correction and update
Diffstat (limited to 'examples/python/route_guide/README.md')
-rw-r--r--examples/python/route_guide/README.md36
1 files changed, 16 insertions, 20 deletions
diff --git a/examples/python/route_guide/README.md b/examples/python/route_guide/README.md
index 636e134964..cb1aa7d78a 100644
--- a/examples/python/route_guide/README.md
+++ b/examples/python/route_guide/README.md
@@ -29,7 +29,7 @@ Then change your current directory to `examples/python/route_guide`:
$ cd examples/python/route_guide
```
-You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Python quick start guide](../python).
+You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Python quick start guide](../helloworld).
## Defining the service
@@ -99,12 +99,11 @@ $ protoc -I ../../protos --python_out=. --grpc_out=. --plugin=protoc-gen-grpc=`w
Note that as we've already provided a version of the generated code in the example repository, running this command regenerates the appropriate file rather than creates a new one. The generated code file is called `route_guide_pb2.py` and contains:
- classes for the messages defined in route_guide.proto
- abstract classes for the service defined in route_guide.proto
- - `EarlyAdopterRouteGuideServicer`, which defines the interface for implementations of the RouteGuide service
- - `EarlyAdopterRouteGuideServer`, which may be started and stopped
- - `EarlyAdopterRouteGuideStub`, which can be used by clients to invoke RouteGuide RPCs
+ - `BetaRouteGuideServicer`, which defines the interface for implementations of the RouteGuide service
+ - `BetaRouteGuideStub`, which can be used by clients to invoke RouteGuide RPCs
- functions for application use
- - `early_adopter_create_RouteGuide_server`, which creates a gRPC server given an `EarlyAdopterRouteGuideServicer` object
- - `early_adopter_create_RouteGuide_stub`, which can be used by clients to create a stub object
+ - `beta_create_RouteGuide_server`, which creates a gRPC server given a `BetaRouteGuideServicer` object
+ - `beta_create_RouteGuide_stub`, which can be used by clients to create a stub object
<a name="server"></a>
## Creating the server
@@ -119,11 +118,11 @@ You can find the example `RouteGuide` server in [route_guide_server.py](route_gu
### Implementing RouteGuide
-`route_guide_server.py` has a `RouteGuideServicer` class that implements the generated interface `route_guide_pb2.EarlyAdopterRouteGuideServicer`:
+`route_guide_server.py` has a `RouteGuideServicer` class that implements the generated interface `route_guide_pb2.BetaRouteGuideServicer`:
```python
# RouteGuideServicer provides an implementation of the methods of the RouteGuide service.
-class RouteGuideServicer(route_guide_pb2.EarlyAdopterRouteGuideServicer):
+class RouteGuideServicer(route_guide_pb2.BetaRouteGuideServicer):
```
`RouteGuideServicer` implements all the `RouteGuide` service methods.
@@ -141,7 +140,7 @@ Let's look at the simplest type first, `GetFeature`, which just gets a `Point` f
return feature
```
-The method is passed a `route_guide_pb2.Point` request for the RPC, and an `RpcContext` object that provides RPC-specific information such as timeout limits. It returns a `route_guide_pb2.Feature` response.
+The method is passed a `route_guide_pb2.Point` request for the RPC, and a `ServicerContext` object that provides RPC-specific information such as timeout limits. It returns a `route_guide_pb2.Feature` response.
#### Response-streaming RPC
@@ -212,8 +211,8 @@ Once you have implemented all the `RouteGuide` methods, the next step is to star
```python
def serve():
- server = route_guide_pb2.early_adopter_create_RouteGuide_server(
- RouteGuideServicer(), 50051, None, None)
+ server = route_guide_pb2.beta_create_RouteGuide_server(RouteGuideServicer())
+ server.add_insecure_port('[::]:50051')
server.start()
```
@@ -228,17 +227,14 @@ You can see the complete example client code in [route_guide_client.py](route_gu
To call service methods, we first need to create a *stub*.
-We use the `early_adopter_create_RouteGuide_stub` function of the `route_guide_pb2` module, generated from our .proto.
+We use the `beta_create_RouteGuide_stub` function of the `route_guide_pb2` module, generated from our .proto.
```python
-stub = RouteGuide::Stub.new('localhost', 50051)
+channel = implementations.insecure_channel('localhost', 50051)
+stub = beta_create_RouteGuide_stub(channel)
```
-The returned object implements all the methods defined by the `EarlyAdopterRouteGuideStub` interface, and is also a [context manager](https://docs.python.org/2/library/stdtypes.html#typecontextmanager). All RPCs invoked on the stub must be invoked within the stub's context, so it is common for stubs to be created and used with a [with statement](https://docs.python.org/2/reference/compound_stmts.html#the-with-statement):
-
-```python
-with route_guide_pb2.early_adopter_create_RouteGuide_stub('localhost', 50051) as stub:
-```
+The returned object implements all the methods defined by the `BetaRouteGuideStub` interface.
### Calling service methods
@@ -255,7 +251,7 @@ feature = stub.GetFeature(point, timeout_in_seconds)
An asynchronous call to `GetFeature` is similar, but like calling a local method asynchronously in a thread pool:
```python
-feature_future = stub.GetFeature.async(point, timeout_in_seconds)
+feature_future = stub.GetFeature.future(point, timeout_in_seconds)
feature = feature_future.result()
```
@@ -276,7 +272,7 @@ route_summary = stub.RecordRoute(point_sequence, timeout_in_seconds)
```
```python
-route_summary_future = stub.RecordRoute.async(point_sequence, timeout_in_seconds)
+route_summary_future = stub.RecordRoute.future(point_sequence, timeout_in_seconds)
route_summary = route_summary_future.result()
```