{"action":"created","comment":{"url":"https://api.github.com/repos/grpc/grpc-common/pulls/comments/27348533","id":27348533,"diff_hunk":"@@ -0,0 +1,281 @@\n+#gRPC Basics: Python\n+\n+This tutorial provides a basic Python programmer's introduction to working with gRPC. By walking through this example you'll learn how to:\n+\n+- Define a service in a .proto file.\n+- Generate server and client code using the protocol buffer compiler.\n+- Use the Python gRPC API to write a simple client and server for your service.\n+\n+It assumes that you have read the [Getting started](https://github.com/grpc/grpc-common) guide and are familiar with [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview).\n+\n+## Why use gRPC?\n+\n+This example is a simple route mapping application that lets clients get information about features on their route, create a summary of their route, and exchange route information such as traffic updates with the server and other clients.\n+\n+With gRPC you can define your service once in a .proto file and implement clients and servers in any of gRPC's supported languages, which in turn can be run in environments ranging from servers inside Google to your own tablet, with all the complexity of communication between different languages and environments is handled for you by gRPC. You also get all the advantages of working with protocol buffers, including efficient serialization, a simple IDL, and easy interface updating.\n+\n+## Example code and setup\n+\n+The example code for this tutorial is in [grpc/grpc-common/python/route_guide](https://github.com/grpc/grpc-common/tree/master/python/route_guide). To download the example, clone the `grpc-common` repository by running the following command:\n+```shell\n+$ git clone https://github.com/google/grpc-common.git\n+```\n+\n+Then change your current directory to `grpc-common/python/route_guide`:\n+```shell\n+$ cd grpc-common/python/route_guide\n+```\n+\n+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](https://github.com/grpc/grpc-common/tree/master/python).\n+\n+## Defining the service\n+\n+Your first step (as you'll know from [Getting started](https://github.com/grpc/grpc-common)) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers](https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`grpc-common/protos/route_guide.proto`](https://github.com/grpc/grpc-common/blob/master/protos/route_guide.proto).\n+\n+To define a service, you specify a named `service` in your .proto file:\n+\n+```protobuf\n+service RouteGuide {\n+   // (Method definitions not shown)\n+}\n+```\n+\n+Then you define `rpc` methods inside your service definition, specifying their request and response types. gRPC lets you define four kinds of service method, all of which are used in the `RouteGuide` service:\n+\n+- A *bidirectionally-unary RPC* where the client sends a request to the server using the stub and waits for a response to come back, just like a normal function call.\n+```protobuf\n+   // Obtains the feature at a given position.\n+   rpc GetFeature(Point) returns (Feature) {}\n+```\n+\n+- A *response-streaming RPC* where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from the returned stream until there are no more messages. As you can see in the example, you specify a response-streaming method by placing the `stream` keyword before the *response* type.\n+```protobuf\n+  // Obtains the Features available within the given Rectangle.  Results are\n+  // streamed rather than returned at once (e.g. in a response message with a\n+  // repeated field), as the rectangle may cover a large area and contain a\n+  // huge number of features.\n+  rpc ListFeatures(Rectangle) returns (stream Feature) {}\n+```\n+\n+- A *request-streaming RPC* where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client has finished writing the messages, it waits for the server to read them all and return its response. You specify a request-streaming method by placing the `stream` keyword before the *request* type.\n+```protobuf\n+  // Accepts a stream of Points on a route being traversed, returning a\n+  // RouteSummary when traversal is completed.\n+  rpc RecordRoute(stream Point) returns (RouteSummary) {}\n+```\n+\n+- A *bidirectionally-streaming RPC* where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients and servers can read and write in whatever order they like: for example, the server could wait to receive all the client messages before writing its responses, or it could alternately read a message then write a message, or some other combination of reads and writes. The order of messages in each stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response.\n+```protobuf\n+  // Accepts a stream of RouteNotes sent while a route is being traversed,\n+  // while receiving other RouteNotes (e.g. from other users).\n+  rpc RouteChat(stream RouteNote) returns (stream RouteNote) {}\n+```\n+\n+Your .proto file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type:\n+```protobuf\n+// Points are represented as latitude-longitude pairs in the E7 representation\n+// (degrees multiplied by 10**7 and rounded to the nearest integer).\n+// Latitudes should be in the range +/- 90 degrees and longitude should be in\n+// the range +/- 180 degrees (inclusive).\n+message Point {\n+  int32 latitude = 1;\n+  int32 longitude = 2;\n+}\n+```\n+\n+## Generating client and server code\n+\n+Next you need to generate the gRPC client and server interfaces from your .proto service definition. You may do this using the protocol buffer compiler `protoc` with a special gRPC Python plugin. Make sure you've installed protoc and followed the gRPC Python plugin [installation instructions](https://github.com/grpc/grpc/blob/master/INSTALL) first):\n+\n+With `protoc` and the gRPC Python plugin installed use the following command to generate the Python code:\n+\n+```shell\n+$ protoc -I . --python_out=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_python_plugin` route_guide.proto\n+```\n+\n+Running this command regenerates the route_guide_pb2.py file containing:\n+- classes for the messages defined in route_guide.proto\n+- abstract classes for the service defined in route_guide.proto\n+   - `EarlyAdopterRouteGuideServicer` which defines the interface for implementations of the RouteGuide service\n+   - `EarlyAdopterRouteGuideServer` which may be started and stopped","path":"python/route_guide/README.md","position":100,"original_position":100,"commit_id":"342d8c748a7fe989d8299f191c13605d934741d9","original_commit_id":"342d8c748a7fe989d8299f191c13605d934741d9","user":{"login":"nathanielmanistaatgoogle","id":10131044,"avatar_url":"https://avatars.githubusercontent.com/u/10131044?v=3","gravatar_id":"","url":"https://api.github.com/users/nathanielmanistaatgoogle","html_url":"https://github.com/nathanielmanistaatgoogle","followers_url":"https://api.github.com/users/nathanielmanistaatgoogle/followers","following_url":"https://api.github.com/users/nathanielmanistaatgoogle/following{/other_user}","gists_url":"https://api.github.com/users/nathanielmanistaatgoogle/gists{/gist_id}","starred_url":"https://api.github.com/users/nathanielmanistaatgoogle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nathanielmanistaatgoogle/subscriptions","organizations_url":"https://api.github.com/users/nathanielmanistaatgoogle/orgs","repos_url":"https://api.github.com/users/nathanielmanistaatgoogle/repos","events_url":"https://api.github.com/users/nathanielmanistaatgoogle/events{/privacy}","received_events_url":"https://api.github.com/users/nathanielmanistaatgoogle/received_events","type":"User","site_admin":false},"body":"I think that's the wrong way to describe the EarlyAdopterRouteGuideServer. It is the server object that itself may be started and stopped. It doesn't provide methods for starting and stopping a different, not-yet-described, \"server\" object.","created_at":"2015-03-28T21:10:15Z","updated_at":"2015-03-28T21:10:15Z","html_url":"https://github.com/grpc/grpc-common/pull/126#discussion_r27348533","pull_request_url":"https://api.github.com/repos/grpc/grpc-common/pulls/126","_links":{"self":{"href":"https://api.github.com/repos/grpc/grpc-common/pulls/comments/27348533"},"html":{"href":"https://github.com/grpc/grpc-common/pull/126#discussion_r27348533"},"pull_request":{"href":"https://api.github.com/repos/grpc/grpc-common/pulls/126"}}},"pull_request":{"url":"https://api.github.com/repos/grpc/grpc-common/pulls/126","id":30129243,"html_url":"https://github.com/grpc/grpc-common/pull/126","diff_url":"https://github.com/grpc/grpc-common/pull/126.diff","patch_url":"https://github.com/grpc/grpc-common/pull/126.patch","issue_url":"https://api.github.com/repos/grpc/grpc-common/issues/126","number":126,"state":"open","locked":false,"title":"Python route guide README","user":{"login":"nathanielmanistaatgoogle","id":10131044,"avatar_url":"https://avatars.githubusercontent.com/u/10131044?v=3","gravatar_id":"","url":"https://api.github.com/users/nathanielmanistaatgoogle","html_url":"https://github.com/nathanielmanistaatgoogle","followers_url":"https://api.github.com/users/nathanielmanistaatgoogle/followers","following_url":"https://api.github.com/users/nathanielmanistaatgoogle/following{/other_user}","gists_url":"https://api.github.com/users/nathanielmanistaatgoogle/gists{/gist_id}","starred_url":"https://api.github.com/users/nathanielmanistaatgoogle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nathanielmanistaatgoogle/subscriptions","organizations_url":"https://api.github.com/users/nathanielmanistaatgoogle/orgs","repos_url":"https://api.github.com/users/nathanielmanistaatgoogle/repos","events_url":"https://api.github.com/users/nathanielmanistaatgoogle/events{/privacy}","received_events_url":"https://api.github.com/users/nathanielmanistaatgoogle/received_events","type":"User","site_admin":false},"body":"@murgatroid99, please review and merge.","created_at":"2015-02-26T23:49:30Z","updated_at":"2015-03-28T21:10:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"84832a2959aa6039da15dbe02b021de6256e6234","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/grpc/grpc-common/pulls/126/commits","review_comments_url":"https://api.github.com/repos/grpc/grpc-common/pulls/126/comments","review_comment_url":"https://api.github.com/repos/grpc/grpc-common/pulls/comments{/number}","comments_url":"https://api.github.com/repos/grpc/grpc-common/issues/126/comments","statuses_url":"https://api.github.com/repos/grpc/grpc-common/statuses/342d8c748a7fe989d8299f191c13605d934741d9","head":{"label":"nathanielmanistaatgoogle:route-guide-readme","ref":"route-guide-readme","sha":"342d8c748a7fe989d8299f191c13605d934741d9","user":{"login":"nathanielmanistaatgoogle","id":10131044,"avatar_url":"https://avatars.githubusercontent.com/u/10131044?v=3","gravatar_id":"","url":"https://api.github.com/users/nathanielmanistaatgoogle","html_url":"https://github.com/nathanielmanistaatgoogle","followers_url":"https://api.github.com/users/nathanielmanistaatgoogle/followers","following_url":"https://api.github.com/users/nathanielmanistaatgoogle/following{/other_user}","gists_url":"https://api.github.com/users/nathanielmanistaatgoogle/gists{/gist_id}","starred_url":"https://api.github.com/users/nathanielmanistaatgoogle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nathanielmanistaatgoogle/subscriptions","organizations_url":"https://api.github.com/users/nathanielmanistaatgoogle/orgs","repos_url":"https://api.github.com/users/nathanielmanistaatgoogle/repos","events_url":"https://api.github.com/users/nathanielmanistaatgoogle/events{/privacy}","received_events_url":"https://api.github.com/users/nathanielmanistaatgoogle/received_events","type":"User","site_admin":false},"repo":{"id":31385515,"name":"grpc-common","full_name":"nathanielmanistaatgoogle/grpc-common","owner":{"login":"nathanielmanistaatgoogle","id":10131044,"avatar_url":"https://avatars.githubusercontent.com/u/10131044?v=3","gravatar_id":"","url":"https://api.github.com/users/nathanielmanistaatgoogle","html_url":"https://github.com/nathanielmanistaatgoogle","followers_url":"https://api.github.com/users/nathanielmanistaatgoogle/followers","following_url":"https://api.github.com/users/nathanielmanistaatgoogle/following{/other_user}","gists_url":"https://api.github.com/users/nathanielmanistaatgoogle/gists{/gist_id}","starred_url":"https://api.github.com/users/nathanielmanistaatgoogle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nathanielmanistaatgoogle/subscriptions","organizations_url":"https://api.github.com/users/nathanielmanistaatgoogle/orgs","repos_url":"https://api.github.com/users/nathanielmanistaatgoogle/repos","events_url":"https://api.github.com/users/nathanielmanistaatgoogle/events{/privacy}","received_events_url":"https://api.github.com/users/nathanielmanistaatgoogle/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nathanielmanistaatgoogle/grpc-common","description":"Documents, resources, examples shared across other gRPC repos.","fork":true,"url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common","forks_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/forks","keys_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/teams","hooks_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/hooks","issue_events_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/issues/events{/number}","events_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/events","assignees_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/assignees{/user}","branches_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/branches{/branch}","tags_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/tags","blobs_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/git/refs{/sha}","trees_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/statuses/{sha}","languages_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/languages","stargazers_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/stargazers","contributors_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/contributors","subscribers_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/subscribers","subscription_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/subscription","commits_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/commits{/sha}","git_commits_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/git/commits{/sha}","comments_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/comments{/number}","issue_comment_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/issues/comments{/number}","contents_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/contents/{+path}","compare_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/merges","archive_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/downloads","issues_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/issues{/number}","pulls_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/pulls{/number}","milestones_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/milestones{/number}","notifications_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/labels{/name}","releases_url":"https://api.github.com/repos/nathanielmanistaatgoogle/grpc-common/releases{/id}","created_at":"2015-02-26T19:47:40Z","updated_at":"2015-02-26T19:47:52Z","pushed_at":"2015-03-28T20:56:35Z","git_url":"git://github.com/nathanielmanistaatgoogle/grpc-common.git","ssh_url":"git@github.com:nathanielmanistaatgoogle/grpc-common.git","clone_url":"https://github.com/nathanielmanistaatgoogle/grpc-common.git","svn_url":"https://github.com/nathanielmanistaatgoogle/grpc-common","homepage":"","size":429,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"grpc:master","ref":"master","sha":"fd16f0604775ff6e00a02800e09845f3fce96d09","user":{"login":"grpc","id":7802525,"avatar_url":"https://avatars.githubusercontent.com/u/7802525?v=3","gravatar_id":"","url":"https://api.github.com/users/grpc","html_url":"https://github.com/grpc","followers_url":"https://api.github.com/users/grpc/followers","following_url":"https://api.github.com/users/grpc/following{/other_user}","gists_url":"https://api.github.com/users/grpc/gists{/gist_id}","starred_url":"https://api.github.com/users/grpc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grpc/subscriptions","organizations_url":"https://api.github.com/users/grpc/orgs","repos_url":"https://api.github.com/users/grpc/repos","events_url":"https://api.github.com/users/grpc/events{/privacy}","received_events_url":"https://api.github.com/users/grpc/received_events","type":"Organization","site_admin":false},"repo":{"id":30084851,"name":"grpc-common","full_name":"grpc/grpc-common","owner":{"login":"grpc","id":7802525,"avatar_url":"https://avatars.githubusercontent.com/u/7802525?v=3","gravatar_id":"","url":"https://api.github.com/users/grpc","html_url":"https://github.com/grpc","followers_url":"https://api.github.com/users/grpc/followers","following_url":"https://api.github.com/users/grpc/following{/other_user}","gists_url":"https://api.github.com/users/grpc/gists{/gist_id}","starred_url":"https://api.github.com/users/grpc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grpc/subscriptions","organizations_url":"https://api.github.com/users/grpc/orgs","repos_url":"https://api.github.com/users/grpc/repos","events_url":"https://api.github.com/users/grpc/events{/privacy}","received_events_url":"https://api.github.com/users/grpc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/grpc/grpc-common","description":"Documents, resources, examples shared across other gRPC repos.","fork":false,"url":"https://api.github.com/repos/grpc/grpc-common","forks_url":"https://api.github.com/repos/grpc/grpc-common/forks","keys_url":"https://api.github.com/repos/grpc/grpc-common/keys{/key_id}","collaborators_url":"https://api.github.com/repos/grpc/grpc-common/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/grpc/grpc-common/teams","hooks_url":"https://api.github.com/repos/grpc/grpc-common/hooks","issue_events_url":"https://api.github.com/repos/grpc/grpc-common/issues/events{/number}","events_url":"https://api.github.com/repos/grpc/grpc-common/events","assignees_url":"https://api.github.com/repos/grpc/grpc-common/assignees{/user}","branches_url":"https://api.github.com/repos/grpc/grpc-common/branches{/branch}","tags_url":"https://api.github.com/repos/grpc/grpc-common/tags","blobs_url":"https://api.github.com/repos/grpc/grpc-common/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/grpc/grpc-common/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/grpc/grpc-common/git/refs{/sha}","trees_url":"https://api.github.com/repos/grpc/grpc-common/git/trees{/sha}","statuses_url":"https://api.github.com/repos/grpc/grpc-common/statuses/{sha}","languages_url":"https://api.github.com/repos/grpc/grpc-common/languages","stargazers_url":"https://api.github.com/repos/grpc/grpc-common/stargazers","contributors_url":"https://api.github.com/repos/grpc/grpc-common/contributors","subscribers_url":"https://api.github.com/repos/grpc/grpc-common/subscribers","subscription_url":"https://api.github.com/repos/grpc/grpc-common/subscription","commits_url":"https://api.github.com/repos/grpc/grpc-common/commits{/sha}","git_commits_url":"https://api.github.com/repos/grpc/grpc-common/git/commits{/sha}","comments_url":"https://api.github.com/repos/grpc/grpc-common/comments{/number}","issue_comment_url":"https://api.github.com/repos/grpc/grpc-common/issues/comments{/number}","contents_url":"https://api.github.com/repos/grpc/grpc-common/contents/{+path}","compare_url":"https://api.github.com/repos/grpc/grpc-common/compare/{base}...{head}","merges_url":"https://api.github.com/repos/grpc/grpc-common/merges","archive_url":"https://api.github.com/repos/grpc/grpc-common/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/grpc/grpc-common/downloads","issues_url":"https://api.github.com/repos/grpc/grpc-common/issues{/number}","pulls_url":"https://api.github.com/repos/grpc/grpc-common/pulls{/number}","milestones_url":"https://api.github.com/repos/grpc/grpc-common/milestones{/number}","notifications_url":"https://api.github.com/repos/grpc/grpc-common/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/grpc/grpc-common/labels{/name}","releases_url":"https://api.github.com/repos/grpc/grpc-common/releases{/id}","created_at":"2015-01-30T18:19:21Z","updated_at":"2015-03-28T17:56:38Z","pushed_at":"2015-03-28T20:58:24Z","git_url":"git://github.com/grpc/grpc-common.git","ssh_url":"git@github.com:grpc/grpc-common.git","clone_url":"https://github.com/grpc/grpc-common.git","svn_url":"https://github.com/grpc/grpc-common","homepage":"","size":2557,"stargazers_count":588,"watchers_count":588,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":89,"mirror_url":null,"open_issues_count":25,"forks":89,"open_issues":25,"watchers":588,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/grpc/grpc-common/pulls/126"},"html":{"href":"https://github.com/grpc/grpc-common/pull/126"},"issue":{"href":"https://api.github.com/repos/grpc/grpc-common/issues/126"},"comments":{"href":"https://api.github.com/repos/grpc/grpc-common/issues/126/comments"},"review_comments":{"href":"https://api.github.com/repos/grpc/grpc-common/pulls/126/comments"},"review_comment":{"href":"https://api.github.com/repos/grpc/grpc-common/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/grpc/grpc-common/pulls/126/commits"},"statuses":{"href":"https://api.github.com/repos/grpc/grpc-common/statuses/342d8c748a7fe989d8299f191c13605d934741d9"}}}}