grpcreflect-py 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ """An idiomatic Python implementation of gRPC Server Reflection."""
2
+
3
+ from grpcreflect.client import Client, ClientStream
4
+ from grpcreflect.reflector import ReflectionSchema, Reflector, ReflectorOptions
5
+ from grpcreflect.server import mount_reflection_handlers
6
+
7
+ __all__ = [
8
+ "Client",
9
+ "ClientStream",
10
+ "ReflectionSchema",
11
+ "Reflector",
12
+ "ReflectorOptions",
13
+ "mount_reflection_handlers",
14
+ ]
@@ -0,0 +1 @@
1
+ from __future__ import annotations
@@ -0,0 +1 @@
1
+ from __future__ import annotations
@@ -0,0 +1 @@
1
+ from __future__ import annotations
@@ -0,0 +1 @@
1
+ from __future__ import annotations
@@ -0,0 +1,174 @@
1
+ # Generated from grpc/reflection/v1/reflection.proto. DO NOT EDIT.
2
+ # Generated by protoc-gen-connectrpc-py v0.12.1 with parameter "".
3
+ # ruff: noqa: PGH004
4
+ # ruff: noqa
5
+ # fmt: off
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import Protocol, TYPE_CHECKING
10
+
11
+ from connectrpc.client import ConnectClient, ConnectClientSync
12
+ from connectrpc.code import Code
13
+ from connectrpc.errors import ConnectError
14
+ from connectrpc.method import IdempotencyLevel, MethodInfo
15
+ from connectrpc.server import ConnectASGIApplication, ConnectWSGIApplication, DEFAULT_READ_MAX_BYTES, Endpoint, EndpointSync
16
+ from protobuf import DescService
17
+
18
+ from . import reflection_pb
19
+ from .reflection_pb import ServerReflectionRequest, ServerReflectionResponse
20
+
21
+ if TYPE_CHECKING:
22
+ from collections.abc import AsyncGenerator, AsyncIterator, Iterable, Iterator, Mapping
23
+
24
+ from connectrpc.codec import Codec
25
+ from connectrpc.compression import Compression
26
+ from connectrpc.interceptor import Interceptor, InterceptorSync
27
+ from connectrpc.request import Headers, RequestContext
28
+
29
+
30
+ class ServerReflection(Protocol):
31
+ def server_reflection_info(self, request: AsyncIterator[ServerReflectionRequest], ctx: RequestContext[ServerReflectionRequest, ServerReflectionResponse], /) -> AsyncIterator[ServerReflectionResponse]:
32
+ """
33
+ The reflection service is structured as a bidirectional stream, ensuring
34
+ all related requests go to a single server.
35
+ """
36
+ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
37
+
38
+ @classmethod
39
+ def desc(cls) -> DescService:
40
+ """Returns the descriptor for this service."""
41
+ return next(s for s in reflection_pb.desc().services if s.type_name == 'grpc.reflection.v1.ServerReflection')
42
+
43
+ class ServerReflectionASGIApplication(ConnectASGIApplication[ServerReflection]):
44
+ def __init__(
45
+ self,
46
+ service: ServerReflection | AsyncGenerator[ServerReflection],
47
+ *,
48
+ interceptors: Iterable[Interceptor] = (),
49
+ read_max_bytes: int | None = DEFAULT_READ_MAX_BYTES,
50
+ compressions: Iterable[Compression] | None = None,
51
+ codecs: Iterable[Codec] | None = None,
52
+ ) -> None:
53
+ super().__init__(
54
+ service=service,
55
+ endpoints=lambda svc: {
56
+ "/grpc.reflection.v1.ServerReflection/ServerReflectionInfo": Endpoint.bidi_stream(
57
+ method=MethodInfo(
58
+ name="ServerReflectionInfo",
59
+ service_name="grpc.reflection.v1.ServerReflection",
60
+ input=ServerReflectionRequest,
61
+ output=ServerReflectionResponse,
62
+ idempotency_level=IdempotencyLevel.UNKNOWN,
63
+ ),
64
+ function=svc.server_reflection_info,
65
+ ),
66
+ },
67
+ interceptors=interceptors,
68
+ read_max_bytes=read_max_bytes,
69
+ compressions=compressions,
70
+ codecs=codecs,
71
+ )
72
+
73
+ @property
74
+ def path(self) -> str:
75
+ """Returns the URL path to mount the application to when serving multiple applications."""
76
+ return "/grpc.reflection.v1.ServerReflection"
77
+
78
+
79
+ class ServerReflectionClient(ConnectClient):
80
+ def server_reflection_info(
81
+ self,
82
+ request: AsyncIterator[ServerReflectionRequest],
83
+ *,
84
+ headers: Headers | Mapping[str, str] | None = None,
85
+ timeout_ms: int | None = None,
86
+ ) -> AsyncIterator[ServerReflectionResponse]:
87
+ """
88
+ The reflection service is structured as a bidirectional stream, ensuring
89
+ all related requests go to a single server.
90
+ """
91
+ return self.execute_bidi_stream(
92
+ request=request,
93
+ method=MethodInfo(
94
+ name="ServerReflectionInfo",
95
+ service_name="grpc.reflection.v1.ServerReflection",
96
+ input=ServerReflectionRequest,
97
+ output=ServerReflectionResponse,
98
+ idempotency_level=IdempotencyLevel.UNKNOWN,
99
+ ),
100
+ headers=headers,
101
+ timeout_ms=timeout_ms,
102
+ )
103
+
104
+ class ServerReflectionSync(Protocol):
105
+ def server_reflection_info(self, request: Iterator[ServerReflectionRequest], ctx: RequestContext[ServerReflectionRequest, ServerReflectionResponse], /) -> Iterator[ServerReflectionResponse]:
106
+ """
107
+ The reflection service is structured as a bidirectional stream, ensuring
108
+ all related requests go to a single server.
109
+ """
110
+ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
111
+
112
+ @classmethod
113
+ def desc(cls) -> DescService:
114
+ """Returns the descriptor for this service."""
115
+ return next(s for s in reflection_pb.desc().services if s.type_name == 'grpc.reflection.v1.ServerReflection')
116
+
117
+ class ServerReflectionWSGIApplication(ConnectWSGIApplication):
118
+ def __init__(
119
+ self,
120
+ service: ServerReflectionSync,
121
+ interceptors: Iterable[InterceptorSync] = (),
122
+ read_max_bytes: int | None = DEFAULT_READ_MAX_BYTES,
123
+ compressions: Iterable[Compression] | None = None,
124
+ codecs: Iterable[Codec] | None = None,
125
+ ) -> None:
126
+ super().__init__(
127
+ endpoints={
128
+ "/grpc.reflection.v1.ServerReflection/ServerReflectionInfo": EndpointSync.bidi_stream(
129
+ method=MethodInfo(
130
+ name="ServerReflectionInfo",
131
+ service_name="grpc.reflection.v1.ServerReflection",
132
+ input=ServerReflectionRequest,
133
+ output=ServerReflectionResponse,
134
+ idempotency_level=IdempotencyLevel.UNKNOWN,
135
+ ),
136
+ function=service.server_reflection_info,
137
+ ),
138
+ },
139
+ interceptors=interceptors,
140
+ read_max_bytes=read_max_bytes,
141
+ compressions=compressions,
142
+ codecs=codecs,
143
+ )
144
+
145
+ @property
146
+ def path(self) -> str:
147
+ """Returns the URL path to mount the application to when serving multiple applications."""
148
+ return "/grpc.reflection.v1.ServerReflection"
149
+
150
+
151
+ class ServerReflectionClientSync(ConnectClientSync):
152
+ def server_reflection_info(
153
+ self,
154
+ request: Iterator[ServerReflectionRequest],
155
+ *,
156
+ headers: Headers | Mapping[str, str] | None = None,
157
+ timeout_ms: int | None = None,
158
+ ) -> Iterator[ServerReflectionResponse]:
159
+ """
160
+ The reflection service is structured as a bidirectional stream, ensuring
161
+ all related requests go to a single server.
162
+ """
163
+ return self.execute_bidi_stream(
164
+ request=request,
165
+ method=MethodInfo(
166
+ name="ServerReflectionInfo",
167
+ service_name="grpc.reflection.v1.ServerReflection",
168
+ input=ServerReflectionRequest,
169
+ output=ServerReflectionResponse,
170
+ idempotency_level=IdempotencyLevel.UNKNOWN,
171
+ ),
172
+ headers=headers,
173
+ timeout_ms=timeout_ms,
174
+ )
@@ -0,0 +1,342 @@
1
+ # Generated from grpc/reflection/v1/reflection.proto. DO NOT EDIT.
2
+ # Generated by protoc-gen-py v0.5.0 with parameter "".
3
+ # ruff: noqa: PGH004
4
+ # ruff: noqa
5
+ # fmt: off
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import Literal, TYPE_CHECKING, TypeAlias
10
+
11
+ from protobuf import Message
12
+ from protobuf._codegen import file_desc
13
+
14
+ if TYPE_CHECKING:
15
+ from protobuf import DescFile, Oneof
16
+
17
+
18
+ _ServerReflectionRequestFields: TypeAlias = Literal["host", "file_by_filename", "file_containing_symbol", "file_containing_extension", "all_extension_numbers_of_type", "list_services"]
19
+
20
+ class ServerReflectionRequest(Message[_ServerReflectionRequestFields]):
21
+ """
22
+ The message sent by the client when calling ServerReflectionInfo method.
23
+
24
+ ```proto
25
+ message grpc.reflection.v1.ServerReflectionRequest
26
+ ```
27
+
28
+ Attributes:
29
+ host:
30
+ ```proto
31
+ string host = 1;
32
+ ```
33
+ message_request:
34
+ To use reflection service, the client should set one of the following
35
+ fields in message_request. The server distinguishes requests by their
36
+ defined field and then handles them using corresponding methods.
37
+
38
+ ```proto
39
+ oneof message_request
40
+ ```
41
+ """
42
+
43
+ __slots__ = ("host", "message_request")
44
+
45
+ if TYPE_CHECKING:
46
+
47
+ def __init__(
48
+ self,
49
+ *,
50
+ host: str = "",
51
+ message_request: Oneof[Literal["file_by_filename"], str] | Oneof[Literal["file_containing_symbol"], str] | Oneof[Literal["file_containing_extension"], ExtensionRequest] | Oneof[Literal["all_extension_numbers_of_type"], str] | Oneof[Literal["list_services"], str] | None = None,
52
+ ) -> None:
53
+ pass
54
+
55
+ host: str
56
+ message_request: Oneof[Literal["file_by_filename"], str] | Oneof[Literal["file_containing_symbol"], str] | Oneof[Literal["file_containing_extension"], ExtensionRequest] | Oneof[Literal["all_extension_numbers_of_type"], str] | Oneof[Literal["list_services"], str] | None
57
+
58
+ _ExtensionRequestFields: TypeAlias = Literal["containing_type", "extension_number"]
59
+
60
+ class ExtensionRequest(Message[_ExtensionRequestFields]):
61
+ """
62
+ The type name and extension number sent by the client when requesting
63
+ file_containing_extension.
64
+
65
+ ```proto
66
+ message grpc.reflection.v1.ExtensionRequest
67
+ ```
68
+
69
+ Attributes:
70
+ containing_type:
71
+ Fully-qualified type name. The format should be <package>.<type>
72
+
73
+ ```proto
74
+ string containing_type = 1;
75
+ ```
76
+ extension_number:
77
+ ```proto
78
+ int32 extension_number = 2;
79
+ ```
80
+ """
81
+
82
+ __slots__ = ("containing_type", "extension_number")
83
+
84
+ if TYPE_CHECKING:
85
+
86
+ def __init__(
87
+ self,
88
+ *,
89
+ containing_type: str = "",
90
+ extension_number: int = 0,
91
+ ) -> None:
92
+ pass
93
+
94
+ containing_type: str
95
+ extension_number: int
96
+
97
+ _ServerReflectionResponseFields: TypeAlias = Literal["valid_host", "original_request", "file_descriptor_response", "all_extension_numbers_response", "list_services_response", "error_response"]
98
+
99
+ class ServerReflectionResponse(Message[_ServerReflectionResponseFields]):
100
+ """
101
+ The message sent by the server to answer ServerReflectionInfo method.
102
+
103
+ ```proto
104
+ message grpc.reflection.v1.ServerReflectionResponse
105
+ ```
106
+
107
+ Attributes:
108
+ valid_host:
109
+ ```proto
110
+ string valid_host = 1;
111
+ ```
112
+ original_request:
113
+ ```proto
114
+ optional grpc.reflection.v1.ServerReflectionRequest original_request = 2;
115
+ ```
116
+ message_response:
117
+ The server sets one of the following fields according to the message_request
118
+ in the request.
119
+
120
+ ```proto
121
+ oneof message_response
122
+ ```
123
+ """
124
+
125
+ __slots__ = ("valid_host", "original_request", "message_response")
126
+
127
+ if TYPE_CHECKING:
128
+
129
+ def __init__(
130
+ self,
131
+ *,
132
+ valid_host: str = "",
133
+ original_request: ServerReflectionRequest | None = None,
134
+ message_response: Oneof[Literal["file_descriptor_response"], FileDescriptorResponse] | Oneof[Literal["all_extension_numbers_response"], ExtensionNumberResponse] | Oneof[Literal["list_services_response"], ListServiceResponse] | Oneof[Literal["error_response"], ErrorResponse] | None = None,
135
+ ) -> None:
136
+ pass
137
+
138
+ valid_host: str
139
+ original_request: ServerReflectionRequest | None
140
+ message_response: Oneof[Literal["file_descriptor_response"], FileDescriptorResponse] | Oneof[Literal["all_extension_numbers_response"], ExtensionNumberResponse] | Oneof[Literal["list_services_response"], ListServiceResponse] | Oneof[Literal["error_response"], ErrorResponse] | None
141
+
142
+ _FileDescriptorResponseFields: TypeAlias = Literal["file_descriptor_proto"]
143
+
144
+ class FileDescriptorResponse(Message[_FileDescriptorResponseFields]):
145
+ """
146
+ Serialized FileDescriptorProto messages sent by the server answering
147
+ a file_by_filename, file_containing_symbol, or file_containing_extension
148
+ request.
149
+
150
+ ```proto
151
+ message grpc.reflection.v1.FileDescriptorResponse
152
+ ```
153
+
154
+ Attributes:
155
+ file_descriptor_proto:
156
+ Serialized FileDescriptorProto messages. We avoid taking a dependency on
157
+ descriptor.proto, which uses proto2 only features, by making them opaque
158
+ bytes instead.
159
+
160
+ ```proto
161
+ repeated bytes file_descriptor_proto = 1;
162
+ ```
163
+ """
164
+
165
+ __slots__ = ("file_descriptor_proto",)
166
+
167
+ if TYPE_CHECKING:
168
+
169
+ def __init__(
170
+ self,
171
+ *,
172
+ file_descriptor_proto: list[bytes] | None = None,
173
+ ) -> None:
174
+ pass
175
+
176
+ file_descriptor_proto: list[bytes]
177
+
178
+ _ExtensionNumberResponseFields: TypeAlias = Literal["base_type_name", "extension_number"]
179
+
180
+ class ExtensionNumberResponse(Message[_ExtensionNumberResponseFields]):
181
+ """
182
+ A list of extension numbers sent by the server answering
183
+ all_extension_numbers_of_type request.
184
+
185
+ ```proto
186
+ message grpc.reflection.v1.ExtensionNumberResponse
187
+ ```
188
+
189
+ Attributes:
190
+ base_type_name:
191
+ Full name of the base type, including the package name. The format
192
+ is <package>.<type>
193
+
194
+ ```proto
195
+ string base_type_name = 1;
196
+ ```
197
+ extension_number:
198
+ ```proto
199
+ repeated int32 extension_number = 2 [packed = true];
200
+ ```
201
+ """
202
+
203
+ __slots__ = ("base_type_name", "extension_number")
204
+
205
+ if TYPE_CHECKING:
206
+
207
+ def __init__(
208
+ self,
209
+ *,
210
+ base_type_name: str = "",
211
+ extension_number: list[int] | None = None,
212
+ ) -> None:
213
+ pass
214
+
215
+ base_type_name: str
216
+ extension_number: list[int]
217
+
218
+ _ListServiceResponseFields: TypeAlias = Literal["service"]
219
+
220
+ class ListServiceResponse(Message[_ListServiceResponseFields]):
221
+ """
222
+ A list of ServiceResponse sent by the server answering list_services request.
223
+
224
+ ```proto
225
+ message grpc.reflection.v1.ListServiceResponse
226
+ ```
227
+
228
+ Attributes:
229
+ service:
230
+ The information of each service may be expanded in the future, so we use
231
+ ServiceResponse message to encapsulate it.
232
+
233
+ ```proto
234
+ repeated grpc.reflection.v1.ServiceResponse service = 1;
235
+ ```
236
+ """
237
+
238
+ __slots__ = ("service",)
239
+
240
+ if TYPE_CHECKING:
241
+
242
+ def __init__(
243
+ self,
244
+ *,
245
+ service: list[ServiceResponse] | None = None,
246
+ ) -> None:
247
+ pass
248
+
249
+ service: list[ServiceResponse]
250
+
251
+ _ServiceResponseFields: TypeAlias = Literal["name"]
252
+
253
+ class ServiceResponse(Message[_ServiceResponseFields]):
254
+ """
255
+ The information of a single service used by ListServiceResponse to answer
256
+ list_services request.
257
+
258
+ ```proto
259
+ message grpc.reflection.v1.ServiceResponse
260
+ ```
261
+
262
+ Attributes:
263
+ name:
264
+ Full name of a registered service, including its package name. The format
265
+ is <package>.<service>
266
+
267
+ ```proto
268
+ string name = 1;
269
+ ```
270
+ """
271
+
272
+ __slots__ = ("name",)
273
+
274
+ if TYPE_CHECKING:
275
+
276
+ def __init__(
277
+ self,
278
+ *,
279
+ name: str = "",
280
+ ) -> None:
281
+ pass
282
+
283
+ name: str
284
+
285
+ _ErrorResponseFields: TypeAlias = Literal["error_code", "error_message"]
286
+
287
+ class ErrorResponse(Message[_ErrorResponseFields]):
288
+ """
289
+ The error code and error message sent by the server when an error occurs.
290
+
291
+ ```proto
292
+ message grpc.reflection.v1.ErrorResponse
293
+ ```
294
+
295
+ Attributes:
296
+ error_code:
297
+ This field uses the error codes defined in grpc::StatusCode.
298
+
299
+ ```proto
300
+ int32 error_code = 1;
301
+ ```
302
+ error_message:
303
+ ```proto
304
+ string error_message = 2;
305
+ ```
306
+ """
307
+
308
+ __slots__ = ("error_code", "error_message")
309
+
310
+ if TYPE_CHECKING:
311
+
312
+ def __init__(
313
+ self,
314
+ *,
315
+ error_code: int = 0,
316
+ error_message: str = "",
317
+ ) -> None:
318
+ pass
319
+
320
+ error_code: int
321
+ error_message: str
322
+
323
+
324
+ _DESC = file_desc(
325
+ b'\n#grpc/reflection/v1/reflection.proto\x12\x12grpc.reflection.v1"\xf3\x02\n\x17ServerReflectionRequest\x12\x12\n\x04host\x18\x01 \x01(\tR\x04host\x12*\n\x10file_by_filename\x18\x03 \x01(\tH\x00R\x0efileByFilename\x126\n\x16file_containing_symbol\x18\x04 \x01(\tH\x00R\x14fileContainingSymbol\x12b\n\x19file_containing_extension\x18\x05 \x01(\x0b2$.grpc.reflection.v1.ExtensionRequestH\x00R\x17fileContainingExtension\x12B\n\x1dall_extension_numbers_of_type\x18\x06 \x01(\tH\x00R\x19allExtensionNumbersOfType\x12%\n\rlist_services\x18\x07 \x01(\tH\x00R\x0clistServicesB\x11\n\x0fmessage_request"f\n\x10ExtensionRequest\x12\'\n\x0fcontaining_type\x18\x01 \x01(\tR\x0econtainingType\x12)\n\x10extension_number\x18\x02 \x01(\x05R\x0fextensionNumber"\xae\x04\n\x18ServerReflectionResponse\x12\x1d\n\nvalid_host\x18\x01 \x01(\tR\tvalidHost\x12V\n\x10original_request\x18\x02 \x01(\x0b2+.grpc.reflection.v1.ServerReflectionRequestR\x0foriginalRequest\x12f\n\x18file_descriptor_response\x18\x04 \x01(\x0b2*.grpc.reflection.v1.FileDescriptorResponseH\x00R\x16fileDescriptorResponse\x12r\n\x1eall_extension_numbers_response\x18\x05 \x01(\x0b2+.grpc.reflection.v1.ExtensionNumberResponseH\x00R\x1ballExtensionNumbersResponse\x12_\n\x16list_services_response\x18\x06 \x01(\x0b2\'.grpc.reflection.v1.ListServiceResponseH\x00R\x14listServicesResponse\x12J\n\x0eerror_response\x18\x07 \x01(\x0b2!.grpc.reflection.v1.ErrorResponseH\x00R\rerrorResponseB\x12\n\x10message_response"L\n\x16FileDescriptorResponse\x122\n\x15file_descriptor_proto\x18\x01 \x03(\x0cR\x13fileDescriptorProto"j\n\x17ExtensionNumberResponse\x12$\n\x0ebase_type_name\x18\x01 \x01(\tR\x0cbaseTypeName\x12)\n\x10extension_number\x18\x02 \x03(\x05R\x0fextensionNumber"T\n\x13ListServiceResponse\x12=\n\x07service\x18\x01 \x03(\x0b2#.grpc.reflection.v1.ServiceResponseR\x07service"%\n\x0fServiceResponse\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name"S\n\rErrorResponse\x12\x1d\n\nerror_code\x18\x01 \x01(\x05R\terrorCode\x12#\n\rerror_message\x18\x02 \x01(\tR\x0cerrorMessage2\x89\x01\n\x10ServerReflection\x12u\n\x14ServerReflectionInfo\x12+.grpc.reflection.v1.ServerReflectionRequest\x1a,.grpc.reflection.v1.ServerReflectionResponse(\x010\x01B\xc9\x01\n\x16com.grpc.reflection.v1B\x0fReflectionProtoP\x01Z4google.golang.org/grpc/reflection/grpc_reflection_v1\xa2\x02\x03GRX\xaa\x02\x12Grpc.Reflection.V1\xca\x02\x12Grpc\\Reflection\\V1\xe2\x02\x1eGrpc\\Reflection\\V1\\GPBMetadata\xea\x02\x14Grpc::Reflection::V1b\x06proto3',
326
+ [],
327
+ {
328
+ "ServerReflectionRequest": ServerReflectionRequest,
329
+ "ExtensionRequest": ExtensionRequest,
330
+ "ServerReflectionResponse": ServerReflectionResponse,
331
+ "FileDescriptorResponse": FileDescriptorResponse,
332
+ "ExtensionNumberResponse": ExtensionNumberResponse,
333
+ "ListServiceResponse": ListServiceResponse,
334
+ "ServiceResponse": ServiceResponse,
335
+ "ErrorResponse": ErrorResponse,
336
+ },
337
+ )
338
+
339
+
340
+ def desc() -> DescFile:
341
+ """Returns the descriptor for the file `grpc/reflection/v1/reflection.proto`."""
342
+ return _DESC
@@ -0,0 +1 @@
1
+ from __future__ import annotations