resource-engine 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 (177) hide show
  1. resource_engine-0.1.0/.gitignore +18 -0
  2. resource_engine-0.1.0/CHANGELOG.md +16 -0
  3. resource_engine-0.1.0/LICENSE +202 -0
  4. resource_engine-0.1.0/PKG-INFO +36 -0
  5. resource_engine-0.1.0/README.md +5 -0
  6. resource_engine-0.1.0/pyproject.toml +39 -0
  7. resource_engine-0.1.0/src/resource_engine/__init__.py +96 -0
  8. resource_engine-0.1.0/src/resource_engine/application/__init__.py +1 -0
  9. resource_engine-0.1.0/src/resource_engine/application/actions.py +48 -0
  10. resource_engine-0.1.0/src/resource_engine/application/context.py +111 -0
  11. resource_engine-0.1.0/src/resource_engine/application/events.py +54 -0
  12. resource_engine-0.1.0/src/resource_engine/application/hooks.py +272 -0
  13. resource_engine-0.1.0/src/resource_engine/application/idempotency.py +277 -0
  14. resource_engine-0.1.0/src/resource_engine/application/manager.py +1987 -0
  15. resource_engine-0.1.0/src/resource_engine/application/query.py +47 -0
  16. resource_engine-0.1.0/src/resource_engine/application/registry.py +137 -0
  17. resource_engine-0.1.0/src/resource_engine/application/relations.py +470 -0
  18. resource_engine-0.1.0/src/resource_engine/application/resource.py +984 -0
  19. resource_engine-0.1.0/src/resource_engine/application/searching.py +162 -0
  20. resource_engine-0.1.0/src/resource_engine/application/settings.py +169 -0
  21. resource_engine-0.1.0/src/resource_engine/application/slots.py +67 -0
  22. resource_engine-0.1.0/src/resource_engine/application/state_machines.py +177 -0
  23. resource_engine-0.1.0/src/resource_engine/application/timers.py +347 -0
  24. resource_engine-0.1.0/src/resource_engine/application/transaction.py +100 -0
  25. resource_engine-0.1.0/src/resource_engine/application/views.py +239 -0
  26. resource_engine-0.1.0/src/resource_engine/audit/__init__.py +40 -0
  27. resource_engine-0.1.0/src/resource_engine/audit/export.py +280 -0
  28. resource_engine-0.1.0/src/resource_engine/audit/history.py +165 -0
  29. resource_engine-0.1.0/src/resource_engine/audit/janitor.py +257 -0
  30. resource_engine-0.1.0/src/resource_engine/audit/model.py +98 -0
  31. resource_engine-0.1.0/src/resource_engine/audit/recorder.py +145 -0
  32. resource_engine-0.1.0/src/resource_engine/audit/resource.py +68 -0
  33. resource_engine-0.1.0/src/resource_engine/audit/seal.py +327 -0
  34. resource_engine-0.1.0/src/resource_engine/audit/sink.py +69 -0
  35. resource_engine-0.1.0/src/resource_engine/authz/__init__.py +72 -0
  36. resource_engine-0.1.0/src/resource_engine/authz/apikeys.py +300 -0
  37. resource_engine-0.1.0/src/resource_engine/authz/base.py +143 -0
  38. resource_engine-0.1.0/src/resource_engine/authz/catalog.py +291 -0
  39. resource_engine-0.1.0/src/resource_engine/authz/conditions.py +416 -0
  40. resource_engine-0.1.0/src/resource_engine/authz/config.py +77 -0
  41. resource_engine-0.1.0/src/resource_engine/authz/evaluator.py +382 -0
  42. resource_engine-0.1.0/src/resource_engine/authz/external.py +249 -0
  43. resource_engine-0.1.0/src/resource_engine/authz/fields.py +44 -0
  44. resource_engine-0.1.0/src/resource_engine/authz/model.py +145 -0
  45. resource_engine-0.1.0/src/resource_engine/authz/resources.py +289 -0
  46. resource_engine-0.1.0/src/resource_engine/authz/roles.py +101 -0
  47. resource_engine-0.1.0/src/resource_engine/cache.py +144 -0
  48. resource_engine-0.1.0/src/resource_engine/calls.py +100 -0
  49. resource_engine-0.1.0/src/resource_engine/capabilities.py +145 -0
  50. resource_engine-0.1.0/src/resource_engine/composite.py +295 -0
  51. resource_engine-0.1.0/src/resource_engine/documents/__init__.py +69 -0
  52. resource_engine-0.1.0/src/resource_engine/documents/content.py +57 -0
  53. resource_engine-0.1.0/src/resource_engine/documents/events.py +49 -0
  54. resource_engine-0.1.0/src/resource_engine/documents/janitor.py +93 -0
  55. resource_engine-0.1.0/src/resource_engine/documents/machine.py +38 -0
  56. resource_engine-0.1.0/src/resource_engine/documents/manager.py +704 -0
  57. resource_engine-0.1.0/src/resource_engine/documents/model.py +91 -0
  58. resource_engine-0.1.0/src/resource_engine/documents/pipeline.py +98 -0
  59. resource_engine-0.1.0/src/resource_engine/documents/processors.py +320 -0
  60. resource_engine-0.1.0/src/resource_engine/documents/resource.py +39 -0
  61. resource_engine-0.1.0/src/resource_engine/domain/__init__.py +10 -0
  62. resource_engine-0.1.0/src/resource_engine/domain/events.py +50 -0
  63. resource_engine-0.1.0/src/resource_engine/domain/exceptions.py +23 -0
  64. resource_engine-0.1.0/src/resource_engine/email.py +417 -0
  65. resource_engine-0.1.0/src/resource_engine/errors.py +562 -0
  66. resource_engine-0.1.0/src/resource_engine/explorer.py +133 -0
  67. resource_engine-0.1.0/src/resource_engine/exports.py +687 -0
  68. resource_engine-0.1.0/src/resource_engine/generation.py +233 -0
  69. resource_engine-0.1.0/src/resource_engine/i18n.py +251 -0
  70. resource_engine-0.1.0/src/resource_engine/identity.py +46 -0
  71. resource_engine-0.1.0/src/resource_engine/integration.py +80 -0
  72. resource_engine-0.1.0/src/resource_engine/jobs.py +390 -0
  73. resource_engine-0.1.0/src/resource_engine/locale/ca/LC_MESSAGES/resource_engine.mo +0 -0
  74. resource_engine-0.1.0/src/resource_engine/locale/ca/LC_MESSAGES/resource_engine.po +206 -0
  75. resource_engine-0.1.0/src/resource_engine/locale/es/LC_MESSAGES/resource_engine.mo +0 -0
  76. resource_engine-0.1.0/src/resource_engine/locale/es/LC_MESSAGES/resource_engine.po +206 -0
  77. resource_engine-0.1.0/src/resource_engine/logs.py +201 -0
  78. resource_engine-0.1.0/src/resource_engine/messaging/__init__.py +73 -0
  79. resource_engine-0.1.0/src/resource_engine/messaging/asyncapi.py +529 -0
  80. resource_engine-0.1.0/src/resource_engine/messaging/cloudevents.py +98 -0
  81. resource_engine-0.1.0/src/resource_engine/messaging/consumer.py +165 -0
  82. resource_engine-0.1.0/src/resource_engine/messaging/delivery.py +115 -0
  83. resource_engine-0.1.0/src/resource_engine/messaging/envelope.py +193 -0
  84. resource_engine-0.1.0/src/resource_engine/messaging/hub.py +148 -0
  85. resource_engine-0.1.0/src/resource_engine/messaging/inbound.py +76 -0
  86. resource_engine-0.1.0/src/resource_engine/messaging/inspection.py +113 -0
  87. resource_engine-0.1.0/src/resource_engine/messaging/janitor.py +136 -0
  88. resource_engine-0.1.0/src/resource_engine/messaging/live.py +179 -0
  89. resource_engine-0.1.0/src/resource_engine/messaging/processing.py +357 -0
  90. resource_engine-0.1.0/src/resource_engine/messaging/publishing.py +318 -0
  91. resource_engine-0.1.0/src/resource_engine/messaging/relay.py +84 -0
  92. resource_engine-0.1.0/src/resource_engine/messaging/worker.py +166 -0
  93. resource_engine-0.1.0/src/resource_engine/nosql.py +394 -0
  94. resource_engine-0.1.0/src/resource_engine/ports/__init__.py +13 -0
  95. resource_engine-0.1.0/src/resource_engine/ports/activity.py +171 -0
  96. resource_engine-0.1.0/src/resource_engine/ports/audit.py +42 -0
  97. resource_engine-0.1.0/src/resource_engine/ports/authz.py +132 -0
  98. resource_engine-0.1.0/src/resource_engine/ports/cache.py +41 -0
  99. resource_engine-0.1.0/src/resource_engine/ports/email.py +118 -0
  100. resource_engine-0.1.0/src/resource_engine/ports/event_publisher.py +34 -0
  101. resource_engine-0.1.0/src/resource_engine/ports/idempotency.py +69 -0
  102. resource_engine-0.1.0/src/resource_engine/ports/identity.py +112 -0
  103. resource_engine-0.1.0/src/resource_engine/ports/locks.py +28 -0
  104. resource_engine-0.1.0/src/resource_engine/ports/messaging.py +197 -0
  105. resource_engine-0.1.0/src/resource_engine/ports/observability.py +60 -0
  106. resource_engine-0.1.0/src/resource_engine/ports/ratelimit.py +59 -0
  107. resource_engine-0.1.0/src/resource_engine/ports/repository.py +56 -0
  108. resource_engine-0.1.0/src/resource_engine/ports/storage.py +93 -0
  109. resource_engine-0.1.0/src/resource_engine/ports/templates.py +54 -0
  110. resource_engine-0.1.0/src/resource_engine/ports/tracing.py +61 -0
  111. resource_engine-0.1.0/src/resource_engine/ports/unit_of_work.py +46 -0
  112. resource_engine-0.1.0/src/resource_engine/processes.py +408 -0
  113. resource_engine-0.1.0/src/resource_engine/py.typed +0 -0
  114. resource_engine-0.1.0/src/resource_engine/querying.py +319 -0
  115. resource_engine-0.1.0/src/resource_engine/ratelimit.py +217 -0
  116. resource_engine-0.1.0/src/resource_engine/reporting.py +230 -0
  117. resource_engine-0.1.0/src/resource_engine/schema_examples.py +51 -0
  118. resource_engine-0.1.0/src/resource_engine/templates.py +143 -0
  119. resource_engine-0.1.0/src/resource_engine/tenancy.py +68 -0
  120. resource_engine-0.1.0/src/resource_engine/testing/__init__.py +34 -0
  121. resource_engine-0.1.0/src/resource_engine/testing/activity.py +123 -0
  122. resource_engine-0.1.0/src/resource_engine/testing/contracts.py +1416 -0
  123. resource_engine-0.1.0/src/resource_engine/testing/email.py +36 -0
  124. resource_engine-0.1.0/src/resource_engine/testing/engine.py +40 -0
  125. resource_engine-0.1.0/src/resource_engine/testing/memory.py +603 -0
  126. resource_engine-0.1.0/src/resource_engine/testing/storage.py +110 -0
  127. resource_engine-0.1.0/src/resource_engine/testing/tracing.py +100 -0
  128. resource_engine-0.1.0/src/resource_engine/tracing.py +156 -0
  129. resource_engine-0.1.0/src/resource_engine/translatable.py +80 -0
  130. resource_engine-0.1.0/src/resource_engine/versions.py +189 -0
  131. resource_engine-0.1.0/tests/test_api_keys.py +166 -0
  132. resource_engine-0.1.0/tests/test_asyncapi.py +288 -0
  133. resource_engine-0.1.0/tests/test_audit.py +253 -0
  134. resource_engine-0.1.0/tests/test_audit_export.py +285 -0
  135. resource_engine-0.1.0/tests/test_audit_seal.py +180 -0
  136. resource_engine-0.1.0/tests/test_authz.py +634 -0
  137. resource_engine-0.1.0/tests/test_caching.py +92 -0
  138. resource_engine-0.1.0/tests/test_capabilities.py +168 -0
  139. resource_engine-0.1.0/tests/test_composite.py +208 -0
  140. resource_engine-0.1.0/tests/test_concurrency.py +234 -0
  141. resource_engine-0.1.0/tests/test_consumers.py +175 -0
  142. resource_engine-0.1.0/tests/test_declarations.py +325 -0
  143. resource_engine-0.1.0/tests/test_definitions.py +123 -0
  144. resource_engine-0.1.0/tests/test_document_processors.py +126 -0
  145. resource_engine-0.1.0/tests/test_documents.py +329 -0
  146. resource_engine-0.1.0/tests/test_email.py +217 -0
  147. resource_engine-0.1.0/tests/test_email_suppressions.py +35 -0
  148. resource_engine-0.1.0/tests/test_engine_authorizer.py +147 -0
  149. resource_engine-0.1.0/tests/test_exactly_once.py +169 -0
  150. resource_engine-0.1.0/tests/test_explorer_events.py +368 -0
  151. resource_engine-0.1.0/tests/test_explorer_jobs.py +140 -0
  152. resource_engine-0.1.0/tests/test_explorer_publish.py +225 -0
  153. resource_engine-0.1.0/tests/test_export_jobs.py +292 -0
  154. resource_engine-0.1.0/tests/test_exports.py +187 -0
  155. resource_engine-0.1.0/tests/test_history.py +162 -0
  156. resource_engine-0.1.0/tests/test_i18n.py +96 -0
  157. resource_engine-0.1.0/tests/test_idempotency.py +227 -0
  158. resource_engine-0.1.0/tests/test_jobs.py +165 -0
  159. resource_engine-0.1.0/tests/test_machines.py +208 -0
  160. resource_engine-0.1.0/tests/test_messaging.py +176 -0
  161. resource_engine-0.1.0/tests/test_messaging_janitor.py +66 -0
  162. resource_engine-0.1.0/tests/test_observability.py +264 -0
  163. resource_engine-0.1.0/tests/test_polymorphism.py +330 -0
  164. resource_engine-0.1.0/tests/test_processes.py +244 -0
  165. resource_engine-0.1.0/tests/test_querying.py +190 -0
  166. resource_engine-0.1.0/tests/test_ratelimit.py +103 -0
  167. resource_engine-0.1.0/tests/test_relationships.py +556 -0
  168. resource_engine-0.1.0/tests/test_reporting.py +151 -0
  169. resource_engine-0.1.0/tests/test_searching.py +210 -0
  170. resource_engine-0.1.0/tests/test_storage.py +15 -0
  171. resource_engine-0.1.0/tests/test_tenancy.py +239 -0
  172. resource_engine-0.1.0/tests/test_timers.py +233 -0
  173. resource_engine-0.1.0/tests/test_tracing.py +131 -0
  174. resource_engine-0.1.0/tests/test_transaction.py +143 -0
  175. resource_engine-0.1.0/tests/test_translatable.py +125 -0
  176. resource_engine-0.1.0/tests/test_versions_contract_memory.py +11 -0
  177. resource_engine-0.1.0/tests/test_views.py +199 -0
@@ -0,0 +1,18 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ dist/
7
+ build/
8
+ *.egg-info/
9
+ *.db
10
+ site/
11
+ .emulators/
12
+
13
+ # Local notes, not committed
14
+ reviews/
15
+ .coverage
16
+ .coverage.*
17
+ htmlcov/
18
+ python-coverage-comment-action.txt
@@ -0,0 +1,16 @@
1
+ # Changelog: resource-engine
2
+
3
+ Notable changes to this package, newest first. Versions follow
4
+ [semantic versioning](https://semver.org) with the project's
5
+ [stability rules](https://github.com/EloiSans/python-resource-engine/blob/main/docs/stability.md).
6
+
7
+ ## Unreleased
8
+
9
+ ## 0.1.0 (2026-12-05)
10
+
11
+ First release.
12
+
13
+ - Core: `Resource`, registry, hooks, `ResourceManager`, documents, messaging, ports, in-memory adapters
14
+ - The public API is defined ([stability](https://github.com/EloiSans/python-resource-engine/blob/main/docs/stability.md#public-api)): every public module has an `__all__`, and `resource_engine.integration` gathers what the packages built on the engine need from its internals
15
+ - `ResourceManager.run_action(resource, entity_id, action, data)` takes the record id before the action, like `transition` (`None` for a collection action); `rate_limiter`, `cache` and `generator` are typed, and so are `Resource.view`, `api_versions`, `deprecation` and `printouts`
16
+ - Search and filter operators on lists: `Listing(searchable=[...])` and `ListQuery(search=...)`, `field[gte]`-style filters, the `icontains` condition operator
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,36 @@
1
+ Metadata-Version: 2.5
2
+ Name: resource-engine
3
+ Version: 0.1.0
4
+ Summary: Declarative resource engine for business backends: resources, lifecycle hooks, state machines, ports.
5
+ Project-URL: Homepage, https://github.com/EloiSans/python-resource-engine
6
+ Project-URL: Documentation, https://github.com/EloiSans/python-resource-engine/tree/main/docs
7
+ Project-URL: Source, https://github.com/EloiSans/python-resource-engine/tree/main/packages/resource-engine
8
+ Project-URL: Issues, https://github.com/EloiSans/python-resource-engine/issues
9
+ Project-URL: Changelog, https://github.com/EloiSans/python-resource-engine/blob/main/packages/resource-engine/CHANGELOG.md
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Framework :: AsyncIO
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.12
23
+ Requires-Dist: pydantic>=2.7
24
+ Requires-Dist: python-statemachine>=3.0
25
+ Provides-Extra: testing
26
+ Requires-Dist: pytest-asyncio>=0.24; extra == 'testing'
27
+ Requires-Dist: pytest>=8; extra == 'testing'
28
+ Provides-Extra: xlsx
29
+ Requires-Dist: openpyxl>=3.1; extra == 'xlsx'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # resource-engine
33
+
34
+ Core of Resource Engine: declarative resources, lifecycle hooks, state machines, actions and ports. No web or database dependencies.
35
+
36
+ Part of [Resource Engine](../../README.md).
@@ -0,0 +1,5 @@
1
+ # resource-engine
2
+
3
+ Core of Resource Engine: declarative resources, lifecycle hooks, state machines, actions and ports. No web or database dependencies.
4
+
5
+ Part of [Resource Engine](../../README.md).
@@ -0,0 +1,39 @@
1
+ [project]
2
+ name = "resource-engine"
3
+ version = "0.1.0"
4
+ description = "Declarative resource engine for business backends: resources, lifecycle hooks, state machines, ports."
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ license = "Apache-2.0"
8
+ license-files = ["LICENSE"]
9
+ classifiers = [
10
+ "Development Status :: 3 - Alpha",
11
+ "Framework :: AsyncIO",
12
+ "Intended Audience :: Developers",
13
+ "Operating System :: OS Independent",
14
+ "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3.12",
16
+ "Programming Language :: Python :: 3.13",
17
+ "Programming Language :: Python :: 3.14",
18
+ "Topic :: Software Development :: Libraries :: Application Frameworks",
19
+ "Typing :: Typed",
20
+ ]
21
+ dependencies = ["pydantic>=2.7", "python-statemachine>=3.0"]
22
+
23
+ [project.optional-dependencies]
24
+ testing = ["pytest>=8", "pytest-asyncio>=0.24"]
25
+ xlsx = ["openpyxl>=3.1"]
26
+
27
+ [project.urls]
28
+ Homepage = "https://github.com/EloiSans/python-resource-engine"
29
+ Documentation = "https://github.com/EloiSans/python-resource-engine/tree/main/docs"
30
+ Source = "https://github.com/EloiSans/python-resource-engine/tree/main/packages/resource-engine"
31
+ Issues = "https://github.com/EloiSans/python-resource-engine/issues"
32
+ Changelog = "https://github.com/EloiSans/python-resource-engine/blob/main/packages/resource-engine/CHANGELOG.md"
33
+
34
+ [build-system]
35
+ requires = ["hatchling>=1.27"]
36
+ build-backend = "hatchling.build"
37
+
38
+ [tool.hatch.build.targets.wheel]
39
+ packages = ["src/resource_engine"]
@@ -0,0 +1,96 @@
1
+ """Resource Engine: declarative resources for business backends.
2
+
3
+ Import from here, or from the public modules docs/stability.md lists (the
4
+ first-level ones, such as ``resource_engine.messaging``). Deeper modules, and
5
+ ``resource_engine.application``, are internal and can change in any release.
6
+ """
7
+
8
+ from resource_engine.application.actions import Action
9
+ from resource_engine.application.context import OperationContext
10
+ from resource_engine.application.events import (
11
+ ActionExecuted,
12
+ ResourceCreated,
13
+ ResourceDeleted,
14
+ ResourceEvent,
15
+ ResourceUpdated,
16
+ TransitionExecuted,
17
+ )
18
+ from resource_engine.application.hooks import HookPoint, external_effect, hook
19
+ from resource_engine.application.idempotency import IdempotencyJanitor
20
+ from resource_engine.application.manager import ResourceManager
21
+ from resource_engine.application.query import ListQuery, Page
22
+ from resource_engine.application.registry import ResourceRegistry
23
+ from resource_engine.application.relations import Link, Reference
24
+ from resource_engine.application.resource import (
25
+ CRUD,
26
+ CRUD_OPERATIONS,
27
+ ActionDefinition,
28
+ Resource,
29
+ ResourceDefinition,
30
+ )
31
+ from resource_engine.application.settings import (
32
+ Access,
33
+ Audited,
34
+ Cached,
35
+ Internal,
36
+ Listing,
37
+ Subtype,
38
+ Translatable,
39
+ Versioned,
40
+ )
41
+ from resource_engine.application.slots import DocumentSlot
42
+ from resource_engine.application.state_machines import Machine, describe_machine
43
+ from resource_engine.application.timers import Timer, TimerJob
44
+ from resource_engine.application.views import Aggregate, Avg, Count, Max, Min, Sum
45
+ from resource_engine.domain import DomainError, DomainEvent
46
+ from resource_engine.errors import ResourceEngineError
47
+
48
+ __version__ = "0.1.0"
49
+
50
+ __all__ = [
51
+ "CRUD",
52
+ "CRUD_OPERATIONS",
53
+ "Access",
54
+ "Action",
55
+ "ActionDefinition",
56
+ "ActionExecuted",
57
+ "Aggregate",
58
+ "Audited",
59
+ "Avg",
60
+ "Cached",
61
+ "Count",
62
+ "DocumentSlot",
63
+ "DomainError",
64
+ "DomainEvent",
65
+ "HookPoint",
66
+ "IdempotencyJanitor",
67
+ "Internal",
68
+ "Link",
69
+ "ListQuery",
70
+ "Listing",
71
+ "Machine",
72
+ "Max",
73
+ "Min",
74
+ "OperationContext",
75
+ "Page",
76
+ "Reference",
77
+ "Resource",
78
+ "ResourceCreated",
79
+ "ResourceDefinition",
80
+ "ResourceDeleted",
81
+ "ResourceEngineError",
82
+ "ResourceEvent",
83
+ "ResourceManager",
84
+ "ResourceRegistry",
85
+ "ResourceUpdated",
86
+ "Subtype",
87
+ "Sum",
88
+ "Timer",
89
+ "TimerJob",
90
+ "TransitionExecuted",
91
+ "Translatable",
92
+ "Versioned",
93
+ "describe_machine",
94
+ "external_effect",
95
+ "hook",
96
+ ]
@@ -0,0 +1 @@
1
+ """Application layer: resource definitions, lifecycle and orchestration."""
@@ -0,0 +1,48 @@
1
+ """Business actions (use cases) attached to a resource."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ from typing import TYPE_CHECKING, Any, ClassVar
7
+
8
+ from pydantic import BaseModel
9
+
10
+ if TYPE_CHECKING:
11
+ from resource_engine.application.context import OperationContext
12
+
13
+
14
+ def _snake(name: str) -> str:
15
+ return re.sub(r"(?<!^)(?=[A-Z])", "_", name).lower()
16
+
17
+
18
+ class Action:
19
+ """A business operation that is neither CRUD nor a plain state transition.
20
+
21
+ Subclass it, document it with a docstring and implement ``execute``. The engine
22
+ validates the input, opens the unit of work, loads the entity (for instance
23
+ actions), runs ``before_action`` / ``after_action`` hooks, commits and publishes
24
+ events. ``execute`` may be sync or async.
25
+
26
+ Class attributes:
27
+ name: Public name (defaults to the snake_case class name).
28
+ input_schema: Pydantic model for the input, or ``None``.
29
+ output_schema: Pydantic model for the result. If ``None`` the resource's
30
+ ``read`` schema is used for instance actions returning the entity.
31
+ instance: ``True`` if the action targets one entity (``/{id}/actions/x``),
32
+ ``False`` for collection-level actions (``/actions/x``).
33
+ """
34
+
35
+ name: ClassVar[str | None] = None
36
+ input_schema: ClassVar[type[BaseModel] | None] = None
37
+ output_schema: ClassVar[type[BaseModel] | None] = None
38
+ instance: ClassVar[bool] = True
39
+
40
+ @classmethod
41
+ def action_name(cls) -> str:
42
+ """The action's name: ``name``, or the class name in snake case."""
43
+ return cls.name or _snake(cls.__name__)
44
+
45
+ def execute(self, ctx: OperationContext) -> Any: # pragma: no cover - abstract
46
+ """Run the action. ``ctx.entity`` is the record (``None`` for collection actions); the
47
+ return value is the response."""
48
+ raise NotImplementedError
@@ -0,0 +1,111 @@
1
+ """The context every operation carries through its hooks: the resource, the actor, the data, the
2
+ entity and what the operation produced."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import uuid
7
+ from collections.abc import Awaitable, Callable, Mapping
8
+ from dataclasses import dataclass, field
9
+ from typing import TYPE_CHECKING, Any
10
+
11
+ from resource_engine.domain.events import DomainEvent
12
+
13
+ if TYPE_CHECKING:
14
+ from resource_engine.application.resource import ResourceDefinition
15
+ from resource_engine.ports.repository import Repository
16
+ from resource_engine.ports.unit_of_work import UnitOfWork
17
+
18
+
19
+ type Callback = Callable[[], Awaitable[Any] | Any] # results are ignored
20
+
21
+
22
+ @dataclass(kw_only=True)
23
+ class OperationContext:
24
+ """Everything a hook, state-machine bridge or action can see about an operation.
25
+
26
+ Attributes:
27
+ resource: Definition of the resource being operated on.
28
+ operation: ``list``, ``get``, ``create``, ``update``, ``delete``,
29
+ ``transition`` or ``action``.
30
+ transition: Event name when ``operation == "transition"``.
31
+ action: Action name when ``operation == "action"``.
32
+ slot: Document slot for ``attach`` / ``detach`` operations.
33
+ actor: The caller (a ``Principal``, ``system_principal(...)`` for engine
34
+ jobs, or ``None``), provided by the entry adapter.
35
+ raw_input: Input as received, before validation (mutable in ``before_validate``).
36
+ data: Validated input (a Pydantic model instance), or ``None``.
37
+ entity_id: Identifier of the target entity, when there is one.
38
+ entity: The loaded or newly built entity.
39
+ previous_state / new_state: State values around a transition.
40
+ uow: Active unit of work (``None`` outside the transaction).
41
+ events: Events recorded so far; published after commit.
42
+ result: Value returned to the caller (set before commit).
43
+ correlation_id: Identifier shared by logs and events of this operation.
44
+ extras: Free-form storage for hooks to share data.
45
+ documents: Attach/detach documents inside this transaction (``None`` when
46
+ the manager has no blob store).
47
+ decision: The last authorization ``Decision`` for this operation.
48
+ tenant: Tenant the operation is confined to (tenant-scoped resources);
49
+ ``None`` for cross-tenant callers acting on all tenants.
50
+ """
51
+
52
+ resource: ResourceDefinition
53
+ operation: str
54
+ transition: str | None = None
55
+ action: str | None = None
56
+ slot: str | None = None
57
+ actor: Any = None
58
+ raw_input: Any = None
59
+ data: Any = None
60
+ entity_id: Any = None
61
+ entity: Any = None
62
+ previous_state: Any = None
63
+ new_state: Any = None
64
+ uow: UnitOfWork | None = None
65
+ events: list[DomainEvent] = field(default_factory=list)
66
+ result: Any = None
67
+ correlation_id: str = field(default_factory=lambda: uuid.uuid4().hex)
68
+ services: Mapping[str, Any] = field(default_factory=dict)
69
+ extras: dict[str, Any] = field(default_factory=dict)
70
+ documents: Any = None
71
+ decision: Any = None
72
+ tenant: str | None = None
73
+ _tenant_scope: Any = field(default=None, repr=False)
74
+ _on_rollback: list[Callback] = field(default_factory=list, repr=False)
75
+ _on_commit: list[Callback] = field(default_factory=list, repr=False)
76
+
77
+ def on_rollback(self, callback: Callback) -> None:
78
+ """Register a compensation for a *staged effect*.
79
+
80
+ Use it for writes outside the database that nothing references until the
81
+ commit (a stored blob, a remote record with a delete call). If the
82
+ operation fails, callbacks run in reverse order, best effort: errors are
83
+ logged. A crash can skip them, so pair them with a cleanup job.
84
+ """
85
+ self._on_rollback.append(callback)
86
+
87
+ def on_commit(self, callback: Callback) -> None:
88
+ """Run ``callback`` after a successful commit, before ``after_commit`` hooks.
89
+
90
+ For deferred clean-ups (e.g. deleting a detached blob). Errors are logged.
91
+ """
92
+ self._on_commit.append(callback)
93
+
94
+ def record_event(self, event: DomainEvent) -> None:
95
+ """Queue an event; it is published only if the transaction commits."""
96
+ self.events.append(event)
97
+
98
+ def repository(self, resource_name: str | None = None) -> Repository[Any]:
99
+ """Repository of this (or another) resource inside the current transaction."""
100
+ if self.uow is None:
101
+ raise RuntimeError("No unit of work is active at this point of the lifecycle")
102
+ return self.uow.repository(resource_name or self.resource.name)
103
+
104
+ def service(self, name: str) -> Any:
105
+ """Look up a service registered on the ResourceManager (e.g. a mail gateway port)."""
106
+ try:
107
+ return self.services[name]
108
+ except KeyError:
109
+ raise KeyError(
110
+ f"Service {name!r} is not registered; pass it to ResourceManager(services=...)"
111
+ ) from None
@@ -0,0 +1,54 @@
1
+ """Lifecycle events emitted by the engine itself."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+ from typing import Any
7
+
8
+ from resource_engine.domain.events import DomainEvent
9
+
10
+
11
+ @dataclass(frozen=True, kw_only=True)
12
+ class ResourceEvent(DomainEvent):
13
+ """Base of the events the manager publishes about a record of a resource."""
14
+
15
+ resource: str
16
+ entity_id: Any
17
+
18
+
19
+ @dataclass(frozen=True, kw_only=True)
20
+ class ResourceCreated(ResourceEvent):
21
+ """A record was created."""
22
+
23
+ pass
24
+
25
+
26
+ @dataclass(frozen=True, kw_only=True)
27
+ class ResourceUpdated(ResourceEvent):
28
+ """A record was updated; ``changes`` maps each changed field to ``(before, after)``."""
29
+
30
+ changes: dict[str, tuple[Any, Any]] = field(default_factory=dict)
31
+
32
+
33
+ @dataclass(frozen=True, kw_only=True)
34
+ class ResourceDeleted(ResourceEvent):
35
+ """A record was deleted."""
36
+
37
+ pass
38
+
39
+
40
+ @dataclass(frozen=True, kw_only=True)
41
+ class TransitionExecuted(ResourceEvent):
42
+ """A state machine moved a record from ``source`` to ``target`` with ``transition``."""
43
+
44
+ transition: str
45
+ source: Any
46
+ target: Any
47
+ machine: str | None = None # which of the resource's machines (its name)
48
+
49
+
50
+ @dataclass(frozen=True, kw_only=True)
51
+ class ActionExecuted(ResourceEvent):
52
+ """An action ran on a record (instance actions) or on the resource."""
53
+
54
+ action: str