python 3类型暗示的protobuf绑定生成器

protobuf-gen的Python项目详细描述


https://img.shields.io/pypi/v/protobuf-gen.svghttps://img.shields.io/travis/andreycizov/python-protobuf-gen.svgDocumentation StatusUpdateshttps://codecov.io/gh/andreycizov/python-protobuf-gen/coverage.svg?branch=master

动机

这是一个库,用于生成类型提示的协议缓冲区绑定。这个工具解决了原始的两个主要问题 google cproto编译器python输出:

  • cproto不支持导出具有不同于所提供的包根的代码 由原始的.proto文件作者编写,因此期望协议用户通过代码sed(参见问题 8811491)。
  • 它在运行时构建接口,因此不允许使用静态类型检查程序并禁用 在你最喜欢的IDE中自动完成。

示例

此示例可用于在python中构建功能齐全的etcd3客户机。否则请参见tests

让我们从克隆包含要编译的必要.proto文件的存储库开始。ETCD3引用文件 来自几个protobuf库,所以我们需要所有这些。

mkdir pb-includes

# etcd references it's own .proto files against the root of their own repository, so the doubling here is intended
git clone https://github.com/coreos/etcd.git ./pb-includes/etcd/etcd

git clone https://github.com/grpc-ecosystem/grpc-gateway.git ./pb-includes/grpc-gateway
git clone https://github.com/gogo/protobuf.git ./pb-includes/protobuf

现在,让我们实际生成文件。

fromprotobuf_genimportremap,wrap# all of the _pb2 modules will now be importable through `etcd3py.pb_mods.*`# for example a module "google/api/http.proto" will be available as "etcd3py.pb_mods.google.api.http_pb2"remap(# the working directory is given as the parent directory of the package folder (etcd3py in this case).'.','etcd3py.pb_mods,# .proto include directories['./pb-includes/grpc-gateway/third_party/googleapis','./pb-includes/etcd','./pb-includes/protobuf',],# .proto files to be included in the distribution['etcd/etcdserver/etcdserverpb/rpc.proto','etcd/mvcc/mvccpb/kv.proto','etcd/auth/authpb/auth.proto','google/api/annotations.proto','gogoproto/gogo.proto','google/api/http.proto',])

作者

安德烈·西佐夫(acizov@gmail.com),2018年

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用Eclipse Helios for Web项目   java指定行。作为编译器设置的分隔符?   osm映射中带有osmdroid的java标记   java Android ClassNotFoundException在路径:DexPathList上未找到类   java从j2me调用GWT方法   更新到java 8后的aspectj问题   如何仅从根元素java,com提取文本内容。滴虫软件。是的。html   安卓公司。谷歌。火基。数据库DatabaseException:未能转换java类型的值。将字符串改为长字符串   从java中的方法返回arraylist变量   java如果将引用重新分配给同步块内的锁对象,会是什么?   java下载。使用spring mvc的资源文件中的xlsx文件   java Eclipse提供了什么工具来运行Eclipse中未包含的程序?   spring boot Java泛型如何读取传递给泛型方法的类型上的字段或调用方法   Javacard中的javaecdsa签名