dory-processor-sdk 0.0.1__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 (93) hide show
  1. dory_processor_sdk-0.0.1/LICENSE +201 -0
  2. dory_processor_sdk-0.0.1/MANIFEST.in +5 -0
  3. dory_processor_sdk-0.0.1/PKG-INFO +424 -0
  4. dory_processor_sdk-0.0.1/README-pypi.md +383 -0
  5. dory_processor_sdk-0.0.1/README.md +476 -0
  6. dory_processor_sdk-0.0.1/pyproject.toml +151 -0
  7. dory_processor_sdk-0.0.1/setup.cfg +4 -0
  8. dory_processor_sdk-0.0.1/src/dory/__init__.py +101 -0
  9. dory_processor_sdk-0.0.1/src/dory/auth/__init__.py +10 -0
  10. dory_processor_sdk-0.0.1/src/dory/auth/oauth2.py +153 -0
  11. dory_processor_sdk-0.0.1/src/dory/auto_instrument.py +142 -0
  12. dory_processor_sdk-0.0.1/src/dory/cli/__init__.py +5 -0
  13. dory_processor_sdk-0.0.1/src/dory/cli/main.py +137 -0
  14. dory_processor_sdk-0.0.1/src/dory/cli/templates.py +123 -0
  15. dory_processor_sdk-0.0.1/src/dory/config/__init__.py +23 -0
  16. dory_processor_sdk-0.0.1/src/dory/config/defaults.py +24 -0
  17. dory_processor_sdk-0.0.1/src/dory/config/loader.py +430 -0
  18. dory_processor_sdk-0.0.1/src/dory/config/presets.py +73 -0
  19. dory_processor_sdk-0.0.1/src/dory/config/schema.py +84 -0
  20. dory_processor_sdk-0.0.1/src/dory/core/__init__.py +27 -0
  21. dory_processor_sdk-0.0.1/src/dory/core/app.py +434 -0
  22. dory_processor_sdk-0.0.1/src/dory/core/context.py +209 -0
  23. dory_processor_sdk-0.0.1/src/dory/core/lifecycle.py +214 -0
  24. dory_processor_sdk-0.0.1/src/dory/core/meta.py +121 -0
  25. dory_processor_sdk-0.0.1/src/dory/core/modes.py +479 -0
  26. dory_processor_sdk-0.0.1/src/dory/core/processor.py +564 -0
  27. dory_processor_sdk-0.0.1/src/dory/core/signals.py +122 -0
  28. dory_processor_sdk-0.0.1/src/dory/decorators.py +142 -0
  29. dory_processor_sdk-0.0.1/src/dory/edge/__init__.py +88 -0
  30. dory_processor_sdk-0.0.1/src/dory/edge/adaptive.py +644 -0
  31. dory_processor_sdk-0.0.1/src/dory/edge/detector.py +546 -0
  32. dory_processor_sdk-0.0.1/src/dory/edge/fencing.py +488 -0
  33. dory_processor_sdk-0.0.1/src/dory/edge/heartbeat.py +598 -0
  34. dory_processor_sdk-0.0.1/src/dory/edge/role.py +419 -0
  35. dory_processor_sdk-0.0.1/src/dory/errors/__init__.py +139 -0
  36. dory_processor_sdk-0.0.1/src/dory/errors/classification.py +362 -0
  37. dory_processor_sdk-0.0.1/src/dory/errors/codes.py +498 -0
  38. dory_processor_sdk-0.0.1/src/dory/geo/__init__.py +40 -0
  39. dory_processor_sdk-0.0.1/src/dory/geo/geolocalizer.py +1034 -0
  40. dory_processor_sdk-0.0.1/src/dory/health/__init__.py +12 -0
  41. dory_processor_sdk-0.0.1/src/dory/health/probes.py +210 -0
  42. dory_processor_sdk-0.0.1/src/dory/health/server.py +635 -0
  43. dory_processor_sdk-0.0.1/src/dory/k8s/__init__.py +80 -0
  44. dory_processor_sdk-0.0.1/src/dory/k8s/annotation_watcher.py +184 -0
  45. dory_processor_sdk-0.0.1/src/dory/k8s/client.py +251 -0
  46. dory_processor_sdk-0.0.1/src/dory/k8s/labels.py +505 -0
  47. dory_processor_sdk-0.0.1/src/dory/k8s/pod_metadata.py +182 -0
  48. dory_processor_sdk-0.0.1/src/dory/logging/__init__.py +9 -0
  49. dory_processor_sdk-0.0.1/src/dory/logging/logger.py +148 -0
  50. dory_processor_sdk-0.0.1/src/dory/metrics/__init__.py +7 -0
  51. dory_processor_sdk-0.0.1/src/dory/metrics/collector.py +301 -0
  52. dory_processor_sdk-0.0.1/src/dory/middleware/__init__.py +46 -0
  53. dory_processor_sdk-0.0.1/src/dory/middleware/connection_tracker.py +608 -0
  54. dory_processor_sdk-0.0.1/src/dory/middleware/request_id.py +325 -0
  55. dory_processor_sdk-0.0.1/src/dory/middleware/request_tracker.py +511 -0
  56. dory_processor_sdk-0.0.1/src/dory/migration/__init__.py +33 -0
  57. dory_processor_sdk-0.0.1/src/dory/migration/configmap.py +232 -0
  58. dory_processor_sdk-0.0.1/src/dory/migration/s3_store.py +594 -0
  59. dory_processor_sdk-0.0.1/src/dory/migration/serialization.py +135 -0
  60. dory_processor_sdk-0.0.1/src/dory/migration/state_manager.py +286 -0
  61. dory_processor_sdk-0.0.1/src/dory/migration/transfer.py +382 -0
  62. dory_processor_sdk-0.0.1/src/dory/monitoring/__init__.py +29 -0
  63. dory_processor_sdk-0.0.1/src/dory/monitoring/opentelemetry.py +489 -0
  64. dory_processor_sdk-0.0.1/src/dory/output/__init__.py +31 -0
  65. dory_processor_sdk-0.0.1/src/dory/output/envelope.py +137 -0
  66. dory_processor_sdk-0.0.1/src/dory/output/formatter.py +113 -0
  67. dory_processor_sdk-0.0.1/src/dory/output/rabbitmq.py +632 -0
  68. dory_processor_sdk-0.0.1/src/dory/output/routing.py +318 -0
  69. dory_processor_sdk-0.0.1/src/dory/output/validator.py +199 -0
  70. dory_processor_sdk-0.0.1/src/dory/py.typed +2 -0
  71. dory_processor_sdk-0.0.1/src/dory/recovery/__init__.py +60 -0
  72. dory_processor_sdk-0.0.1/src/dory/recovery/golden_image.py +487 -0
  73. dory_processor_sdk-0.0.1/src/dory/recovery/golden_snapshot.py +713 -0
  74. dory_processor_sdk-0.0.1/src/dory/recovery/golden_validator.py +518 -0
  75. dory_processor_sdk-0.0.1/src/dory/recovery/partial_recovery.py +482 -0
  76. dory_processor_sdk-0.0.1/src/dory/recovery/recovery_decision.py +242 -0
  77. dory_processor_sdk-0.0.1/src/dory/recovery/restart_detector.py +142 -0
  78. dory_processor_sdk-0.0.1/src/dory/recovery/state_validator.py +183 -0
  79. dory_processor_sdk-0.0.1/src/dory/resilience/__init__.py +45 -0
  80. dory_processor_sdk-0.0.1/src/dory/resilience/circuit_breaker.py +457 -0
  81. dory_processor_sdk-0.0.1/src/dory/resilience/retry.py +389 -0
  82. dory_processor_sdk-0.0.1/src/dory/simple.py +342 -0
  83. dory_processor_sdk-0.0.1/src/dory/types.py +68 -0
  84. dory_processor_sdk-0.0.1/src/dory/utils/__init__.py +31 -0
  85. dory_processor_sdk-0.0.1/src/dory/utils/errors.py +59 -0
  86. dory_processor_sdk-0.0.1/src/dory/utils/retry.py +115 -0
  87. dory_processor_sdk-0.0.1/src/dory/utils/timeout.py +80 -0
  88. dory_processor_sdk-0.0.1/src/dory_processor_sdk.egg-info/PKG-INFO +424 -0
  89. dory_processor_sdk-0.0.1/src/dory_processor_sdk.egg-info/SOURCES.txt +91 -0
  90. dory_processor_sdk-0.0.1/src/dory_processor_sdk.egg-info/dependency_links.txt +1 -0
  91. dory_processor_sdk-0.0.1/src/dory_processor_sdk.egg-info/entry_points.txt +2 -0
  92. dory_processor_sdk-0.0.1/src/dory_processor_sdk.egg-info/requires.txt +20 -0
  93. dory_processor_sdk-0.0.1/src/dory_processor_sdk.egg-info/top_level.txt +1 -0
@@ -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 Derivative
95
+ 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, excluding
103
+ those notices that do not pertain to any part of the Derivative
104
+ 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 do
117
+ not modify the License. You may add Your own attribution notices
118
+ within Derivative Works that You distribute, alongside or as an
119
+ addendum to the NOTICE text from the Work, provided that such
120
+ additional attribution notices cannot be construed as modifying
121
+ 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 Dory Project Contributors
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,5 @@
1
+ # Keep tests and examples out of the source distribution
2
+ prune tests
3
+ prune examples
4
+ recursive-exclude tests *
5
+ recursive-exclude examples *
@@ -0,0 +1,424 @@
1
+ Metadata-Version: 2.4
2
+ Name: dory-processor-sdk
3
+ Version: 0.0.1
4
+ Summary: Python SDK for building stateful processors with zero-downtime migration, auto-initialization, and smart instrumentation
5
+ Author-email: Dory Team <xguo2016@fau.edu>
6
+ License: Apache-2.0
7
+ Keywords: kubernetes,stateful,migration,orchestration,sdk
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Classifier: Topic :: System :: Distributed Computing
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.11
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: aiohttp>=3.8.0
23
+ Requires-Dist: pydantic>=2.0.0
24
+ Requires-Dist: PyYAML>=6.0
25
+ Provides-Extra: production
26
+ Requires-Dist: kubernetes>=28.0.0; extra == "production"
27
+ Requires-Dist: boto3>=1.28.0; extra == "production"
28
+ Requires-Dist: opentelemetry-api>=1.20.0; extra == "production"
29
+ Requires-Dist: opentelemetry-sdk>=1.20.0; extra == "production"
30
+ Requires-Dist: opentelemetry-exporter-otlp-proto-grpc>=1.20.0; extra == "production"
31
+ Requires-Dist: aio-pika>=9.0.0; extra == "production"
32
+ Requires-Dist: redis>=4.5.0; extra == "production"
33
+ Provides-Extra: dev
34
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
35
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
36
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
37
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
38
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
39
+ Requires-Dist: black>=23.0.0; extra == "dev"
40
+ Dynamic: license-file
41
+
42
+ # Dory Processor SDK
43
+
44
+ A production-ready Python SDK for building **stateful, fault-tolerant processors** on Kubernetes with zero-downtime migration, automatic state persistence, and comprehensive observability.
45
+
46
+ [![PyPI version](https://badge.fury.io/py/dory-processor-sdk.svg)](https://pypi.org/project/dory-processor-sdk/)
47
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
48
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
49
+
50
+ > **Part of the Dory platform.** The Dory Processor SDK is the official Python SDK for building processors that run on the **Dory platform**. It is designed to work together with the Dory orchestrator, which manages pod lifecycle, zero-downtime migration, state transfer, and edge failover for your processors.
51
+
52
+ ## Why Dory Processor SDK?
53
+
54
+ | Challenge | Without Dory | With Dory Processor SDK |
55
+ |-----------|--------------|---------------|
56
+ | Pod termination | State lost, start from scratch | State auto-saved to ConfigMap, restored on new pod |
57
+ | Node drain/maintenance | Downtime, manual intervention | Zero-downtime migration with state transfer |
58
+ | Transient failures | DIY retry logic | Built-in retry with exponential backoff |
59
+ | Cascading failures | Service degradation | Circuit breakers protect dependencies |
60
+ | Debugging distributed systems | Scattered logs | OpenTelemetry tracing across services |
61
+ | Health monitoring | Custom implementation | Built-in `/health`, `/ready`, `/metrics` |
62
+
63
+ ## Features
64
+
65
+ ### Core
66
+ - **`@stateful` decorator** - Automatic state persistence and restoration
67
+ - **`DoryApp`** - Application lifecycle management
68
+ - **`BaseProcessor`** - Base class with built-in hooks
69
+ - **`ExecutionContext`** - Pod metadata, logging, shutdown detection
70
+
71
+ ### Resilience
72
+ - **Circuit Breaker** - Prevent cascading failures with configurable thresholds
73
+ - **Retry with Backoff** - Exponential backoff with jitter and retry budgets
74
+ - **Error Classification** - Intelligent error categorization (transient, permanent, resource)
75
+
76
+ ### Observability
77
+ - **OpenTelemetry** - Distributed tracing with automatic span creation
78
+ - **Prometheus Metrics** - Built-in `/metrics` endpoint
79
+ - **Structured Logging** - JSON logs with request context
80
+
81
+ ### State Management
82
+ - **ConfigMap Backend** - Persist state in Kubernetes ConfigMaps
83
+ - **S3 Backend** - Store large state in S3 (with offline buffering)
84
+ - **Local Backend** - File-based storage for development
85
+ - **State Versioning** - Forward/backward compatible state formats
86
+
87
+ ### Recovery
88
+ - **Restart Detection** - Detect rapid restart loops
89
+ - **State Validation** - Validate state integrity before restore
90
+ - **Golden Snapshots** - Create known-good state checkpoints
91
+ - **Partial Recovery** - Recover individual fields when full restore fails
92
+ - **Golden Image Reset** - Factory reset capability
93
+
94
+ ### Middleware
95
+ - **Request Tracking** - Track request lifecycle and metrics
96
+ - **Request ID Propagation** - Automatic request ID across service calls
97
+ - **Connection Tracking** - Monitor connection lifecycle
98
+
99
+ ### Edge Support
100
+ - **Fencing Manager** - Split-brain prevention for edge deployments
101
+ - **Heartbeat Manager** - Connectivity monitoring
102
+ - **Role Manager** - Primary/standby failover
103
+
104
+ ## Installation
105
+
106
+ ```bash
107
+ pip install dory-processor-sdk # Core SDK (aiohttp, pydantic, PyYAML)
108
+ pip install dory-processor-sdk[production] # EKS deployment (K8s, S3, OpenTelemetry, RabbitMQ, Redis)
109
+ pip install dory-processor-sdk[dev] # Test/lint tooling (pytest, mypy, ruff, black)
110
+ ```
111
+
112
+ > Only two optional-dependency extras exist: `[production]` and `[dev]`. The Kubernetes, S3 (boto3),
113
+ > OpenTelemetry, RabbitMQ (aio-pika) and Redis dependencies are all bundled inside `[production]`.
114
+
115
+ ## Quick Start
116
+
117
+ ### Minimal Example (7 lines)
118
+
119
+ ```python
120
+ from dory import DoryApp, BaseProcessor, stateful
121
+
122
+ class MyApp(BaseProcessor):
123
+ counter = stateful(0) # Automatically saved and restored
124
+
125
+ async def run(self):
126
+ async for _ in self.run_loop(interval=1):
127
+ self.counter += 1
128
+ print(f"Count: {self.counter}")
129
+
130
+ if __name__ == "__main__":
131
+ DoryApp().run(MyApp)
132
+ ```
133
+
134
+ ### With Resilience Features
135
+
136
+ ```python
137
+ from dory import DoryApp, BaseProcessor, stateful
138
+ from dory.resilience import CircuitBreaker, retry_with_backoff
139
+ from dory.monitoring import create_span
140
+
141
+ class MyApp(BaseProcessor):
142
+ counter = stateful(0)
143
+ db_breaker = CircuitBreaker(name="database", failure_threshold=5)
144
+
145
+ @retry_with_backoff(max_attempts=3)
146
+ async def fetch_data(self):
147
+ with create_span("fetch_data"):
148
+ return await self.db_breaker.call(self.database.query)
149
+
150
+ async def run(self):
151
+ async for _ in self.run_loop(interval=1):
152
+ try:
153
+ data = await self.fetch_data()
154
+ self.counter += 1
155
+ except Exception as e:
156
+ self.context.logger().error(f"Failed: {e}")
157
+
158
+ if __name__ == "__main__":
159
+ DoryApp().run(MyApp)
160
+ ```
161
+
162
+ ### Function-Based API
163
+
164
+ ```python
165
+ from dory.simple import processor, state
166
+
167
+ counter = state(0)
168
+
169
+ @processor
170
+ async def main(ctx):
171
+ async for _ in ctx.run_loop(interval=1):
172
+ counter.value += 1
173
+ ctx.logger().info(f"Count: {counter.value}")
174
+ ```
175
+
176
+ ## Configuration
177
+
178
+ ### Zero-Config (Recommended)
179
+
180
+ **No configuration file needed!** The SDK auto-detects your environment:
181
+
182
+ | Environment | Auto-Configuration |
183
+ |-------------|-------------------|
184
+ | **Kubernetes** | Production preset, ConfigMap state, JSON logs, port 8080 |
185
+ | **Local** | Development preset, local file state, colored logs, auto-port |
186
+
187
+ Just run your code - the SDK handles everything.
188
+
189
+ **Run multiple apps locally?** Each auto-selects an available port (no conflicts).
190
+
191
+ ### Optional: dory.yaml
192
+
193
+ Only create `dory.yaml` if you need custom settings. `DoryConfig` recognizes
194
+ exactly **five** keys (everything else is silently ignored via `extra="ignore"`):
195
+
196
+ ```yaml
197
+ startup_timeout_sec: 30 # 1-300, default 30
198
+ shutdown_timeout_sec: 30 # 1-300, default 30
199
+ health_port: 8080 # 0-65535, default 8080 (0 = auto-select)
200
+ state_backend: configmap # configmap | pvc | s3 | local, default configmap
201
+ log_level: INFO # DEBUG | INFO | WARNING | ERROR | CRITICAL, default INFO
202
+ ```
203
+
204
+ > **Not supported in `dory.yaml`:** retry, circuit-breaker, and OpenTelemetry tuning are
205
+ > **not** config-file keys. Any `retry:`, `circuit_breaker:`, or `opentelemetry:` block is
206
+ > silently dropped. Configure those components in code (see the resilience examples below)
207
+ > or via their constructor arguments in `BaseProcessor.__init__`.
208
+
209
+ See `docs/08-configuration.md` for the authoritative config reference.
210
+
211
+ ### Environment Variables
212
+
213
+ | Variable | Default | Description |
214
+ |----------|---------|-------------|
215
+ | `DORY_HEALTH_PORT` | 8080 | Health server port |
216
+ | `DORY_STATE_BACKEND` | configmap | State storage (configmap/pvc/s3/local) |
217
+ | `DORY_LOG_LEVEL` | INFO | Log level |
218
+ | `DORY_STARTUP_TIMEOUT_SEC` | 30 | Startup timeout |
219
+ | `DORY_SHUTDOWN_TIMEOUT_SEC` | 30 | Shutdown timeout |
220
+
221
+ See `docs/08-configuration.md` for the full runtime env var catalog.
222
+
223
+ ## API Reference
224
+
225
+ ### BaseProcessor
226
+
227
+ ```python
228
+ class MyApp(BaseProcessor):
229
+ # Stateful fields (auto-saved/restored)
230
+ counter = stateful(0)
231
+ data = stateful(dict)
232
+
233
+ async def startup(self):
234
+ """Called once on startup (optional)"""
235
+ pass
236
+
237
+ async def run(self):
238
+ """Main processing loop (required)"""
239
+ async for i in self.run_loop(interval=1):
240
+ self.counter += 1
241
+
242
+ async def shutdown(self):
243
+ """Called on graceful shutdown (optional)"""
244
+ pass
245
+
246
+ # Fault handling hooks (optional)
247
+ async def on_state_restore_failed(self, error: Exception):
248
+ """Called when state restoration fails"""
249
+ pass
250
+
251
+ async def on_rapid_restart_detected(self, restart_count: int):
252
+ """Called when rapid restart loop detected"""
253
+ pass
254
+
255
+ def reset_caches(self):
256
+ """Called on golden image reset"""
257
+ pass
258
+ ```
259
+
260
+ ### Circuit Breaker
261
+
262
+ ```python
263
+ from dory.resilience import CircuitBreaker, CircuitState
264
+
265
+ # Create circuit breaker
266
+ breaker = CircuitBreaker(
267
+ name="database",
268
+ failure_threshold=5, # Open after 5 failures
269
+ success_threshold=2, # Close after 2 successes in half-open
270
+ timeout_seconds=30.0, # Seconds before trying half-open
271
+ )
272
+
273
+ # Use with async call
274
+ result = await breaker.call(async_function, arg1, arg2)
275
+
276
+ # Check state
277
+ if breaker.state == CircuitState.OPEN:
278
+ print("Circuit is open, requests will fail fast")
279
+
280
+ # Manual control (both are async coroutines)
281
+ await breaker.open() # Force open
282
+ await breaker.reset() # Force closed
283
+ ```
284
+
285
+ ### Retry with Backoff
286
+
287
+ ```python
288
+ from dory.resilience import retry_with_backoff, RetryPolicy
289
+
290
+ # Decorator usage
291
+ @retry_with_backoff(max_attempts=3, initial_delay=0.1)
292
+ async def flaky_operation():
293
+ return await api.call()
294
+
295
+ # With custom policy
296
+ policy = RetryPolicy(
297
+ max_attempts=5,
298
+ initial_delay=0.1,
299
+ multiplier=2.0,
300
+ max_delay=30.0,
301
+ jitter=True
302
+ )
303
+
304
+ @retry_with_backoff(policy=policy)
305
+ async def custom_retry():
306
+ pass
307
+ ```
308
+
309
+ ### Error Classification
310
+
311
+ ```python
312
+ from dory.errors import ErrorClassifier, ErrorType
313
+
314
+ classifier = ErrorClassifier()
315
+
316
+ try:
317
+ await operation()
318
+ except Exception as e:
319
+ result = classifier.classify(e)
320
+
321
+ # ClassificationResult fields: error_type, recommended_action,
322
+ # retryable, severity, details
323
+ if result.retryable:
324
+ # Retry the operation
325
+ await retry_operation()
326
+ else:
327
+ # Don't retry, log and alert
328
+ logger.error(
329
+ f"Non-retryable error: {e} "
330
+ f"(action={result.recommended_action}, severity={result.severity})"
331
+ )
332
+ ```
333
+
334
+ ### OpenTelemetry
335
+
336
+ ```python
337
+ from dory.monitoring import create_span, add_span_attributes, trace_function
338
+
339
+ # Context manager
340
+ with create_span("database_query", {"table": "users"}):
341
+ result = await db.query("SELECT * FROM users")
342
+
343
+ # Decorator
344
+ @trace_function("process_item")
345
+ async def process_item(item):
346
+ add_span_attributes({"item_id": item.id})
347
+ return await transform(item)
348
+ ```
349
+
350
+ ### ExecutionContext
351
+
352
+ ```python
353
+ async def run(self):
354
+ ctx = self.context
355
+
356
+ # Logging
357
+ ctx.logger().info("Processing started")
358
+
359
+ # Pod metadata
360
+ print(f"Pod: {ctx.pod_name}")
361
+ print(f"Namespace: {ctx.pod_namespace}")
362
+ print(f"Processor ID: {ctx.processor_id}")
363
+
364
+ # Shutdown detection
365
+ while not ctx.is_shutdown_requested():
366
+ if ctx.is_migration_imminent():
367
+ print("Migration coming, saving state...")
368
+ await process()
369
+ ```
370
+
371
+ ## HTTP Endpoints
372
+
373
+ | Endpoint | Method | Description |
374
+ |----------|--------|-------------|
375
+ | `/health` | GET | Liveness probe (is process alive?) |
376
+ | `/ready` | GET | Readiness probe (ready to serve?) |
377
+ | `/metrics` | GET | Prometheus metrics |
378
+ | `/state` | GET | Export current state (Bearer-authenticated) |
379
+ | `/state` | POST | Import/restore state (Bearer-authenticated) |
380
+ | `/prestop` | GET | PreStop hook handler |
381
+ | `/` | GET | Service info + SDK version |
382
+
383
+ ## CLI Tool
384
+
385
+ The CLI provides two commands: `dory init` and `dory validate`.
386
+
387
+ ```bash
388
+ # Initialize a new project (creates main.py + Dockerfile)
389
+ dory init my-app
390
+ dory init my-app -o ./my-app -f # custom output dir, overwrite existing
391
+
392
+ # Validate configuration (loads dory.yaml + env overrides and prints settings)
393
+ dory validate
394
+ dory validate -c path/to/dory.yaml
395
+ ```
396
+
397
+ **`dory init` flags:** `name` (positional), `-o/--output`, `-i/--image` (accepted but
398
+ currently unused), `-f/--force`.
399
+ **`dory validate` flags:** `-c/--config`.
400
+
401
+ ## State Migration Flow
402
+
403
+ ### Pod Shutdown
404
+ ```
405
+ 1. Kubernetes sends SIGTERM / calls /prestop
406
+ 2. SDK marks processor as not-ready
407
+ 3. SDK saves state to ConfigMap
408
+ 4. Your shutdown() is called
409
+ 5. Pod terminates
410
+ ```
411
+
412
+ ### Pod Startup
413
+ ```
414
+ 1. New pod starts
415
+ 2. SDK checks for existing state in ConfigMap
416
+ 3. Your startup() is called
417
+ 4. SDK restores state (calls restore_state or sets @stateful fields)
418
+ 5. SDK marks processor as ready
419
+ 6. Your run() starts
420
+ ```
421
+
422
+ ## License
423
+
424
+ Apache 2.0