servicewright 0.1.0__tar.gz

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 (117) hide show
  1. servicewright-0.1.0/.gitignore +133 -0
  2. servicewright-0.1.0/CHANGELOG.md +19 -0
  3. servicewright-0.1.0/LICENSE +201 -0
  4. servicewright-0.1.0/PKG-INFO +239 -0
  5. servicewright-0.1.0/README.md +159 -0
  6. servicewright-0.1.0/pyproject.toml +287 -0
  7. servicewright-0.1.0/servicewright/__init__.py +134 -0
  8. servicewright-0.1.0/servicewright/__version__.py +15 -0
  9. servicewright-0.1.0/servicewright/adapters/__init__.py +11 -0
  10. servicewright-0.1.0/servicewright/adapters/_uvicorn.py +200 -0
  11. servicewright-0.1.0/servicewright/adapters/apscheduler3/__init__.py +20 -0
  12. servicewright-0.1.0/servicewright/adapters/apscheduler3/_imports.py +26 -0
  13. servicewright-0.1.0/servicewright/adapters/apscheduler3/config.py +54 -0
  14. servicewright-0.1.0/servicewright/adapters/apscheduler3/entrypoint.py +228 -0
  15. servicewright-0.1.0/servicewright/adapters/apscheduler3/exceptions.py +25 -0
  16. servicewright-0.1.0/servicewright/adapters/apscheduler4/__init__.py +16 -0
  17. servicewright-0.1.0/servicewright/adapters/apscheduler4/_imports.py +25 -0
  18. servicewright-0.1.0/servicewright/adapters/apscheduler4/config.py +56 -0
  19. servicewright-0.1.0/servicewright/adapters/apscheduler4/entrypoint.py +304 -0
  20. servicewright-0.1.0/servicewright/adapters/apscheduler4/exceptions.py +21 -0
  21. servicewright-0.1.0/servicewright/adapters/builtin/__init__.py +8 -0
  22. servicewright-0.1.0/servicewright/adapters/builtin/daemon.py +37 -0
  23. servicewright-0.1.0/servicewright/adapters/builtin/oneshot.py +37 -0
  24. servicewright-0.1.0/servicewright/adapters/dishka/__init__.py +12 -0
  25. servicewright-0.1.0/servicewright/adapters/dishka/container.py +120 -0
  26. servicewright-0.1.0/servicewright/adapters/fastapi/__init__.py +71 -0
  27. servicewright-0.1.0/servicewright/adapters/fastapi/_imports.py +33 -0
  28. servicewright-0.1.0/servicewright/adapters/fastapi/config.py +166 -0
  29. servicewright-0.1.0/servicewright/adapters/fastapi/configurators.py +163 -0
  30. servicewright-0.1.0/servicewright/adapters/fastapi/context.py +155 -0
  31. servicewright-0.1.0/servicewright/adapters/fastapi/entrypoint.py +282 -0
  32. servicewright-0.1.0/servicewright/adapters/fastapi/exceptions.py +161 -0
  33. servicewright-0.1.0/servicewright/adapters/fastapi/headers.py +62 -0
  34. servicewright-0.1.0/servicewright/adapters/fastapi/metrics.py +59 -0
  35. servicewright-0.1.0/servicewright/adapters/fastapi/middlewares/__init__.py +35 -0
  36. servicewright-0.1.0/servicewright/adapters/fastapi/middlewares/context.py +171 -0
  37. servicewright-0.1.0/servicewright/adapters/fastapi/middlewares/errors.py +79 -0
  38. servicewright-0.1.0/servicewright/adapters/fastapi/middlewares/logging.py +112 -0
  39. servicewright-0.1.0/servicewright/adapters/fastapi/middlewares/processing_time.py +40 -0
  40. servicewright-0.1.0/servicewright/adapters/fastapi/middlewares/protocols.py +27 -0
  41. servicewright-0.1.0/servicewright/adapters/fastapi/middlewares/sentry.py +94 -0
  42. servicewright-0.1.0/servicewright/adapters/fastapi/observability.py +65 -0
  43. servicewright-0.1.0/servicewright/adapters/fastapi/schemas.py +48 -0
  44. servicewright-0.1.0/servicewright/adapters/fastapi/unit_scope.py +113 -0
  45. servicewright-0.1.0/servicewright/adapters/grpc/__init__.py +37 -0
  46. servicewright-0.1.0/servicewright/adapters/grpc/_imports.py +35 -0
  47. servicewright-0.1.0/servicewright/adapters/grpc/config.py +146 -0
  48. servicewright-0.1.0/servicewright/adapters/grpc/context.py +167 -0
  49. servicewright-0.1.0/servicewright/adapters/grpc/entrypoint.py +298 -0
  50. servicewright-0.1.0/servicewright/adapters/grpc/errors.py +82 -0
  51. servicewright-0.1.0/servicewright/adapters/grpc/health.py +83 -0
  52. servicewright-0.1.0/servicewright/adapters/grpc/interceptors.py +153 -0
  53. servicewright-0.1.0/servicewright/adapters/grpc/metadata.py +132 -0
  54. servicewright-0.1.0/servicewright/adapters/grpc/metrics.py +65 -0
  55. servicewright-0.1.0/servicewright/adapters/health/__init__.py +16 -0
  56. servicewright-0.1.0/servicewright/adapters/health/postgres.py +96 -0
  57. servicewright-0.1.0/servicewright/adapters/health/redis.py +85 -0
  58. servicewright-0.1.0/servicewright/adapters/litestar/__init__.py +30 -0
  59. servicewright-0.1.0/servicewright/adapters/litestar/_imports.py +43 -0
  60. servicewright-0.1.0/servicewright/adapters/litestar/config.py +67 -0
  61. servicewright-0.1.0/servicewright/adapters/litestar/configurators.py +57 -0
  62. servicewright-0.1.0/servicewright/adapters/litestar/entrypoint.py +235 -0
  63. servicewright-0.1.0/servicewright/adapters/litestar/unit_scope.py +107 -0
  64. servicewright-0.1.0/servicewright/adapters/observability/__init__.py +26 -0
  65. servicewright-0.1.0/servicewright/adapters/observability/_errors/__init__.py +1 -0
  66. servicewright-0.1.0/servicewright/adapters/observability/_errors/sentry.py +101 -0
  67. servicewright-0.1.0/servicewright/adapters/observability/_logging/__init__.py +1 -0
  68. servicewright-0.1.0/servicewright/adapters/observability/_logging/stdlib.py +123 -0
  69. servicewright-0.1.0/servicewright/adapters/observability/_logging/structlog.py +102 -0
  70. servicewright-0.1.0/servicewright/adapters/observability/_metrics/__init__.py +1 -0
  71. servicewright-0.1.0/servicewright/adapters/observability/_metrics/prometheus.py +185 -0
  72. servicewright-0.1.0/servicewright/adapters/observability/_tracing/__init__.py +1 -0
  73. servicewright-0.1.0/servicewright/adapters/observability/_tracing/otel.py +95 -0
  74. servicewright-0.1.0/servicewright/adapters/observability/base.py +133 -0
  75. servicewright-0.1.0/servicewright/adapters/warmers/__init__.py +32 -0
  76. servicewright-0.1.0/servicewright/adapters/warmers/kafka.py +82 -0
  77. servicewright-0.1.0/servicewright/adapters/warmers/postgres.py +109 -0
  78. servicewright-0.1.0/servicewright/adapters/warmers/redis.py +158 -0
  79. servicewright-0.1.0/servicewright/core/__init__.py +124 -0
  80. servicewright-0.1.0/servicewright/core/aio/__init__.py +12 -0
  81. servicewright-0.1.0/servicewright/core/aio/host.py +372 -0
  82. servicewright-0.1.0/servicewright/core/constants.py +7 -0
  83. servicewright-0.1.0/servicewright/core/context.py +160 -0
  84. servicewright-0.1.0/servicewright/core/contracts/__init__.py +46 -0
  85. servicewright-0.1.0/servicewright/core/contracts/bases.py +94 -0
  86. servicewright-0.1.0/servicewright/core/contracts/container.py +65 -0
  87. servicewright-0.1.0/servicewright/core/contracts/entrypoint.py +54 -0
  88. servicewright-0.1.0/servicewright/core/contracts/health.py +13 -0
  89. servicewright-0.1.0/servicewright/core/contracts/lifecycle.py +16 -0
  90. servicewright-0.1.0/servicewright/core/contracts/observability.py +117 -0
  91. servicewright-0.1.0/servicewright/core/contracts/plugin.py +23 -0
  92. servicewright-0.1.0/servicewright/core/contracts/settings.py +48 -0
  93. servicewright-0.1.0/servicewright/core/contracts/warmer.py +40 -0
  94. servicewright-0.1.0/servicewright/core/errors.py +300 -0
  95. servicewright-0.1.0/servicewright/core/exceptions.py +35 -0
  96. servicewright-0.1.0/servicewright/core/health/__init__.py +8 -0
  97. servicewright-0.1.0/servicewright/core/health/registry.py +105 -0
  98. servicewright-0.1.0/servicewright/core/health/report.py +36 -0
  99. servicewright-0.1.0/servicewright/core/lifecycle/__init__.py +8 -0
  100. servicewright-0.1.0/servicewright/core/lifecycle/manager.py +133 -0
  101. servicewright-0.1.0/servicewright/core/observability/__init__.py +65 -0
  102. servicewright-0.1.0/servicewright/core/observability/config.py +61 -0
  103. servicewright-0.1.0/servicewright/core/observability/manager.py +211 -0
  104. servicewright-0.1.0/servicewright/core/observability/naming.py +26 -0
  105. servicewright-0.1.0/servicewright/core/observability/null.py +163 -0
  106. servicewright-0.1.0/servicewright/core/observability/protocols.py +60 -0
  107. servicewright-0.1.0/servicewright/core/observability/redaction.py +79 -0
  108. servicewright-0.1.0/servicewright/core/observability/registry.py +48 -0
  109. servicewright-0.1.0/servicewright/core/observability/sinks.py +117 -0
  110. servicewright-0.1.0/servicewright/core/service.py +63 -0
  111. servicewright-0.1.0/servicewright/core/signals.py +138 -0
  112. servicewright-0.1.0/servicewright/core/spec.py +85 -0
  113. servicewright-0.1.0/servicewright/core/warmup/__init__.py +8 -0
  114. servicewright-0.1.0/servicewright/core/warmup/engine.py +123 -0
  115. servicewright-0.1.0/servicewright/core/warmup/orchestrator.py +88 -0
  116. servicewright-0.1.0/servicewright/py.typed +0 -0
  117. servicewright-0.1.0/servicewright/testing.py +104 -0
@@ -0,0 +1,133 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ pip-wheel-metadata/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ *.manifest
32
+ *.spec
33
+
34
+ # Installer logs
35
+ pip-log.txt
36
+ pip-delete-this-directory.txt
37
+
38
+ # Unit test / coverage reports
39
+ htmlcov/
40
+ .tox/
41
+ .nox/
42
+ .coverage
43
+ .coverage.*
44
+ .cache
45
+ nosetests.xml
46
+ coverage.xml
47
+ *.cover
48
+ *.py,cover
49
+ .hypothesis/
50
+ .pytest_cache/
51
+
52
+ # Translations
53
+ *.mo
54
+ *.pot
55
+
56
+ # Django stuff:
57
+ *.log
58
+ local_settings.py
59
+ db.sqlite3
60
+ db.sqlite3-journal
61
+
62
+ # Flask stuff:
63
+ instance/
64
+ .webassets-cache
65
+
66
+ # Scrapy stuff:
67
+ .scrapy
68
+
69
+ # Sphinx documentation
70
+ docs/_build/
71
+
72
+ # PyBuilder
73
+ target/
74
+
75
+ # Jupyter Notebook
76
+ .ipynb_checkpoints
77
+
78
+ # IPython
79
+ profile_default/
80
+ ipython_config.py
81
+
82
+ # pyenv
83
+ .python-version
84
+
85
+ # pipenv
86
+ #Pipfile.lock
87
+
88
+ # PEP 582
89
+ __pypackages__/
90
+
91
+ # Celery stuff
92
+ celerybeat-schedule
93
+ celerybeat.pid
94
+
95
+ # SageMath parsed files
96
+ *.sage.py
97
+
98
+ # Environments
99
+ .env
100
+ .venv
101
+ env/
102
+ venv/
103
+ ENV/
104
+ env.bak/
105
+ venv.bak/
106
+
107
+ # Spyder project settings
108
+ .spyderproject
109
+ .spyproject
110
+
111
+ # Rope project settings
112
+ .ropeproject
113
+
114
+ # mkdocs documentation
115
+ /site
116
+ docs/changelog.md
117
+
118
+ # mypy
119
+ .mypy_cache/
120
+ .dmypy.json
121
+ dmypy.json
122
+
123
+ # Pyre type checker
124
+ .pyre/
125
+
126
+ # ruff
127
+ .ruff_cache/
128
+
129
+ # Internal working document, never part of the distribution
130
+ DEPS_AUDIT.md
131
+
132
+ # Throwaway venv for the APScheduler 3.x test job
133
+ .venv-aps3/
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2026-08-12)
4
+
5
+ Initial release of servicewright.
6
+
7
+ ### Features
8
+
9
+ * `Host` + `Entrypoint` model — one `AppSpec` runs any number of transports (HTTP, gRPC, scheduler, daemon, one-shot) under a single lifecycle
10
+ * Kubernetes-correct shutdown — readiness flips to false before draining, each entrypoint finishes in-flight work inside a grace window, the DI scope closes last
11
+ * Failure is visible — an essential entrypoint that dies mid-serve propagates out of `run()`, so the process exit code distinguishes a crash from a graceful stop
12
+ * Stop-aware startup — a signal during warmup or bind abandons startup instead of binding ports and reporting ready on a terminating process
13
+ * Signal escalation — the first SIGINT/SIGTERM drains gracefully, a second exits immediately with `128 + signum`
14
+ * Transport-neutral error taxonomy — one `ServiceError` renders as an RFC 9457 problem document over HTTP and as the mapped `grpc.StatusCode` over gRPC, with one masking rule and a pluggable renderer
15
+ * Transport-neutral correlation store — one request id in the logs, in outbound propagation and in the response, bridged into structlog contextvars and OTel Baggage
16
+ * DI-agnostic two-tier scopes — `AppScope` for process-lifetime singletons, a fresh `UnitScope` per request/RPC/job; dishka adapter included
17
+ * Pluggable observability — metrics, tracing, logging and error tracking as kernel protocols with prometheus, OpenTelemetry, Sentry, structlog and stdlib backends, plus `register_sink` for your own
18
+ * Priority-grouped, fail-fast warmup and a health registry driving both the HTTP probes and the gRPC health service
19
+ * Zero hard dependencies — `pip install servicewright` pulls nothing; every framework binding lives behind an extra
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Alex Shalaev
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,239 @@
1
+ Metadata-Version: 2.5
2
+ Name: servicewright
3
+ Version: 0.1.0
4
+ Summary: Batteries-optional microservice runtime: lifecycle, observability, warmup and gRPC/FastAPI transport entities to build services fast
5
+ Project-URL: Repository, https://github.com/bedrock-python/servicewright
6
+ Project-URL: Documentation, https://bedrock-python.github.io/servicewright/
7
+ Project-URL: Changelog, https://github.com/bedrock-python/servicewright/blob/master/CHANGELOG.md
8
+ Project-URL: Bug Tracker, https://github.com/bedrock-python/servicewright/issues
9
+ Author-email: Alex Shalaev <shalaevad.alexey@gmail.com>
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: asyncio,fastapi,graceful-shutdown,grpc,lifecycle,microservices,observability,runtime
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Framework :: AsyncIO
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.12
22
+ Provides-Extra: all
23
+ Requires-Dist: aiokafka>=0.10.0; extra == 'all'
24
+ Requires-Dist: apscheduler<5,>=4.0.0a5; extra == 'all'
25
+ Requires-Dist: deadline-budget<1.0.0,>=0.1.0; extra == 'all'
26
+ Requires-Dist: dishka>=1.4.0; extra == 'all'
27
+ Requires-Dist: fastapi<1.0.0,>=0.115.0; extra == 'all'
28
+ Requires-Dist: grpc-server-kit[channelz,health,reflection]<0.2,>=0.1.0; extra == 'all'
29
+ Requires-Dist: litestar>=2.12.0; extra == 'all'
30
+ Requires-Dist: opentelemetry-exporter-otlp-proto-grpc>=1.39.1; extra == 'all'
31
+ Requires-Dist: opentelemetry-instrumentation-fastapi>=0.60b1; extra == 'all'
32
+ Requires-Dist: opentelemetry-sdk>=1.39.1; extra == 'all'
33
+ Requires-Dist: prometheus-client<1.0.0,>=0.24.0; extra == 'all'
34
+ Requires-Dist: prometheus-fastapi-instrumentator<9.0.0,>=7.0.0; extra == 'all'
35
+ Requires-Dist: redis>=4.2.0; extra == 'all'
36
+ Requires-Dist: sentry-sdk<3.0.0,>=2.0.0; extra == 'all'
37
+ Requires-Dist: sqlalchemy[asyncio]<3.0.0,>=2.0.0; extra == 'all'
38
+ Requires-Dist: structlog<27.0.0,>=25.5.0; extra == 'all'
39
+ Requires-Dist: uvicorn[standard]<1.0.0,>=0.34.0; extra == 'all'
40
+ Provides-Extra: apscheduler3
41
+ Requires-Dist: apscheduler<4,>=3.10; extra == 'apscheduler3'
42
+ Provides-Extra: apscheduler4
43
+ Requires-Dist: apscheduler<5,>=4.0.0a5; extra == 'apscheduler4'
44
+ Provides-Extra: dishka
45
+ Requires-Dist: dishka>=1.4.0; extra == 'dishka'
46
+ Provides-Extra: fastapi
47
+ Requires-Dist: deadline-budget<1.0.0,>=0.1.0; extra == 'fastapi'
48
+ Requires-Dist: fastapi<1.0.0,>=0.115.0; extra == 'fastapi'
49
+ Requires-Dist: prometheus-fastapi-instrumentator<9.0.0,>=7.0.0; extra == 'fastapi'
50
+ Requires-Dist: uvicorn[standard]<1.0.0,>=0.34.0; extra == 'fastapi'
51
+ Provides-Extra: fastapi-tracing
52
+ Requires-Dist: deadline-budget<1.0.0,>=0.1.0; extra == 'fastapi-tracing'
53
+ Requires-Dist: fastapi<1.0.0,>=0.115.0; extra == 'fastapi-tracing'
54
+ Requires-Dist: opentelemetry-exporter-otlp-proto-grpc>=1.39.1; extra == 'fastapi-tracing'
55
+ Requires-Dist: opentelemetry-instrumentation-fastapi>=0.60b1; extra == 'fastapi-tracing'
56
+ Requires-Dist: opentelemetry-sdk>=1.39.1; extra == 'fastapi-tracing'
57
+ Requires-Dist: prometheus-fastapi-instrumentator<9.0.0,>=7.0.0; extra == 'fastapi-tracing'
58
+ Requires-Dist: structlog<27.0.0,>=25.5.0; extra == 'fastapi-tracing'
59
+ Requires-Dist: uvicorn[standard]<1.0.0,>=0.34.0; extra == 'fastapi-tracing'
60
+ Provides-Extra: grpc
61
+ Requires-Dist: grpc-server-kit[channelz,health,reflection]<0.2,>=0.1.0; extra == 'grpc'
62
+ Provides-Extra: kafka
63
+ Requires-Dist: aiokafka>=0.10.0; extra == 'kafka'
64
+ Provides-Extra: litestar
65
+ Requires-Dist: litestar>=2.12.0; extra == 'litestar'
66
+ Requires-Dist: uvicorn[standard]<1.0.0,>=0.34.0; extra == 'litestar'
67
+ Provides-Extra: metrics
68
+ Requires-Dist: prometheus-client<1.0.0,>=0.24.0; extra == 'metrics'
69
+ Provides-Extra: observability
70
+ Requires-Dist: opentelemetry-exporter-otlp-proto-grpc>=1.39.1; extra == 'observability'
71
+ Requires-Dist: opentelemetry-sdk>=1.39.1; extra == 'observability'
72
+ Requires-Dist: structlog<27.0.0,>=25.5.0; extra == 'observability'
73
+ Provides-Extra: postgres
74
+ Requires-Dist: sqlalchemy[asyncio]<3.0.0,>=2.0.0; extra == 'postgres'
75
+ Provides-Extra: redis
76
+ Requires-Dist: redis>=4.2.0; extra == 'redis'
77
+ Provides-Extra: sentry
78
+ Requires-Dist: sentry-sdk<3.0.0,>=2.0.0; extra == 'sentry'
79
+ Description-Content-Type: text/markdown
80
+
81
+ # servicewright
82
+
83
+ **One `Host`, many `Entrypoint`s** — a batteries-optional microservice runtime for async Python.
84
+
85
+ [![PyPI](https://img.shields.io/pypi/v/servicewright?color=blue)](https://pypi.org/project/servicewright/)
86
+ [![Python](https://img.shields.io/pypi/pyversions/servicewright)](https://pypi.org/project/servicewright/)
87
+ [![License](https://img.shields.io/github/license/bedrock-python/servicewright)](LICENSE)
88
+ [![CI](https://github.com/bedrock-python/servicewright/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/bedrock-python/servicewright/actions/workflows/ci.yml)
89
+ [![codecov](https://codecov.io/gh/bedrock-python/servicewright/graph/badge.svg)](https://codecov.io/gh/bedrock-python/servicewright)
90
+ [![Docs](https://img.shields.io/badge/docs-online-blue)](https://bedrock-python.github.io/servicewright/)
91
+
92
+ Describe a service once as an `AppSpec` (DI container, lifecycle, observability, warmup, health) and
93
+ run it through any number of pluggable entrypoints — HTTP, gRPC, scheduler, background daemon,
94
+ one-shot batch — under one unified lifecycle. The "API vs worker" distinction does not exist at the
95
+ core: a cron job and an HTTP request are the same thing — one unit of work in a fresh DI scope.
96
+
97
+ This is the model behind .NET Generic Host, Spring `SmartLifecycle` and go-kratos
98
+ `transport.Server`, adapted to async Python.
99
+
100
+ ## Why
101
+
102
+ - **One lifecycle for every archetype**: Bootstrap → Warmup → Ready → Serve → Drain → Cleanup.
103
+ Kubernetes-correct shutdown out of the box: readiness flips to `false` *before* draining, every
104
+ entrypoint finishes in-flight work within a grace window, the DI scope closes last, and a service
105
+ that dies mid-serve exits non-zero instead of looking like a graceful stop.
106
+ - **DI-agnostic two-tier scopes**: the core depends on no DI library. `AppScope` holds
107
+ process-lifetime singletons; a fresh `UnitScope` wraps every request / RPC / job / message.
108
+ A dishka adapter ships in the box; any container fits by implementing two methods.
109
+ - **Pluggable observability add-ons**: metrics / tracing / logging / error-tracking are protocols
110
+ in the kernel with selectable, extra-gated backends (prometheus, OpenTelemetry, Sentry,
111
+ structlog). Adding a backend = one module + one `register_sink` call, zero core changes.
112
+ - **One error taxonomy, every transport**: a `ServiceError` raised in business code renders as an
113
+ RFC 9457 problem document over HTTP and as the mapped `grpc.StatusCode` over gRPC, with one
114
+ masking rule for non-public details and a pluggable renderer when you own the wire format.
115
+ - **Zero hard dependencies**: `pip install servicewright` brings pure Python. Every framework
116
+ binding lives behind an extra; the kernel never imports an SDK, a vendor, or a transport.
117
+
118
+ ## Installation
119
+
120
+ ```bash
121
+ pip install servicewright # pure kernel, zero dependencies
122
+ pip install "servicewright[fastapi]" # + FastAPI/uvicorn entrypoint
123
+ pip install "servicewright[grpc]" # + gRPC entrypoint
124
+ pip install "servicewright[apscheduler4]" # + cron/scheduler entrypoint
125
+ pip install "servicewright[metrics,observability,sentry]" # + prometheus, otel+structlog, sentry
126
+ pip install "servicewright[all]" # everything except the conflicting [apscheduler3]
127
+ ```
128
+
129
+ **Requirements:** Python 3.12+
130
+
131
+ ## Quick start — HTTP API + cron in ONE process
132
+
133
+ ```python
134
+ import asyncio
135
+
136
+ from servicewright import AppSpec, ObsConfig, ObservabilityManager, Service, run
137
+ from servicewright.adapters.apscheduler4 import ScheduledJob, SchedulerEntrypoint
138
+ from servicewright.adapters.fastapi import FastApiEntrypoint
139
+
140
+
141
+ def build_service() -> Service:
142
+ spec = AppSpec(
143
+ service_name="orders-service",
144
+ create_container=build_container, # your DI container factory
145
+ observability=ObservabilityManager(
146
+ ObsConfig(metrics="prometheus", tracing="otel", logging="structlog"),
147
+ ),
148
+ )
149
+
150
+ http = FastApiEntrypoint(routers=(router,)) # kind="http"
151
+ cron = SchedulerEntrypoint(jobs=[ # kind="scheduler"
152
+ ScheduledJob(id="sweep", func=sweep_expired_orders, trigger=interval_trigger),
153
+ ])
154
+ return Service(spec, entrypoints=[http, cron])
155
+
156
+
157
+ if __name__ == "__main__":
158
+ asyncio.run(run(build_service(), Settings()))
159
+ ```
160
+
161
+ Both entrypoints share one DI container, one observability setup and one graceful shutdown.
162
+ Scaling the worker separately later = the same `AppSpec` in a second process with a different
163
+ entrypoint list.
164
+
165
+ ## Entrypoints
166
+
167
+ | Archetype | Adapter | Extra |
168
+ | --- | --- | --- |
169
+ | HTTP API | `adapters.fastapi` / `adapters.litestar` | `fastapi` / `litestar` |
170
+ | gRPC API | `adapters.grpc` | `grpc` |
171
+ | Scheduled / cron | `adapters.apscheduler4` / `adapters.apscheduler3` | `apscheduler4` / `apscheduler3` |
172
+ | Background daemon | `DaemonEntrypoint` (built-in) | — |
173
+ | One-shot / batch | `OneShotEntrypoint` (built-in) | — |
174
+
175
+ Writing your own entrypoint = implementing four methods (`bind`, `serve`, `drain`, `stop`)
176
+ with nothing installed.
177
+
178
+ ## What's inside
179
+
180
+ The kernel is `core/`; everything that touches a third-party SDK is an extra-gated adapter. An
181
+ import-linter contract enforces the direction in CI: deleting `adapters/` leaves `core/` importable.
182
+
183
+ | Module | Responsibility | Extra |
184
+ | --- | --- | --- |
185
+ | `servicewright` | `AppSpec`, `Service`, `Host`, `run` — the public vocabulary | — |
186
+ | `core.contracts` | `Entrypoint`, `Plugin`, container/settings/health protocols | — |
187
+ | `core.aio.host` | The lifecycle kernel: warmup → ready → serve → drain → cleanup | — |
188
+ | `core.errors` | `ServiceError`, `ErrorKind`, RFC 9457 renderer + renderer seam | — |
189
+ | `core.context` | Transport-neutral correlation store + outbound propagation | — |
190
+ | `core.health` | `HealthRegistry` driving both HTTP routes and the gRPC health service | — |
191
+ | `core.warmup` | Priority-grouped, fail-fast warmup before readiness flips | — |
192
+ | `core.observability` | Sink protocols, NullObjects, backend registry, redaction | — |
193
+ | `adapters.builtin` | `DaemonEntrypoint`, `OneShotEntrypoint` — zero-dependency | — |
194
+ | `adapters.fastapi` | FastAPI entrypoint, middleware stack, problem-details handlers | `fastapi` |
195
+ | `adapters.litestar` | Litestar entrypoint | `litestar` |
196
+ | `adapters.grpc` | gRPC entrypoint over grpc-server-kit, error mapping, health bridge | `grpc` |
197
+ | `adapters.apscheduler4` / `apscheduler3` | Scheduler entrypoints with identical public surfaces | `apscheduler4` / `apscheduler3` |
198
+ | `adapters.dishka` | dishka ⇄ core scope binding | `dishka` |
199
+ | `adapters.observability` | prometheus / OpenTelemetry / Sentry / structlog / stdlib sinks | see below |
200
+ | `adapters.warmers`, `adapters.health` | Redis / Postgres / Kafka warmers and checks | `redis`, `postgres`, `kafka` |
201
+ | `servicewright.testing` | `FakeContainer`, `FakeEntrypoint`, `FakeScope`, `FakeSettings` | — |
202
+
203
+ ## Optional dependencies
204
+
205
+ | Extra | Pulls in | Enables |
206
+ | --- | --- | --- |
207
+ | `fastapi` | fastapi, uvicorn, deadline-budget, prometheus-fastapi-instrumentator | `FastApiEntrypoint` + its middleware stack |
208
+ | `litestar` | litestar, uvicorn | `LitestarEntrypoint` |
209
+ | `grpc` | grpc-server-kit[reflection,channelz,health] | `GrpcEntrypoint`, error mapping, health bridge |
210
+ | `apscheduler4` / `apscheduler3` | apscheduler 4.x / 3.x | `SchedulerEntrypoint` (one major per environment) |
211
+ | `dishka` | dishka | `DishkaContainer` |
212
+ | `observability` | opentelemetry-sdk, OTLP gRPC exporter, structlog | `otel` tracing + `structlog` logging sinks |
213
+ | `fastapi-tracing` | the above + opentelemetry-instrumentation-fastapi | HTTP request spans |
214
+ | `metrics` | prometheus-client | `prometheus` metrics sink + `/system/metrics` |
215
+ | `sentry` | sentry-sdk | `sentry` error-tracking sink |
216
+ | `redis` / `postgres` / `kafka` | redis / sqlalchemy / aiokafka | matching warmers and health checks |
217
+ | `all` | everything except `apscheduler3` | the full runtime |
218
+
219
+ ## Examples
220
+
221
+ Runnable, self-contained scripts (each exits 0):
222
+
223
+ - [`examples/minimal_service.py`](examples/minimal_service.py) — the smallest real service, narrating
224
+ every lifecycle phase in order.
225
+ - [`examples/http_service.py`](examples/http_service.py) — a real uvicorn server with dishka DI,
226
+ per-request scopes, health probes, an RFC 9457 error on the wire and a graceful drain.
227
+ - [`examples/errors_and_context.py`](examples/errors_and_context.py) — the error taxonomy, a custom
228
+ renderer, masking, and the correlation store with outbound propagation.
229
+ - [`examples/warmup_and_health.py`](examples/warmup_and_health.py) — warmup priority groups,
230
+ fail-fast, and health checks driving readiness.
231
+
232
+ ## Documentation
233
+
234
+ Full documentation at [bedrock-python.github.io/servicewright](https://bedrock-python.github.io/servicewright/).
235
+ The reference architecture lives in [ARCHITECTURE.md](ARCHITECTURE.md).
236
+
237
+ ## License
238
+
239
+ Apache 2.0 — see [LICENSE](LICENSE).