grpc-server-kit 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.
Files changed (57) hide show
  1. grpc_server_kit/__init__.py +34 -0
  2. grpc_server_kit/__version__.py +1 -0
  3. grpc_server_kit/aio/__init__.py +44 -0
  4. grpc_server_kit/aio/app.py +368 -0
  5. grpc_server_kit/aio/builder.py +63 -0
  6. grpc_server_kit/aio/dishka/__init__.py +28 -0
  7. grpc_server_kit/aio/dishka/bundle.py +70 -0
  8. grpc_server_kit/aio/dishka/interceptors.py +116 -0
  9. grpc_server_kit/aio/dishka/metrics.py +50 -0
  10. grpc_server_kit/aio/dishka/observability.py +86 -0
  11. grpc_server_kit/aio/dishka/server.py +51 -0
  12. grpc_server_kit/aio/health/__init__.py +36 -0
  13. grpc_server_kit/aio/health/cache.py +89 -0
  14. grpc_server_kit/aio/health/checkers/__init__.py +16 -0
  15. grpc_server_kit/aio/health/checkers/postgres.py +115 -0
  16. grpc_server_kit/aio/health/checkers/redis.py +88 -0
  17. grpc_server_kit/aio/health/checkers/utils.py +97 -0
  18. grpc_server_kit/aio/health/orchestrator.py +122 -0
  19. grpc_server_kit/aio/health/protocols.py +43 -0
  20. grpc_server_kit/aio/health/servicer.py +229 -0
  21. grpc_server_kit/aio/interceptors/__init__.py +62 -0
  22. grpc_server_kit/aio/interceptors/base.py +235 -0
  23. grpc_server_kit/aio/interceptors/context.py +179 -0
  24. grpc_server_kit/aio/interceptors/exception_handler.py +167 -0
  25. grpc_server_kit/aio/interceptors/metadata.py +57 -0
  26. grpc_server_kit/aio/interceptors/metrics.py +104 -0
  27. grpc_server_kit/aio/interceptors/protocols.py +54 -0
  28. grpc_server_kit/aio/interceptors/request_logger.py +103 -0
  29. grpc_server_kit/aio/interceptors/sentry.py +102 -0
  30. grpc_server_kit/aio/interceptors/tracing.py +130 -0
  31. grpc_server_kit/aio/observability/__init__.py +5 -0
  32. grpc_server_kit/aio/observability/tracing.py +48 -0
  33. grpc_server_kit/aio/runtime.py +206 -0
  34. grpc_server_kit/aio/server.py +191 -0
  35. grpc_server_kit/config.py +100 -0
  36. grpc_server_kit/constants.py +34 -0
  37. grpc_server_kit/credentials.py +112 -0
  38. grpc_server_kit/dishka/__init__.py +38 -0
  39. grpc_server_kit/dishka/settings.py +41 -0
  40. grpc_server_kit/interceptors/__init__.py +15 -0
  41. grpc_server_kit/interceptors/constants.py +44 -0
  42. grpc_server_kit/interceptors/utils.py +74 -0
  43. grpc_server_kit/observability/__init__.py +12 -0
  44. grpc_server_kit/observability/metrics.py +116 -0
  45. grpc_server_kit/observability/naming.py +26 -0
  46. grpc_server_kit/observability/protocols.py +86 -0
  47. grpc_server_kit/observability/sentry.py +63 -0
  48. grpc_server_kit/options.py +136 -0
  49. grpc_server_kit/protocols.py +114 -0
  50. grpc_server_kit/py.typed +0 -0
  51. grpc_server_kit/server.py +59 -0
  52. grpc_server_kit/settings.py +151 -0
  53. grpc_server_kit/signals.py +228 -0
  54. grpc_server_kit-0.1.0.dist-info/METADATA +484 -0
  55. grpc_server_kit-0.1.0.dist-info/RECORD +57 -0
  56. grpc_server_kit-0.1.0.dist-info/WHEEL +4 -0
  57. grpc_server_kit-0.1.0.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,484 @@
1
+ Metadata-Version: 2.5
2
+ Name: grpc-server-kit
3
+ Version: 0.1.0
4
+ Summary: Batteries-optional async gRPC server toolkit (app facade, builder, TLS, lifecycle, health, streaming-aware interceptors, observability)
5
+ Project-URL: Repository, https://github.com/bedrock-python/grpc-server-kit
6
+ Project-URL: Documentation, https://bedrock-python.github.io/grpc-server-kit/
7
+ Project-URL: Changelog, https://github.com/bedrock-python/grpc-server-kit/blob/master/CHANGELOG.md
8
+ Project-URL: Bug Tracker, https://github.com/bedrock-python/grpc-server-kit/issues
9
+ Author-email: Alex Shalaev <shalaevad.alexey@gmail.com>
10
+ License: Apache License
11
+ Version 2.0, January 2004
12
+ http://www.apache.org/licenses/
13
+
14
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
15
+
16
+ 1. Definitions.
17
+
18
+ "License" shall mean the terms and conditions for use, reproduction,
19
+ and distribution as defined by Sections 1 through 9 of this document.
20
+
21
+ "Licensor" shall mean the copyright owner or entity authorized by
22
+ the copyright owner that is granting the License.
23
+
24
+ "Legal Entity" shall mean the union of the acting entity and all
25
+ other entities that control, are controlled by, or are under common
26
+ control with that entity. For the purposes of this definition,
27
+ "control" means (i) the power, direct or indirect, to cause the
28
+ direction or management of such entity, whether by contract or
29
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
30
+ outstanding shares, or (iii) beneficial ownership of such entity.
31
+
32
+ "You" (or "Your") shall mean an individual or Legal Entity
33
+ exercising permissions granted by this License.
34
+
35
+ "Source" form shall mean the preferred form for making modifications,
36
+ including but not limited to software source code, documentation
37
+ source, and configuration files.
38
+
39
+ "Object" form shall mean any form resulting from mechanical
40
+ transformation or translation of a Source form, including but
41
+ not limited to compiled object code, generated documentation,
42
+ and conversions to other media types.
43
+
44
+ "Work" shall mean the work of authorship, whether in Source or
45
+ Object form, made available under the License, as indicated by a
46
+ copyright notice that is included in or attached to the work
47
+ (an example is provided in the Appendix below).
48
+
49
+ "Derivative Works" shall mean any work, whether in Source or Object
50
+ form, that is based on (or derived from) the Work and for which the
51
+ editorial revisions, annotations, elaborations, or other modifications
52
+ represent, as a whole, an original work of authorship. For the purposes
53
+ of this License, Derivative Works shall not include works that remain
54
+ separable from, or merely link (or bind by name) to the interfaces of,
55
+ the Work and Derivative Works thereof.
56
+
57
+ "Contribution" shall mean any work of authorship, including
58
+ the original version of the Work and any modifications or additions
59
+ to that Work or Derivative Works thereof, that is intentionally
60
+ submitted to Licensor for inclusion in the Work by the copyright owner
61
+ or by an individual or Legal Entity authorized to submit on behalf of
62
+ the copyright owner. For the purposes of this definition, "submitted"
63
+ means any form of electronic, verbal, or written communication sent
64
+ to the Licensor or its representatives, including but not limited to
65
+ communication on electronic mailing lists, source code control systems,
66
+ and issue tracking systems that are managed by, or on behalf of, the
67
+ Licensor for the purpose of discussing and improving the Work, but
68
+ excluding communication that is conspicuously marked or otherwise
69
+ designated in writing by the copyright owner as "Not a Contribution."
70
+
71
+ "Contributor" shall mean Licensor and any individual or Legal Entity
72
+ on behalf of whom a Contribution has been received by Licensor and
73
+ subsequently incorporated within the Work.
74
+
75
+ 2. Grant of Copyright License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ copyright license to reproduce, prepare Derivative Works of,
79
+ publicly display, publicly perform, sublicense, and distribute the
80
+ Work and such Derivative Works in Source or Object form.
81
+
82
+ 3. Grant of Patent License. Subject to the terms and conditions of
83
+ this License, each Contributor hereby grants to You a perpetual,
84
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
85
+ (except as stated in this section) patent license to make, have made,
86
+ use, offer to sell, sell, import, and otherwise transfer the Work,
87
+ where such license applies only to those patent claims licensable
88
+ by such Contributor that are necessarily infringed by their
89
+ Contribution(s) alone or by combination of their Contribution(s)
90
+ with the Work to which such Contribution(s) was submitted. If You
91
+ institute patent litigation against any entity (including a
92
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
93
+ or a Contribution incorporated within the Work constitutes direct
94
+ or contributory patent infringement, then any patent licenses
95
+ granted to You under this License for that Work shall terminate
96
+ as of the date such litigation is filed.
97
+
98
+ 4. Redistribution. You may reproduce and distribute copies of the
99
+ Work or Derivative Works thereof in any medium, with or without
100
+ modifications, and in Source or Object form, provided that You
101
+ meet the following conditions:
102
+
103
+ (a) You must give any other recipients of the Work or
104
+ Derivative Works a copy of this License; and
105
+
106
+ (b) You must cause any modified files to carry prominent notices
107
+ stating that You changed the files; and
108
+
109
+ (c) You must retain, in the Source form of any Derivative Works
110
+ that You distribute, all copyright, patent, trademark, and
111
+ attribution notices from the Source form of the Work,
112
+ excluding those notices that do not pertain to any part of
113
+ the Derivative Works; and
114
+
115
+ (d) If the Work includes a "NOTICE" text file as part of its
116
+ distribution, then any Derivative Works that You distribute must
117
+ include a readable copy of the attribution notices contained
118
+ within such NOTICE file, excluding those notices that do not
119
+ pertain to any part of the Derivative Works, in at least one
120
+ of the following places: within a NOTICE text file distributed
121
+ as part of the Derivative Works; within the Source form or
122
+ documentation, if provided along with the Derivative Works; or,
123
+ within a display generated by the Derivative Works, if and
124
+ wherever such third-party notices normally appear. The contents
125
+ of the NOTICE file are for informational purposes only and
126
+ do not modify the License. You may add Your own attribution
127
+ notices within Derivative Works that You distribute, alongside
128
+ or as an addendum to the NOTICE text from the Work, provided
129
+ that such additional attribution notices cannot be construed
130
+ as modifying the License.
131
+
132
+ You may add Your own copyright statement to Your modifications and
133
+ may provide additional or different license terms and conditions
134
+ for use, reproduction, or distribution of Your modifications, or
135
+ for any such Derivative Works as a whole, provided Your use,
136
+ reproduction, and distribution of the Work otherwise complies with
137
+ the conditions stated in this License.
138
+
139
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
140
+ any Contribution intentionally submitted for inclusion in the Work
141
+ by You to the Licensor shall be under the terms and conditions of
142
+ this License, without any additional terms or conditions.
143
+ Notwithstanding the above, nothing herein shall supersede or modify
144
+ the terms of any separate license agreement you may have executed
145
+ with Licensor regarding such Contributions.
146
+
147
+ 6. Trademarks. This License does not grant permission to use the trade
148
+ names, trademarks, service marks, or product names of the Licensor,
149
+ except as required for reasonable and customary use in describing the
150
+ origin of the Work and reproducing the content of the NOTICE file.
151
+
152
+ 7. Disclaimer of Warranty. Unless required by applicable law or
153
+ agreed to in writing, Licensor provides the Work (and each
154
+ Contributor provides its Contributions) on an "AS IS" BASIS,
155
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
156
+ implied, including, without limitation, any warranties or conditions
157
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
158
+ PARTICULAR PURPOSE. You are solely responsible for determining the
159
+ appropriateness of using or redistributing the Work and assume any
160
+ risks associated with Your exercise of permissions under this License.
161
+
162
+ 8. Limitation of Liability. In no event and under no legal theory,
163
+ whether in tort (including negligence), contract, or otherwise,
164
+ unless required by applicable law (such as deliberate and grossly
165
+ negligent acts) or agreed to in writing, shall any Contributor be
166
+ liable to You for damages, including any direct, indirect, special,
167
+ incidental, or consequential damages of any character arising as a
168
+ result of this License or out of the use or inability to use the
169
+ Work (including but not limited to damages for loss of goodwill,
170
+ work stoppage, computer failure or malfunction, or any and all
171
+ other commercial damages or losses), even if such Contributor
172
+ has been advised of the possibility of such damages.
173
+
174
+ 9. Accepting Warranty or Additional Liability. While redistributing
175
+ the Work or Derivative Works thereof, You may choose to offer,
176
+ and charge a fee for, acceptance of support, warranty, indemnity,
177
+ or other liability obligations and/or rights consistent with this
178
+ License. However, in accepting such obligations, You may act only
179
+ on Your own behalf and on Your sole responsibility, not on behalf
180
+ of any other Contributor, and only if You agree to indemnify,
181
+ defend, and hold each Contributor harmless for any liability
182
+ incurred by, or claims asserted against, such Contributor by reason
183
+ of your accepting any such warranty or additional liability.
184
+
185
+ END OF TERMS AND CONDITIONS
186
+
187
+ APPENDIX: How to apply the Apache License to your work.
188
+
189
+ To apply the Apache License to your work, attach the following
190
+ boilerplate notice, with the fields enclosed by brackets "[]"
191
+ replaced with your own identifying information. (Don't include
192
+ the brackets!) The text should be enclosed in the appropriate
193
+ comment syntax for the file format. We also recommend that a
194
+ file or class name and description of purpose be included on the
195
+ same "printed page" as the copyright notice for easier
196
+ identification within third-party archives.
197
+
198
+ Copyright 2026 Alex Shalaev
199
+
200
+ Licensed under the Apache License, Version 2.0 (the "License");
201
+ you may not use this file except in compliance with the License.
202
+ You may obtain a copy of the License at
203
+
204
+ http://www.apache.org/licenses/LICENSE-2.0
205
+
206
+ Unless required by applicable law or agreed to in writing, software
207
+ distributed under the License is distributed on an "AS IS" BASIS,
208
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
209
+ See the License for the specific language governing permissions and
210
+ limitations under the License.
211
+ License-File: LICENSE
212
+ Keywords: async,asyncio,grpc,grpcio,microservices,observability,server
213
+ Classifier: Development Status :: 4 - Beta
214
+ Classifier: Framework :: AsyncIO
215
+ Classifier: Intended Audience :: Developers
216
+ Classifier: License :: OSI Approved :: Apache Software License
217
+ Classifier: Programming Language :: Python :: 3
218
+ Classifier: Programming Language :: Python :: 3.12
219
+ Classifier: Programming Language :: Python :: 3.13
220
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
221
+ Classifier: Typing :: Typed
222
+ Requires-Python: >=3.12
223
+ Requires-Dist: grpcio<2.0.0,>=1.78.0
224
+ Provides-Extra: all
225
+ Requires-Dist: dishka>=1.4.0; extra == 'all'
226
+ Requires-Dist: grpcio-channelz<2.0.0,>=1.78.0; extra == 'all'
227
+ Requires-Dist: grpcio-health-checking<2.0.0,>=1.78.0; extra == 'all'
228
+ Requires-Dist: grpcio-reflection<2.0.0,>=1.78.0; extra == 'all'
229
+ Requires-Dist: opentelemetry-instrumentation-grpc>=0.40b0; extra == 'all'
230
+ Requires-Dist: prometheus-client>=0.15.0; extra == 'all'
231
+ Requires-Dist: protobuf>=4.21; extra == 'all'
232
+ Requires-Dist: pydantic<3.0,>=2.0.0; extra == 'all'
233
+ Requires-Dist: redis>=5.0.0; extra == 'all'
234
+ Requires-Dist: sentry-sdk>=2.0.0; extra == 'all'
235
+ Requires-Dist: sqlalchemy[asyncio]<3.0.0,>=2.0.0; extra == 'all'
236
+ Provides-Extra: channelz
237
+ Requires-Dist: grpcio-channelz<2.0.0,>=1.78.0; extra == 'channelz'
238
+ Provides-Extra: dishka
239
+ Requires-Dist: dishka>=1.4.0; extra == 'dishka'
240
+ Requires-Dist: protobuf>=4.21; extra == 'dishka'
241
+ Provides-Extra: health
242
+ Requires-Dist: grpcio-health-checking<2.0.0,>=1.78.0; extra == 'health'
243
+ Provides-Extra: metrics
244
+ Requires-Dist: prometheus-client>=0.15.0; extra == 'metrics'
245
+ Provides-Extra: postgres
246
+ Requires-Dist: sqlalchemy[asyncio]<3.0.0,>=2.0.0; extra == 'postgres'
247
+ Provides-Extra: redis
248
+ Requires-Dist: redis>=5.0.0; extra == 'redis'
249
+ Provides-Extra: reflection
250
+ Requires-Dist: grpcio-reflection<2.0.0,>=1.78.0; extra == 'reflection'
251
+ Provides-Extra: sentry
252
+ Requires-Dist: sentry-sdk>=2.0.0; extra == 'sentry'
253
+ Provides-Extra: settings
254
+ Requires-Dist: pydantic<3.0,>=2.0.0; extra == 'settings'
255
+ Provides-Extra: tracing
256
+ Requires-Dist: opentelemetry-instrumentation-grpc>=0.40b0; extra == 'tracing'
257
+ Description-Content-Type: text/markdown
258
+
259
+ # grpc-server-kit
260
+
261
+ Batteries-optional async gRPC server toolkit (app facade, builder, TLS, lifecycle, health, interceptors, observability)
262
+
263
+ [![PyPI](https://img.shields.io/pypi/v/grpc-server-kit?color=blue)](https://pypi.org/project/grpc-server-kit/)
264
+ [![Python](https://img.shields.io/pypi/pyversions/grpc-server-kit)](https://pypi.org/project/grpc-server-kit/)
265
+ [![License](https://img.shields.io/github/license/bedrock-python/grpc-server-kit)](LICENSE)
266
+ [![CI](https://github.com/bedrock-python/grpc-server-kit/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/bedrock-python/grpc-server-kit/actions/workflows/ci.yml)
267
+ [![codecov](https://codecov.io/gh/bedrock-python/grpc-server-kit/graph/badge.svg)](https://codecov.io/gh/bedrock-python/grpc-server-kit)
268
+ [![Docs](https://img.shields.io/badge/docs-online-blue)](https://bedrock-python.github.io/grpc-server-kit/)
269
+
270
+ `grpc-server-kit` gives you a clean, production-grade foundation for building
271
+ `grpc.aio` servers: a one-object `GrpcApp` facade, validated channel options,
272
+ TLS/mTLS credential loading, graceful signal-driven shutdown, streaming-aware
273
+ interceptors, and gRPC health checking — with **optional** extras for
274
+ reflection, channelz, Prometheus metrics, OpenTelemetry tracing, Sentry,
275
+ Dishka DI, and typed pydantic settings.
276
+
277
+ The core depends only on `grpcio`. Every integration is an opt-in extra, so you
278
+ install exactly what you use.
279
+
280
+ ## Installation
281
+
282
+ ```bash
283
+ pip install grpc-server-kit # core (grpcio only)
284
+ pip install "grpc-server-kit[settings]" # + pydantic settings models
285
+ pip install "grpc-server-kit[health]" # + gRPC health checking
286
+ pip install "grpc-server-kit[metrics,tracing]" # + Prometheus + OpenTelemetry
287
+ pip install "grpc-server-kit[all]" # everything
288
+ ```
289
+
290
+ **Requirements:** Python 3.12+
291
+
292
+ ## Quick start
293
+
294
+ ```python
295
+ import asyncio
296
+
297
+ from grpc_server_kit import GrpcApp
298
+
299
+ app = GrpcApp(port=50051)
300
+ app.add_servicer(MyServicer(), add_MyServiceServicer_to_server)
301
+
302
+ asyncio.run(app.run()) # build + bind + SIGINT/SIGTERM + graceful shutdown
303
+ ```
304
+
305
+ That's the whole server. `GrpcApp` builds the `grpc.aio` server, binds the port
306
+ (TLS-aware), installs signal handlers, and serves until termination. More knobs
307
+ when you need them:
308
+
309
+ ```python
310
+ from grpc_server_kit import GrpcApp, GrpcServerConfig
311
+ from grpc_server_kit.aio.interceptors import (
312
+ AsyncContextInterceptor, AsyncExceptionHandlerInterceptor,
313
+ AsyncMetricsInterceptor, AsyncRequestLoggerInterceptor, HeaderConfig,
314
+ )
315
+ from grpc_server_kit.observability.metrics import get_grpc_server_metrics
316
+
317
+ config = GrpcServerConfig(host="[::]", port=50051, grace_period=10.0) # stdlib dataclass
318
+ app = GrpcApp(config, interceptors=[
319
+ AsyncMetricsInterceptor(metrics=get_grpc_server_metrics(), service_name="my.pkg.MyService"),
320
+ AsyncContextInterceptor([HeaderConfig("x-request-id", "request_id")]),
321
+ AsyncRequestLoggerInterceptor(),
322
+ AsyncExceptionHandlerInterceptor(MY_ERROR_STATUS_MAP), # domain error → gRPC status
323
+ ])
324
+ app.add_servicer(MyServicer(), add_MyServiceServicer_to_server)
325
+ app.enable_health(checkers=[DatabaseHealthChecker(session_maker)]) # [health] extra
326
+ app.enable_reflection(["my.pkg.MyService"]) # [reflection] extra
327
+
328
+ asyncio.run(app.run())
329
+ ```
330
+
331
+ Prefer pydantic-validated, env-friendly settings? Use
332
+ `grpc_server_kit.settings.BaseGrpcServerSettings` (the `[settings]` extra) —
333
+ `GrpcServerConfig` and `BaseGrpcServerSettings` are interchangeable everywhere
334
+ the kit accepts settings.
335
+
336
+ ## Streaming-aware interceptors
337
+
338
+ Every interceptor wraps the **whole** RPC for all four call kinds — unary-unary,
339
+ unary-stream, stream-unary, stream-stream. Durations cover the full stream,
340
+ errors raised mid-stream are mapped to proper gRPC statuses, and cleanup always
341
+ runs. Write your own by implementing a single async-generator hook:
342
+
343
+ ```python
344
+ from grpc_server_kit.aio.interceptors import AsyncServerInterceptor, RpcCall
345
+
346
+ class TimingInterceptor(AsyncServerInterceptor):
347
+ async def around_call(self, call: RpcCall):
348
+ start = time.perf_counter()
349
+ try:
350
+ yield # the RPC (or the full response stream) runs here
351
+ finally:
352
+ log.info("%s took %.3fs", call.method_name, time.perf_counter() - start)
353
+ ```
354
+
355
+ Canonical chain order (outermost first): `metrics → context → logger → tracing
356
+ → exception handler → sentry`. The exception handler maps exception types to
357
+ gRPC statuses over the MRO and sends safe, non-leaking details; deliberate
358
+ `context.abort()` calls pass through untouched. Sentry sits **inside** the
359
+ exception handler so it observes raw handler exceptions before they become
360
+ aborts (outside it would never capture anything), with a capture filter that
361
+ reports only server-class errors.
362
+
363
+ ## Advanced API
364
+
365
+ `GrpcApp` is sugar over small, composable pieces you can use directly — for DI
366
+ containers, custom lifecycles, or embedding:
367
+
368
+ ```python
369
+ from grpc_server_kit import bind_server_port
370
+ from grpc_server_kit.aio import AsyncGrpcServerBuilder, run_async_grpc_server
371
+
372
+ server = (
373
+ AsyncGrpcServerBuilder(settings)
374
+ .with_interceptors(interceptors)
375
+ .with_servicers(lambda s: add_MyServiceServicer_to_server(MyServicer(), s))
376
+ .with_reflection(["my.pkg.MyService"])
377
+ .build()
378
+ )
379
+ bind_server_port(server, settings) # honors settings.ssl_enabled (TLS/mTLS)
380
+ await run_async_grpc_server(server, address=f"{settings.host}:{settings.port}")
381
+ ```
382
+
383
+ ## Dishka DI providers (cut the per-service boilerplate)
384
+
385
+ If your service uses [Dishka](https://github.com/reagento/dishka), the kit ships ready-made
386
+ providers so you register a handful of providers instead of hand-writing the interceptor
387
+ list, settings aliasing, and a metrics provider. `grpc_server_providers(...)` bundles the
388
+ standard set in one call:
389
+
390
+ ```python
391
+ from dishka import make_async_container
392
+ from grpc_server_kit.dishka import GrpcioProvider, FromDishka, inject
393
+ from grpc_server_kit.aio.dishka import grpc_server_providers
394
+ from grpc_server_kit.aio.server import AsyncServer
395
+ from grpc_server_kit.aio import run_async_grpc_server
396
+ from grpc_server_kit import bind_server_port
397
+
398
+ container = make_async_container(
399
+ *grpc_server_providers( # settings + metrics + sentry/tracer seams
400
+ settings.grpc, # + the canonical interceptor chain + AsyncServer
401
+ service_name="my.pkg.MyService",
402
+ error_status_map=MY_ERROR_STATUS_MAP, # service-specific domain map (optional)
403
+ metrics_enabled=settings.grpc.metrics_enabled,
404
+ ),
405
+ GrpcioProvider(), # request-scoped ServicerContext for FromDishka
406
+ MyDomainProvider(), # your use-cases / repos
407
+ )
408
+
409
+ server = await container.get(AsyncServer) # interceptors + options already wired
410
+ add_MyServiceServicer_to_server(MyServicer(), server) # AsyncServer works directly
411
+ bind_server_port(server, settings.grpc)
412
+ await run_async_grpc_server(server, address=f"{settings.grpc.host}:{settings.grpc.port}")
413
+ ```
414
+
415
+ The interceptor chain is built in the canonical order
416
+ (`metrics → context → logger → tracing → exception → sentry → DishkaAioInterceptor`), with
417
+ `include_*` toggles and `extra_outer` / `extra_inner` slots on
418
+ `GrpcServerInterceptorsProvider`. Providers degrade gracefully: the metrics / Sentry / tracer
419
+ seams resolve to `None` when disabled or their extra is absent, and the interceptors no-op.
420
+ SDK initialization (`sentry_sdk.init`, OpenTelemetry setup, the `/metrics` HTTP server) is a
421
+ process-wide concern and is **not** done by these providers. Requires `[dishka]`
422
+ (+ `[metrics]`/`[sentry]`/`[tracing]` for those seams).
423
+
424
+ Granular providers (`GrpcServerSettingsProvider`, `PrometheusGrpcServerMetricsProvider`,
425
+ `SentryAdapterProvider`, `TracerAdapterProvider`, `GrpcServerInterceptorsProvider`,
426
+ `AsyncGrpcServerProvider`) are available for finer control.
427
+
428
+ ## What's inside
429
+
430
+ > **Layout convention:** all async code lives under a single `grpc_server_kit.aio`
431
+ > package (mirroring `grpc.aio`), organized by domain (`aio.health`, `aio.interceptors`,
432
+ > `aio.observability`, `aio.dishka`). Modules that work for both sync and async stay at
433
+ > the top level — either directly (`config`, `options`, `credentials`, `server`,
434
+ > `protocols`, `signals`, `settings`) or as shared domain packages (`interceptors` →
435
+ > constants/utils, `observability` → protocols/metrics/sentry, `dishka` → providers).
436
+
437
+ | Module | Responsibility | Extra |
438
+ | :--- | :--- | :--- |
439
+ | `aio.GrpcApp` | One-object facade: config → servicers → run | core |
440
+ | `config.GrpcServerConfig` | Zero-dependency settings dataclass | core |
441
+ | `aio.builder.AsyncGrpcServerBuilder` | Fluent builder for an `AsyncServer` | core |
442
+ | `aio.create_async_grpc_server` / `aio.AsyncServer` | Server factory + typed wrapper | core |
443
+ | `aio.ServerLifecycleManager` / `aio.run_async_grpc_server` | Start/serve/stop with graceful shutdown | core |
444
+ | `aio.interceptors.*` | streaming-aware base + context, logger, metrics, tracing, sentry, exception-handler | core |
445
+ | `options` / `credentials` / `server` / `signals` / `protocols` | Channel options, TLS/mTLS, port binding, SIGINT/SIGTERM, seams | core |
446
+ | `settings.BaseGrpcServerSettings` | Pydantic config model | `settings` |
447
+ | `aio.health.*` | gRPC Health v1 servicer, orchestrator, TTL cache, pg/redis checkers | `health` |
448
+ | `observability.metrics.GrpcServerMetrics` | Prometheus metric definitions | `metrics` |
449
+ | `aio.observability.tracing.instrument_aio_server` | OpenTelemetry instrumentation | `tracing` |
450
+ | `observability.sentry.SentrySdkAdapter` | Sentry adapter for the sentry interceptor | `sentry` |
451
+ | `aio.dishka.*` / `dishka.*` | DI providers + `DishkaAioInterceptor` re-export | `dishka` |
452
+
453
+ ## Optional dependencies
454
+
455
+ | Extra | Pulls in | Enables |
456
+ | :--- | :--- | :--- |
457
+ | `reflection` | `grpcio-reflection` | server reflection |
458
+ | `channelz` | `grpcio-channelz` | channelz debugging |
459
+ | `settings` | `pydantic` | `BaseGrpcServerSettings` / `BaseHealthSettings` |
460
+ | `health` | `grpcio-health-checking` | health servicer / orchestrator / cache |
461
+ | `postgres` | `sqlalchemy[asyncio]` | `DatabaseHealthChecker` |
462
+ | `redis` | `redis` | `RedisHealthChecker` |
463
+ | `metrics` | `prometheus-client` | `GrpcServerMetrics` |
464
+ | `tracing` | `opentelemetry-instrumentation-grpc` | `instrument_aio_server` |
465
+ | `sentry` | `sentry-sdk` | `SentrySdkAdapter` |
466
+ | `dishka` | `dishka`, `protobuf` | DI providers + `DishkaAioInterceptor` |
467
+ | `all` | all of the above | everything |
468
+
469
+ ## Examples
470
+
471
+ Runnable, self-contained scripts in [`examples/`](examples/) — each prints what it's doing and exits on its own:
472
+
473
+ - [`minimal_server.py`](examples/minimal_server.py) — the smallest real server: `GrpcApp`, one servicer, `asyncio.run(app.run())`.
474
+ - [`observability_chain.py`](examples/observability_chain.py) — the canonical interceptor chain (metrics → context → logger → tracing → exception handler → sentry) wired by hand.
475
+ - [`custom_interceptor.py`](examples/custom_interceptor.py) — writing your own streaming-aware interceptor with `AsyncServerInterceptor.around_call`.
476
+ - [`health_checks.py`](examples/health_checks.py) — `app.enable_health()` with a custom dependency checker, driven through the real `grpc_health.v1` stubs.
477
+
478
+ ## Documentation
479
+
480
+ Full documentation at [bedrock-python.github.io/grpc-server-kit](https://bedrock-python.github.io/grpc-server-kit/).
481
+
482
+ ## License
483
+
484
+ Apache 2.0 — see [LICENSE](LICENSE).
@@ -0,0 +1,57 @@
1
+ grpc_server_kit/__init__.py,sha256=Y-ubotS6irv9DkW45NcxXXxWSIapd6Zr5sB1zJndY4w,928
2
+ grpc_server_kit/__version__.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
3
+ grpc_server_kit/config.py,sha256=cRU-O-RGKiLfoZus_45dzSc9y2a9x3qOL8oEJVWZeMs,3638
4
+ grpc_server_kit/constants.py,sha256=ToF7egu4ThA4oSI41SzgFEDWpuZ6nhuvmY-8x4XxT2o,1399
5
+ grpc_server_kit/credentials.py,sha256=pSUWV1PRrN3JIT7ykTuCp5nAfxNHkJZIxymCk5q-aBw,4155
6
+ grpc_server_kit/options.py,sha256=dZuVISoRnMUWwFHQluVBaXvQoBKRkqX1KC-dgakfb9g,5010
7
+ grpc_server_kit/protocols.py,sha256=T_ln67UkrW7txL1asEFMrcpF3DkN5RkjQ0FDlSMrFxI,3639
8
+ grpc_server_kit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ grpc_server_kit/server.py,sha256=NvP7dRFoU0YtAPMjTK-M9hELHur39_KSWakvVItJ2BQ,2155
10
+ grpc_server_kit/settings.py,sha256=pjDuUV-vfy3QtFK4aR5xJF8EwVyyEaAlHGEOglTBWyE,6388
11
+ grpc_server_kit/signals.py,sha256=LcLZjt9x-WOKTGdkBzncsvimfRUWvpEXVeG_DmFe_C0,8632
12
+ grpc_server_kit/aio/__init__.py,sha256=Dc_yu1Uvplzbzzyu05k0AQ4YCesfbPLc2Z7iNbvQ8N0,1261
13
+ grpc_server_kit/aio/app.py,sha256=PcKO7Y280491nk4BZi5YAtiECr1El8k6o5Ae371nNKU,15183
14
+ grpc_server_kit/aio/builder.py,sha256=DX7qFH2jpKDCHKGms771-7UCc9fTLMhsVOLtYdXqKeQ,2283
15
+ grpc_server_kit/aio/runtime.py,sha256=jrif3IyeAtQePAmUrePunGk7vavXkd6T1PORx-k0O8k,8107
16
+ grpc_server_kit/aio/server.py,sha256=WDvixdtnqbSyTRo4xegYAfLSRWpdNHFvMqlLTAgUWY4,7004
17
+ grpc_server_kit/aio/dishka/__init__.py,sha256=yOziJKapPNpbdijt51VT-YqBo-sYFTy9PqRjqwEhaiU,1082
18
+ grpc_server_kit/aio/dishka/bundle.py,sha256=QKhU-fw6LPhBu-wP9gTYdbdwzWzL_jeEpOKBmp3dbY8,2905
19
+ grpc_server_kit/aio/dishka/interceptors.py,sha256=xfr0jDLG0UIbP_gmW3FaQvIrUu-NsS5G30Z-EY8cnzw,5215
20
+ grpc_server_kit/aio/dishka/metrics.py,sha256=OwLvF8Hs1-5xl6qwu3Brdp_v36bZtMsoqCYXv7EqZ94,1833
21
+ grpc_server_kit/aio/dishka/observability.py,sha256=V_t3Z_SVEQhq16NzvFMZUrJy3dDf57GtW7_9VF7H9C8,3093
22
+ grpc_server_kit/aio/dishka/server.py,sha256=lWEQk4hCY2w0cIUA9Md0aJidU_hDnZhigWRRDA_gO0U,2169
23
+ grpc_server_kit/aio/health/__init__.py,sha256=4ihBbqAKlGN2E7Ov2ZHHyqW6veRzGkr_Rm4XIca2IsU,1075
24
+ grpc_server_kit/aio/health/cache.py,sha256=DvCMrO89JBEstpt2hJxDg964YQ2-YKVm7hjAAK2--mI,3250
25
+ grpc_server_kit/aio/health/orchestrator.py,sha256=NJx9LE5hkuyaExG9RvqYOvzfB2xbKmhLqE1VbrI2DTI,4229
26
+ grpc_server_kit/aio/health/protocols.py,sha256=BAyTphxx0fgId5Me2VondQtuy5mGieubzlAoysImYyM,1367
27
+ grpc_server_kit/aio/health/servicer.py,sha256=NpiCNF4RSQnJa9byuHfBIwrlBstMrqPfagE3dEZMlwc,10115
28
+ grpc_server_kit/aio/health/checkers/__init__.py,sha256=26ITNr1oQ1yQ9gsop0uoqcLJrSH2vPOTKm2jBOHoY3s,534
29
+ grpc_server_kit/aio/health/checkers/postgres.py,sha256=Q8reWB2HdjepxXoI5Hl5kBRtn_9_scebET4YQq--pCk,3902
30
+ grpc_server_kit/aio/health/checkers/redis.py,sha256=jGzhFOzho9WC3rAesK1S-QL2GWDKkmZSqqdX5ZGoDwo,2995
31
+ grpc_server_kit/aio/health/checkers/utils.py,sha256=L_KdsBVXk5-wSTduRgWh09TrfszauZYG1vMEgzaKFFg,3486
32
+ grpc_server_kit/aio/interceptors/__init__.py,sha256=J20nStQB26My26rFe73ANt6Cu9FibWgyugjRTYbFgl8,2110
33
+ grpc_server_kit/aio/interceptors/base.py,sha256=HObh5B84M-2PgVou2Msxw5G3FNc6yRFA6RjfxPkOWEw,9435
34
+ grpc_server_kit/aio/interceptors/context.py,sha256=Tp41tyuMVKX_-omLLb-IAJavknci6JXE4osm-FSJurc,6832
35
+ grpc_server_kit/aio/interceptors/exception_handler.py,sha256=T9i05KDxNuFDHj-raCfuthH6P41n0KAvzSTThd7T2Vc,7076
36
+ grpc_server_kit/aio/interceptors/metadata.py,sha256=vjAZ5a1TcS65aV_TKm8E62yPL6f_tlxacaVr5ocrgAE,2109
37
+ grpc_server_kit/aio/interceptors/metrics.py,sha256=VY6-jhY6datryfZVZAl3-yOuzx-ojG6uSALjhrtU2LE,3910
38
+ grpc_server_kit/aio/interceptors/protocols.py,sha256=-mztxVldbyNszNwmcoWfJ5AESbSAwuh-tWiSh_izdiw,1429
39
+ grpc_server_kit/aio/interceptors/request_logger.py,sha256=rQNTmgdzMc7WMUFx6tHwc3qfQ10xhp-6rqPlEhHinfI,4145
40
+ grpc_server_kit/aio/interceptors/sentry.py,sha256=jG-pLQ0YFwJRnkRO6nfL94s5h4EYmw60Rwc__xanyqg,3678
41
+ grpc_server_kit/aio/interceptors/tracing.py,sha256=XEjfR8G5Jst-lSG4kC1FfEuN2UAVNHSekHxVXOBQElc,5285
42
+ grpc_server_kit/aio/observability/__init__.py,sha256=6XGtDzkMPkowOf5B8Z0-N77l8rVCIQqvJz16Im54Rmw,223
43
+ grpc_server_kit/aio/observability/tracing.py,sha256=5ncOM2pDTvSzU0Gt916THFn4PdPBBVMCIGUBSS6MKo0,1530
44
+ grpc_server_kit/dishka/__init__.py,sha256=kY02b-Iuhz3y0mGqKESjRPlp0R7A8WRDF65EouwIg9U,1217
45
+ grpc_server_kit/dishka/settings.py,sha256=yEltiACl5iyNWR3u_HpdjzTuMDMWUDCrCN_JSHm7Fz8,1425
46
+ grpc_server_kit/interceptors/__init__.py,sha256=V7ysONRMzmEBVTABQbXUv4AZjYRNWFSEK27c0niytDA,444
47
+ grpc_server_kit/interceptors/constants.py,sha256=zKrClsT6E1aWy4-2zqLt2FPJUAWSkU_rCOkn5wLpmtw,1105
48
+ grpc_server_kit/interceptors/utils.py,sha256=Z_GvaHbZwmH12W-gA7rIxGGB6QRUPa6r6HwvIbSbowM,2383
49
+ grpc_server_kit/observability/__init__.py,sha256=8EFf9VRvXTaIP3x5zFcBHg4Dd6bsHmxoze3eIFL_OZs,550
50
+ grpc_server_kit/observability/metrics.py,sha256=XsC2stqYzPVHGV1GdP6M3uflHXLGpEBnrTMx0M66-Ls,4114
51
+ grpc_server_kit/observability/naming.py,sha256=gUcnThpGTK8zeSn3IOwOZeIr2DsD9iCQ6iJLyVJmAzo,761
52
+ grpc_server_kit/observability/protocols.py,sha256=0zm2xyM3Tr3Kbsk-07v9Xs6OX9x5aQzE8YcFAef_hgg,2603
53
+ grpc_server_kit/observability/sentry.py,sha256=uJr2_OdLNWLlF5Nn_oJ4pjLQevCjksq8EOvnZeQnG3g,1982
54
+ grpc_server_kit-0.1.0.dist-info/METADATA,sha256=u4SH4oL8Kkm3z1zjeo4WRuOisTFODcoypRy71XNufHI,26155
55
+ grpc_server_kit-0.1.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
56
+ grpc_server_kit-0.1.0.dist-info/licenses/LICENSE,sha256=HqasrACfRh7mgdbiXMVrs_X8dOCZed1b8KXY7i6Ch14,10239
57
+ grpc_server_kit-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any