17 _REQUIRED_SYMBOLS = (
"_protos",
"_services",
"_protos_and_services")
18 _MINIMUM_VERSION = (3, 5, 0)
20 _UNINSTALLED_TEMPLATE =
"Install the grpcio-tools package (1.32.0+) to use the {} function."
21 _VERSION_ERROR_TEMPLATE =
"The {} function is only on available on Python 3.X interpreters."
25 return all(hasattr(mod, sym)
for sym
in _REQUIRED_SYMBOLS)
32 except ImportError
as e:
35 if "grpc_tools" not in e.args[0]:
41 """Calls one of the three functions, lazily importing grpc_tools.
44 fn_name: The name of the function to import from grpc_tools.protoc.
45 protobuf_path: The path to import.
48 The appropriate module object.
50 if sys.version_info < _MINIMUM_VERSION:
51 raise NotImplementedError(_VERSION_ERROR_TEMPLATE.format(fn_name))
54 raise NotImplementedError(_UNINSTALLED_TEMPLATE.format(fn_name))
58 return fn(protobuf_path)
60 raise NotImplementedError(_UNINSTALLED_TEMPLATE.format(fn_name))
64 """Returns a module generated by the indicated .proto file.
66 THIS IS AN EXPERIMENTAL API.
68 Use this function to retrieve classes corresponding to message
69 definitions in the .proto file.
71 To inspect the contents of the returned module, use the dir function.
75 protos = grpc.protos("foo.proto")
79 The returned module object corresponds to the _pb2.py file generated
80 by protoc. The path is expected to be relative to an entry on sys.path
81 and all transitive dependencies of the file should also be resolveable
82 from an entry on sys.path.
84 To completely disable the machinery behind this function, set the
85 GRPC_PYTHON_DISABLE_DYNAMIC_STUBS environment variable to "true".
88 protobuf_path: The path to the .proto file on the filesystem. This path
89 must be resolveable from an entry on sys.path and so must all of its
90 transitive dependencies.
93 A module object corresponding to the message code for the indicated
94 .proto file. Equivalent to a generated _pb2.py file.
100 """Returns a module generated by the indicated .proto file.
102 THIS IS AN EXPERIMENTAL API.
104 Use this function to retrieve classes and functions corresponding to
105 service definitions in the .proto file, including both stub and servicer
108 To inspect the contents of the returned module, use the dir function.
112 services = grpc.services("foo.proto")
116 The returned module object corresponds to the _pb2_grpc.py file generated
117 by protoc. The path is expected to be relative to an entry on sys.path
118 and all transitive dependencies of the file should also be resolveable
119 from an entry on sys.path.
121 To completely disable the machinery behind this function, set the
122 GRPC_PYTHON_DISABLE_DYNAMIC_STUBS environment variable to "true".
125 protobuf_path: The path to the .proto file on the filesystem. This path
126 must be resolveable from an entry on sys.path and so must all of its
127 transitive dependencies.
130 A module object corresponding to the stub/service code for the indicated
131 .proto file. Equivalent to a generated _pb2_grpc.py file.
137 """Returns a 2-tuple of modules corresponding to protos and services.
139 THIS IS AN EXPERIMENTAL API.
141 The return value of this function is equivalent to a call to protos and a
144 To completely disable the machinery behind this function, set the
145 GRPC_PYTHON_DISABLE_DYNAMIC_STUBS environment variable to "true".
148 protobuf_path: The path to the .proto file on the filesystem. This path
149 must be resolveable from an entry on sys.path and so must all of its
150 transitive dependencies.
153 A 2-tuple of module objects corresponding to (protos(path), services(path)).