Python: proto3 + generated server file names

335 views
Skip to first unread message

Amit Saha

unread,
Aug 22, 2017, 9:06:11 AM8/22/17
to grpc.io
Hey all,

Consider the sample .proto file:


```
syntax = "proto3";

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply) {}
  // Sends another greeting
  rpc SayHelloAgain (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings
message HelloReply {
  string message = 1;
}
```

When I generate the client and server:

```
$ python -m grpc_tools.protoc -I../protos --python_out=. --grpc_python_out=. ../protos/service.proto
```

The filenames are service_pb2.py   and   service_pb2_grpc.py. Should I not be expecting `pb3` in the filenames consider I am declaring the syntax to be proto3?

Relevant packages + versions:

```
$ pip list
grpcio (1.4.0)
grpcio-tools (1.4.0)
protobuf (3.4.0)
setuptools (28.8.0)
```

Thank you in advance.

Best Wishes,
Amit.



Nathaniel Manista

unread,
Aug 22, 2017, 3:02:55 PM8/22/17
to Amit Saha, Protocol Buffers, grpc.io
This is a Protocol Buffers thing much more than it is a gRPC thing, and I could be wrong about the reason, but my impression is that the "2" in "_pb2.py" (and thus in "_pb2_grpc.py", because we on the gRPC side just wanted to match what was being done on the Protocol Buffers side) denotes the API version of the generated Python code, not the .proto syntax version and also not the Protocol Buffers implementation version.

There may not be much available documentation about API version 1 of the generated Python code (files ending in "_pb.py") because it was a long time ago. Also because it may only have ever been Google-internal. Generated-Python-code API Version 2 is definitely much better.

Protocol Buffers Team, please confirm/correct this account?
-Nathaniel (gRPC Python developer; not authoritatively knowledgable about Protocol Buffers Python)

Amit Saha

unread,
Aug 22, 2017, 8:06:07 PM8/22/17
to Nathaniel Manista, Protocol Buffers, grpc.io
Thanks Nataniel (and my apologies for posting it to the gRPC group). I took  your clue and ended up on: https://developers.google.com/protocol-buffers/docs/reference/python-generated where it's stated that:

The number 2 in the extension _pb2.py designates version 2 of Protocol Buffers. Version 1 was used primarily inside Google, though you might be able to find parts of it included in other Python code that was released before Protocol Buffers. Since version 2 of Python Protocol Buffers has a completely different interface, and since Python does not have compile-time type checking to catch mistakes, we chose to make the version number be a prominent part of generated Python file names. Currently both proto2 and proto3 use _pb2.py for their generated files.

That's my answer. 

Thank you.

Best Wishes,
Amit.
 



--
You received this message because you are subscribed to a topic in the Google Groups "grpc.io" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grpc-io/smY3vi8kY1I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/CAEOYnAS6j%3DzEYtzVSN5WnLix1H0gxbZbhpOLW2K3%3D25L2eM4Ow%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages