tigrbl 0.0.1.dev1__py3-none-any.whl → 0.3.0.dev3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. tigrbl/README.md +94 -0
  2. tigrbl/__init__.py +139 -14
  3. tigrbl/api/__init__.py +6 -0
  4. tigrbl/api/_api.py +72 -0
  5. tigrbl/api/api_spec.py +30 -0
  6. tigrbl/api/mro_collect.py +43 -0
  7. tigrbl/api/shortcuts.py +56 -0
  8. tigrbl/api/tigrbl_api.py +286 -0
  9. tigrbl/app/__init__.py +0 -0
  10. tigrbl/app/_app.py +61 -0
  11. tigrbl/app/app_spec.py +42 -0
  12. tigrbl/app/mro_collect.py +67 -0
  13. tigrbl/app/shortcuts.py +65 -0
  14. tigrbl/app/tigrbl_app.py +314 -0
  15. tigrbl/bindings/__init__.py +73 -0
  16. tigrbl/bindings/api/__init__.py +12 -0
  17. tigrbl/bindings/api/common.py +109 -0
  18. tigrbl/bindings/api/include.py +256 -0
  19. tigrbl/bindings/api/resource_proxy.py +149 -0
  20. tigrbl/bindings/api/rpc.py +111 -0
  21. tigrbl/bindings/columns.py +49 -0
  22. tigrbl/bindings/handlers/__init__.py +11 -0
  23. tigrbl/bindings/handlers/builder.py +119 -0
  24. tigrbl/bindings/handlers/ctx.py +74 -0
  25. tigrbl/bindings/handlers/identifiers.py +228 -0
  26. tigrbl/bindings/handlers/namespaces.py +51 -0
  27. tigrbl/bindings/handlers/steps.py +276 -0
  28. tigrbl/bindings/hooks.py +311 -0
  29. tigrbl/bindings/model.py +194 -0
  30. tigrbl/bindings/model_helpers.py +139 -0
  31. tigrbl/bindings/model_registry.py +77 -0
  32. tigrbl/bindings/rest/__init__.py +7 -0
  33. tigrbl/bindings/rest/attach.py +34 -0
  34. tigrbl/bindings/rest/collection.py +265 -0
  35. tigrbl/bindings/rest/common.py +116 -0
  36. tigrbl/bindings/rest/fastapi.py +76 -0
  37. tigrbl/bindings/rest/helpers.py +119 -0
  38. tigrbl/bindings/rest/io.py +317 -0
  39. tigrbl/bindings/rest/member.py +367 -0
  40. tigrbl/bindings/rest/router.py +292 -0
  41. tigrbl/bindings/rest/routing.py +133 -0
  42. tigrbl/bindings/rpc.py +364 -0
  43. tigrbl/bindings/schemas/__init__.py +11 -0
  44. tigrbl/bindings/schemas/builder.py +348 -0
  45. tigrbl/bindings/schemas/defaults.py +260 -0
  46. tigrbl/bindings/schemas/utils.py +193 -0
  47. tigrbl/column/README.md +62 -0
  48. tigrbl/column/__init__.py +72 -0
  49. tigrbl/column/_column.py +96 -0
  50. tigrbl/column/column_spec.py +40 -0
  51. tigrbl/column/field_spec.py +31 -0
  52. tigrbl/column/infer/__init__.py +25 -0
  53. tigrbl/column/infer/core.py +92 -0
  54. tigrbl/column/infer/jsonhints.py +44 -0
  55. tigrbl/column/infer/planning.py +133 -0
  56. tigrbl/column/infer/types.py +102 -0
  57. tigrbl/column/infer/utils.py +59 -0
  58. tigrbl/column/io_spec.py +133 -0
  59. tigrbl/column/mro_collect.py +59 -0
  60. tigrbl/column/shortcuts.py +89 -0
  61. tigrbl/column/storage_spec.py +65 -0
  62. tigrbl/config/__init__.py +19 -0
  63. tigrbl/config/constants.py +224 -0
  64. tigrbl/config/defaults.py +29 -0
  65. tigrbl/config/resolver.py +295 -0
  66. tigrbl/core/__init__.py +47 -0
  67. tigrbl/core/crud/__init__.py +36 -0
  68. tigrbl/core/crud/bulk.py +168 -0
  69. tigrbl/core/crud/helpers/__init__.py +76 -0
  70. tigrbl/core/crud/helpers/db.py +92 -0
  71. tigrbl/core/crud/helpers/enum.py +86 -0
  72. tigrbl/core/crud/helpers/filters.py +162 -0
  73. tigrbl/core/crud/helpers/model.py +123 -0
  74. tigrbl/core/crud/helpers/normalize.py +99 -0
  75. tigrbl/core/crud/ops.py +235 -0
  76. tigrbl/ddl/__init__.py +344 -0
  77. tigrbl/decorators.py +17 -0
  78. tigrbl/deps/__init__.py +20 -0
  79. tigrbl/deps/fastapi.py +45 -0
  80. tigrbl/deps/favicon.svg +4 -0
  81. tigrbl/deps/jinja.py +27 -0
  82. tigrbl/deps/pydantic.py +10 -0
  83. tigrbl/deps/sqlalchemy.py +94 -0
  84. tigrbl/deps/starlette.py +36 -0
  85. tigrbl/engine/__init__.py +26 -0
  86. tigrbl/engine/_engine.py +130 -0
  87. tigrbl/engine/bind.py +33 -0
  88. tigrbl/engine/builders.py +236 -0
  89. tigrbl/engine/collect.py +111 -0
  90. tigrbl/engine/decorators.py +108 -0
  91. tigrbl/engine/engine_spec.py +261 -0
  92. tigrbl/engine/resolver.py +224 -0
  93. tigrbl/engine/shortcuts.py +216 -0
  94. tigrbl/hook/__init__.py +21 -0
  95. tigrbl/hook/_hook.py +22 -0
  96. tigrbl/hook/decorators.py +28 -0
  97. tigrbl/hook/hook_spec.py +24 -0
  98. tigrbl/hook/mro_collect.py +98 -0
  99. tigrbl/hook/shortcuts.py +44 -0
  100. tigrbl/hook/types.py +76 -0
  101. tigrbl/op/__init__.py +50 -0
  102. tigrbl/op/_op.py +31 -0
  103. tigrbl/op/canonical.py +31 -0
  104. tigrbl/op/collect.py +11 -0
  105. tigrbl/op/decorators.py +238 -0
  106. tigrbl/op/model_registry.py +301 -0
  107. tigrbl/op/mro_collect.py +99 -0
  108. tigrbl/op/resolver.py +216 -0
  109. tigrbl/op/types.py +136 -0
  110. tigrbl/orm/__init__.py +1 -0
  111. tigrbl/orm/mixins/_RowBound.py +83 -0
  112. tigrbl/orm/mixins/__init__.py +95 -0
  113. tigrbl/orm/mixins/bootstrappable.py +113 -0
  114. tigrbl/orm/mixins/bound.py +47 -0
  115. tigrbl/orm/mixins/edges.py +40 -0
  116. tigrbl/orm/mixins/fields.py +165 -0
  117. tigrbl/orm/mixins/hierarchy.py +54 -0
  118. tigrbl/orm/mixins/key_digest.py +44 -0
  119. tigrbl/orm/mixins/lifecycle.py +115 -0
  120. tigrbl/orm/mixins/locks.py +51 -0
  121. tigrbl/orm/mixins/markers.py +16 -0
  122. tigrbl/orm/mixins/operations.py +57 -0
  123. tigrbl/orm/mixins/ownable.py +337 -0
  124. tigrbl/orm/mixins/principals.py +98 -0
  125. tigrbl/orm/mixins/tenant_bound.py +301 -0
  126. tigrbl/orm/mixins/upsertable.py +111 -0
  127. tigrbl/orm/mixins/utils.py +49 -0
  128. tigrbl/orm/tables/__init__.py +72 -0
  129. tigrbl/orm/tables/_base.py +8 -0
  130. tigrbl/orm/tables/audit.py +56 -0
  131. tigrbl/orm/tables/client.py +25 -0
  132. tigrbl/orm/tables/group.py +29 -0
  133. tigrbl/orm/tables/org.py +30 -0
  134. tigrbl/orm/tables/rbac.py +76 -0
  135. tigrbl/orm/tables/status.py +106 -0
  136. tigrbl/orm/tables/tenant.py +22 -0
  137. tigrbl/orm/tables/user.py +39 -0
  138. tigrbl/response/README.md +34 -0
  139. tigrbl/response/__init__.py +33 -0
  140. tigrbl/response/bind.py +12 -0
  141. tigrbl/response/decorators.py +37 -0
  142. tigrbl/response/resolver.py +83 -0
  143. tigrbl/response/shortcuts.py +144 -0
  144. tigrbl/response/types.py +49 -0
  145. tigrbl/rest/__init__.py +27 -0
  146. tigrbl/runtime/README.md +129 -0
  147. tigrbl/runtime/__init__.py +20 -0
  148. tigrbl/runtime/atoms/__init__.py +102 -0
  149. tigrbl/runtime/atoms/emit/__init__.py +42 -0
  150. tigrbl/runtime/atoms/emit/paired_post.py +158 -0
  151. tigrbl/runtime/atoms/emit/paired_pre.py +106 -0
  152. tigrbl/runtime/atoms/emit/readtime_alias.py +120 -0
  153. tigrbl/runtime/atoms/out/__init__.py +38 -0
  154. tigrbl/runtime/atoms/out/masking.py +135 -0
  155. tigrbl/runtime/atoms/refresh/__init__.py +38 -0
  156. tigrbl/runtime/atoms/refresh/demand.py +130 -0
  157. tigrbl/runtime/atoms/resolve/__init__.py +40 -0
  158. tigrbl/runtime/atoms/resolve/assemble.py +167 -0
  159. tigrbl/runtime/atoms/resolve/paired_gen.py +147 -0
  160. tigrbl/runtime/atoms/response/__init__.py +17 -0
  161. tigrbl/runtime/atoms/response/negotiate.py +30 -0
  162. tigrbl/runtime/atoms/response/negotiation.py +43 -0
  163. tigrbl/runtime/atoms/response/render.py +36 -0
  164. tigrbl/runtime/atoms/response/renderer.py +116 -0
  165. tigrbl/runtime/atoms/response/template.py +44 -0
  166. tigrbl/runtime/atoms/response/templates.py +88 -0
  167. tigrbl/runtime/atoms/schema/__init__.py +40 -0
  168. tigrbl/runtime/atoms/schema/collect_in.py +21 -0
  169. tigrbl/runtime/atoms/schema/collect_out.py +21 -0
  170. tigrbl/runtime/atoms/storage/__init__.py +38 -0
  171. tigrbl/runtime/atoms/storage/to_stored.py +167 -0
  172. tigrbl/runtime/atoms/wire/__init__.py +45 -0
  173. tigrbl/runtime/atoms/wire/build_in.py +166 -0
  174. tigrbl/runtime/atoms/wire/build_out.py +87 -0
  175. tigrbl/runtime/atoms/wire/dump.py +206 -0
  176. tigrbl/runtime/atoms/wire/validate_in.py +227 -0
  177. tigrbl/runtime/context.py +206 -0
  178. tigrbl/runtime/errors/__init__.py +61 -0
  179. tigrbl/runtime/errors/converters.py +214 -0
  180. tigrbl/runtime/errors/exceptions.py +124 -0
  181. tigrbl/runtime/errors/mappings.py +71 -0
  182. tigrbl/runtime/errors/utils.py +150 -0
  183. tigrbl/runtime/events.py +209 -0
  184. tigrbl/runtime/executor/__init__.py +6 -0
  185. tigrbl/runtime/executor/guards.py +132 -0
  186. tigrbl/runtime/executor/helpers.py +88 -0
  187. tigrbl/runtime/executor/invoke.py +150 -0
  188. tigrbl/runtime/executor/types.py +84 -0
  189. tigrbl/runtime/kernel.py +628 -0
  190. tigrbl/runtime/labels.py +353 -0
  191. tigrbl/runtime/opview.py +87 -0
  192. tigrbl/runtime/ordering.py +256 -0
  193. tigrbl/runtime/system.py +279 -0
  194. tigrbl/runtime/trace.py +330 -0
  195. tigrbl/schema/__init__.py +38 -0
  196. tigrbl/schema/_schema.py +27 -0
  197. tigrbl/schema/builder/__init__.py +17 -0
  198. tigrbl/schema/builder/build_schema.py +209 -0
  199. tigrbl/schema/builder/cache.py +24 -0
  200. tigrbl/schema/builder/compat.py +16 -0
  201. tigrbl/schema/builder/extras.py +85 -0
  202. tigrbl/schema/builder/helpers.py +51 -0
  203. tigrbl/schema/builder/list_params.py +117 -0
  204. tigrbl/schema/builder/strip_parent_fields.py +70 -0
  205. tigrbl/schema/collect.py +55 -0
  206. tigrbl/schema/decorators.py +68 -0
  207. tigrbl/schema/get_schema.py +86 -0
  208. tigrbl/schema/schema_spec.py +20 -0
  209. tigrbl/schema/shortcuts.py +42 -0
  210. tigrbl/schema/types.py +34 -0
  211. tigrbl/schema/utils.py +143 -0
  212. tigrbl/shortcuts.py +22 -0
  213. tigrbl/specs.py +44 -0
  214. tigrbl/system/__init__.py +12 -0
  215. tigrbl/system/diagnostics/__init__.py +24 -0
  216. tigrbl/system/diagnostics/compat.py +31 -0
  217. tigrbl/system/diagnostics/healthz.py +41 -0
  218. tigrbl/system/diagnostics/hookz.py +51 -0
  219. tigrbl/system/diagnostics/kernelz.py +20 -0
  220. tigrbl/system/diagnostics/methodz.py +43 -0
  221. tigrbl/system/diagnostics/router.py +73 -0
  222. tigrbl/system/diagnostics/utils.py +43 -0
  223. tigrbl/table/__init__.py +9 -0
  224. tigrbl/table/_base.py +237 -0
  225. tigrbl/table/_table.py +54 -0
  226. tigrbl/table/mro_collect.py +69 -0
  227. tigrbl/table/shortcuts.py +57 -0
  228. tigrbl/table/table_spec.py +28 -0
  229. tigrbl/transport/__init__.py +74 -0
  230. tigrbl/transport/jsonrpc/__init__.py +19 -0
  231. tigrbl/transport/jsonrpc/dispatcher.py +352 -0
  232. tigrbl/transport/jsonrpc/helpers.py +115 -0
  233. tigrbl/transport/jsonrpc/models.py +41 -0
  234. tigrbl/transport/rest/__init__.py +25 -0
  235. tigrbl/transport/rest/aggregator.py +132 -0
  236. tigrbl/types/__init__.py +174 -0
  237. tigrbl/types/allow_anon_provider.py +19 -0
  238. tigrbl/types/authn_abc.py +30 -0
  239. tigrbl/types/nested_path_provider.py +22 -0
  240. tigrbl/types/op.py +35 -0
  241. tigrbl/types/op_config_provider.py +17 -0
  242. tigrbl/types/op_verb_alias_provider.py +33 -0
  243. tigrbl/types/request_extras_provider.py +22 -0
  244. tigrbl/types/response_extras_provider.py +22 -0
  245. tigrbl/types/table_config_provider.py +13 -0
  246. tigrbl-0.3.0.dev3.dist-info/LICENSE +201 -0
  247. tigrbl-0.3.0.dev3.dist-info/METADATA +501 -0
  248. tigrbl-0.3.0.dev3.dist-info/RECORD +249 -0
  249. tigrbl/ExampleAgent.py +0 -1
  250. tigrbl-0.0.1.dev1.dist-info/METADATA +0 -18
  251. tigrbl-0.0.1.dev1.dist-info/RECORD +0 -5
  252. {tigrbl-0.0.1.dev1.dist-info → tigrbl-0.3.0.dev3.dist-info}/WHEEL +0 -0
@@ -0,0 +1,501 @@
1
+ Metadata-Version: 2.3
2
+ Name: tigrbl
3
+ Version: 0.3.0.dev3
4
+ Summary: Automatic API generation tools by Swarmauri.
5
+ License: Apache-2.0
6
+ Author: Swarmauri Team
7
+ Author-email: team@swarmauri.com
8
+ Requires-Python: >=3.10,<3.13
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Provides-Extra: postgres
15
+ Provides-Extra: templates
16
+ Requires-Dist: aiosqlite (>=0.19.0)
17
+ Requires-Dist: asyncpg (>=0.30.0) ; extra == "postgres"
18
+ Requires-Dist: fastapi (>=0.100.0)
19
+ Requires-Dist: greenlet (>=3.2.3)
20
+ Requires-Dist: httpx (>=0.27.0)
21
+ Requires-Dist: jinja2 (>=3.1.4) ; extra == "templates"
22
+ Requires-Dist: psycopg2-binary (>=2.9.9) ; extra == "postgres"
23
+ Requires-Dist: pydantic (>=2.0.0)
24
+ Requires-Dist: sqlalchemy (>=2.0)
25
+ Requires-Dist: swarmauri_base
26
+ Requires-Dist: swarmauri_core
27
+ Requires-Dist: swarmauri_standard
28
+ Requires-Dist: uvicorn
29
+ Description-Content-Type: text/markdown
30
+
31
+ ![Tigrbl Logo](../../../assets/tigrbl_full_logo.png)
32
+
33
+ <p align="center">
34
+ <a href="https://pypi.org/project/tigrbl/">
35
+ <img src="https://img.shields.io/pypi/dm/tigrbl" alt="PyPI - Downloads"/></a>
36
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/tigrbl/">
37
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/tigrbl.svg"/></a>
38
+ <a href="https://pypi.org/project/tigrbl/">
39
+ <img src="https://img.shields.io/pypi/pyversions/tigrbl" alt="PyPI - Python Version"/></a>
40
+ <a href="https://pypi.org/project/tigrbl/">
41
+ <img src="https://img.shields.io/pypi/l/tigrbl" alt="PyPI - License"/></a>
42
+ <a href="https://pypi.org/project/tigrbl/">
43
+ <img src="https://img.shields.io/pypi/v/tigrbl?label=tigrbl&color=green" alt="PyPI - tigrbl"/></a>
44
+ </p>
45
+
46
+ ---
47
+
48
+ # Tigrbl 🐅🐂
49
+ A high-leverage meta-framework that turns plain SQLAlchemy models into a fully-featured REST+RPC surface with near-zero boilerplate. 🚀
50
+
51
+ ## Terminology 📚
52
+
53
+ - **Tenant** 🏢 – a namespace used to group related resources.
54
+ - **Principal** 👤 – an owner of resources, such as an individual user or an organization.
55
+ - **Resource** 📦 – a logical collection of data or functionality exposed by the API.
56
+ - **Engine** ⚙️ – the database connection and transaction manager backing a resource.
57
+ - **Model / Table** 🧱 – the ORM or database representation of a resource's records.
58
+ - **Column** 📏 – a field on a model that maps to a table column.
59
+ - **Operation** 🛠️ – a verb-driven action executed against a resource.
60
+ - **Hook** 🪝 – a callback that runs during a phase to customize behavior.
61
+ - **Phase** ⏱️ – a step in the request lifecycle where hooks may run.
62
+ - **Verb** 🔤 – the canonical name of an operation such as create or read.
63
+ - **Runtime** 🧠 – orchestrates phases and hooks while processing a request.
64
+ - **Kernel** 🧩 – the core dispatcher invoked by the runtime to handle operations.
65
+ - **Schema** 🧬 – the structured shape of request or response data.
66
+ - **Request** 📥 – inbound data and context provided to an operation.
67
+ - **Response** 📤 – outbound result returned after an operation completes.
68
+
69
+ ## Built-in Verbs 🧰
70
+
71
+ Tigrbl exposes a canonical set of operations that surface as both REST
72
+ and RPC endpoints. The table below summarizes the default REST routes,
73
+ RPC methods, arity, and the expected input and output shapes for each
74
+ verb. `{resource}` stands for the collection path and `{id}` is the
75
+ primary key placeholder.
76
+
77
+ | Verb | REST route | RPC method | Arity | Input type | Output type |
78
+ |------|------------|------------|-------|------------|-------------|
79
+ | `create` ➕ | `POST /{resource}` | `Model.create` | collection | dict | dict |
80
+ | `read` 🔍 | `GET /{resource}/{id}` | `Model.read` | member | – | dict |
81
+ | `update` ✏️ | `PATCH /{resource}/{id}` | `Model.update` | member | dict | dict |
82
+ | `replace` ♻️ | `PUT /{resource}/{id}` | `Model.replace` | member | dict | dict |
83
+ | `merge` 🧬 | `PATCH /{resource}/{id}` | `Model.merge` | member | dict | dict |
84
+ | `delete` 🗑️ | `DELETE /{resource}/{id}` | `Model.delete` | member | – | dict |
85
+ | `list` 📃 | `GET /{resource}` | `Model.list` | collection | dict | array |
86
+ | `clear` 🧹 | `DELETE /{resource}` | `Model.clear` | collection | dict | dict |
87
+ | `bulk_create` 📦➕ | `POST /{resource}` | `Model.bulk_create` | collection | array | array |
88
+ | `bulk_update` 📦✏️ | `PATCH /{resource}` | `Model.bulk_update` | collection | array | array |
89
+ | `bulk_replace` 📦♻️ | `PUT /{resource}` | `Model.bulk_replace` | collection | array | array |
90
+ | `bulk_merge` 📦🧬 | `PATCH /{resource}` | `Model.bulk_merge` | collection | array | array |
91
+ | `bulk_delete` 📦🗑️ | `DELETE /{resource}` | `Model.bulk_delete` | collection | dict | dict |
92
+ | `bulk_read` – | – | – | – | – | – |
93
+
94
+ ### Update, Merge, and Replace 🔄
95
+
96
+ `update` applies a shallow PATCH: only the supplied fields change and
97
+ missing fields are left untouched. `merge` performs a deep merge with
98
+ upsert semantics—if the target row is absent it is created, and nested
99
+ mapping fields are merged rather than replaced. `replace` follows PUT
100
+ semantics, overwriting the entire record and nulling any omitted
101
+ attributes.
102
+
103
+ ### Verb Overrides 🧭
104
+
105
+ Because `create` and `bulk_create` share the same collection `POST`
106
+ route, enabling `bulk_create` removes the REST `create` endpoint; the
107
+ `Model.create` RPC method remains available. Likewise, `bulk_delete`
108
+ supersedes `clear` by claiming the collection `DELETE` route. Only one
109
+ of each conflicting pair can be exposed at a time. Other verbs coexist
110
+ without conflict because they operate on distinct paths or HTTP
111
+ methods.
112
+
113
+ ## Phase Lifecycle ⛓️
114
+
115
+ Tigrbl operations execute through a fixed sequence of phases. Hook chains can
116
+ attach handlers at any phase to customize behavior or enforce policy.
117
+
118
+ | Phase | Description |
119
+ |-------|-------------|
120
+ | `PRE_TX_BEGIN` ⏳ | Pre-transaction checks before a database session is used. |
121
+ | `START_TX` 🚦 | Open a new transaction when one is not already active. |
122
+ | `PRE_HANDLER` 🧹 | Validate the request and prepare resources for the handler. |
123
+ | `HANDLER` ▶️ | Execute the core operation logic within the transaction. |
124
+ | `POST_HANDLER` 🔧 | Post-processing while still inside the transaction. |
125
+ | `PRE_COMMIT` ✅ | Final verification before committing; writes are frozen. |
126
+ | `END_TX` 🧾 | Commit and close the transaction. |
127
+ | `POST_COMMIT` 📌 | Steps that run after commit but before the response is returned. |
128
+ | `POST_RESPONSE` 📮 | Fire-and-forget work after the response has been sent. |
129
+ | `ON_ERROR` 🛑 | Fallback error handler when no phase-specific chain matches. |
130
+ | `ON_PRE_TX_BEGIN_ERROR` 🧯 | Handle errors raised during `PRE_TX_BEGIN`. |
131
+ | `ON_START_TX_ERROR` 🧯 | Handle errors raised during `START_TX`. |
132
+ | `ON_PRE_HANDLER_ERROR` 🧯 | Handle errors raised during `PRE_HANDLER`. |
133
+ | `ON_HANDLER_ERROR` 🧯 | Handle errors raised during `HANDLER`. |
134
+ | `ON_POST_HANDLER_ERROR` 🧯 | Handle errors raised during `POST_HANDLER`. |
135
+ | `ON_PRE_COMMIT_ERROR` 🧯 | Handle errors raised during `PRE_COMMIT`. |
136
+ | `ON_END_TX_ERROR` 🧯 | Handle errors raised during `END_TX`. |
137
+ | `ON_POST_COMMIT_ERROR` 🧯 | Handle errors raised during `POST_COMMIT`. |
138
+ | `ON_POST_RESPONSE_ERROR` 🧯 | Handle errors raised during `POST_RESPONSE`. |
139
+ | `ON_ROLLBACK` ↩️ | Run when the transaction rolls back to perform cleanup. |
140
+
141
+ ### Happy-path flow
142
+
143
+ ```
144
+
145
+ PRE\_TX\_BEGIN
146
+ |
147
+ START\_TX
148
+ |
149
+ PRE\_HANDLER
150
+ |
151
+ HANDLER
152
+ |
153
+ POST\_HANDLER
154
+ |
155
+ PRE\_COMMIT
156
+ |
157
+ END\_TX
158
+ |
159
+ POST\_COMMIT
160
+ |
161
+ POST\_RESPONSE
162
+
163
+ ```
164
+
165
+ If a phase raises an exception, control transfers to the matching
166
+ `ON_<PHASE>_ERROR` chain or falls back to `ON_ERROR`, with `ON_ROLLBACK`
167
+ executing when the transaction is rolled back.
168
+
169
+ ## Request → Response Flow Examples 🔀
170
+
171
+ ### REST example
172
+
173
+ ```
174
+
175
+ Client
176
+ |
177
+ v
178
+ HTTP Request
179
+ |
180
+ v
181
+ FastAPI Router
182
+ |
183
+ v
184
+ Tigrbl Runtime
185
+ |
186
+ v
187
+ Operation Handler
188
+ |
189
+ v
190
+ HTTP Response
191
+
192
+ ```
193
+
194
+ ### RPC example
195
+
196
+ ```
197
+
198
+ Client
199
+ |
200
+ v
201
+ JSON-RPC Request
202
+ |
203
+ v
204
+ RPC Dispatcher
205
+ |
206
+ v
207
+ Tigrbl Runtime
208
+ |
209
+ v
210
+ Operation Handler
211
+ |
212
+ v
213
+ JSON-RPC Response
214
+
215
+ ````
216
+
217
+ ## Hooks 🪝
218
+
219
+ Hooks allow you to plug custom logic into any phase of a verb. Use the
220
+ `hook_ctx` decorator to declare context-only hooks:
221
+
222
+ ```python
223
+ from tigrbl import Base, hook_ctx
224
+
225
+ class Item(Base):
226
+ __tablename__ = "items"
227
+
228
+ @hook_ctx(ops="create", phase="PRE_HANDLER")
229
+ async def validate(cls, ctx):
230
+ if ctx["request"].payload.get("name") == "bad":
231
+ raise ValueError("invalid name")
232
+ ````
233
+
234
+ The function runs during the `PRE_HANDLER` phase of `create`. The
235
+ `ctx` mapping provides request and response objects, a database session,
236
+ and values from earlier hooks.
237
+
238
+ Hooks can also be registered imperatively:
239
+
240
+ ```python
241
+ async def audit(ctx):
242
+ ...
243
+
244
+ class Item(Base):
245
+ __tigrbl_hooks__ = {"delete": {"POST_COMMIT": [audit]}}
246
+ ```
247
+
248
+ Running apps expose a `/system/hookz` route that lists all registered
249
+ hooks. 📋
250
+
251
+ ## Step Types 🧱
252
+
253
+ Tigrbl orders work into labeled steps that control how phases run:
254
+
255
+ * **secdeps** 🔐 – security dependencies executed before other checks. Downstream
256
+ applications declare these to enforce auth or policy.
257
+ * **deps** 🧩 – general dependencies resolved ahead of phase handlers. Downstream
258
+ code provides these to inject request context or resources.
259
+ * **sys** 🏗️ – system steps bundled with Tigrbl that drive core behavior.
260
+ Maintainers own these and downstream packages should not modify them.
261
+ * **atoms** ⚛️ – built-in runtime units such as schema collectors or wire
262
+ validators. These are maintained by the core team.
263
+ * **hooks** 🪝 – extension points that downstream packages register to customize
264
+ phase behavior.
265
+
266
+ Only `secdeps`, `deps`, and `hooks` are expected to be configured downstream;
267
+ `sys` and `atom` steps are maintained by the Tigrbl maintainers.
268
+
269
+ ## Kernelz Labeling 🔎
270
+
271
+ Running apps expose a `/system/kernelz` diagnostics endpoint that returns the
272
+ kernel's phase plan for each model and operation. Every entry is prefixed by
273
+ its phase and a descriptive label, for example:
274
+
275
+ ```
276
+ PRE_TX:secdep:myapp.auth.require_user
277
+ HANDLER:hook:wire:myapp.handlers.audit@HANDLER
278
+ END_TX:hook:sys:txn:commit@END_TX
279
+ POST_HANDLER:atom:wire:dump@POST_HANDLER
280
+ ```
281
+
282
+ The token after the phase identifies the step type:
283
+
284
+ * `secdep` and `dep` – security and general dependencies as
285
+ `PRE_TX:secdep:<callable>` and `PRE_TX:dep:<callable>`.
286
+ * `hook:sys` – built-in system hooks shipped with Tigrbl.
287
+ * `hook:wire` – default label for user hooks including module/function name + phase.
288
+ * `atom:{domain}:{subject}` – runtime atoms, e.g. `atom:wire:dump`.
289
+
290
+ These labels allow downstream services to inspect execution order and debug how
291
+ work is scheduled. 🧭
292
+
293
+ ## Configuration Overview ⚙️
294
+
295
+ ### Operation Config Precedence 🧮
296
+
297
+ When merging configuration for a given operation, Tigrbl layers settings in
298
+ increasing order of precedence:
299
+
300
+ 1. defaults
301
+ 2. app config
302
+ 3. API config
303
+ 4. table config
304
+ 5. column `.cfg` entries
305
+ 6. operation spec
306
+ 7. per-request overrides
307
+
308
+ Later entries override earlier ones, so request overrides win over all other
309
+ sources. This can be summarized as
310
+ `overrides > opspec > colspecs > tabspec > apispec > appspec > defaults`.
311
+
312
+ ### Schema Config Precedence 🧬
313
+
314
+ Tigrbl merges schema configuration from several scopes.
315
+ Later layers override earlier ones, with the precedence order:
316
+
317
+ 1. defaults (lowest)
318
+ 2. app configuration
319
+ 3. API configuration
320
+ 4. table configuration
321
+ 5. column-level `cfg` values
322
+ 6. op-specific `cfg`
323
+ 7. per-request overrides (highest)
324
+
325
+ This hierarchy ensures that the most specific settings always win. 🥇
326
+
327
+ ### Table-Level 🧾
328
+
329
+ * `__tigrbl_request_extras__` – verb-scoped virtual request fields.
330
+ * `__tigrbl_response_extras__` – verb-scoped virtual response fields.
331
+ * `__tigrbl_register_hooks__` – hook registration entry point.
332
+ * `__tigrbl_nested_paths__` – nested REST path segments.
333
+ * `__tigrbl_allow_anon__` – verbs permitted without auth.
334
+ * `__tigrbl_owner_policy__` / `__tigrbl_tenant_policy__` – server vs client field injection.
335
+ * `__tigrbl_verb_aliases__` & `__tigrbl_verb_alias_policy__` – custom verb names.
336
+
337
+ ### Routing 🧭
338
+
339
+ * `__tigrbl_nested_paths__` for hierarchical routing.
340
+ * `__tigrbl_verb_aliases__` for custom verbs.
341
+ * `__tigrbl_verb_alias_policy__` to scope alias application.
342
+
343
+ ### Persistence 💾
344
+
345
+ * Mixins such as `Upsertable`, `Bootstrappable`, `GUIDPk`, `Timestamped`.
346
+ * Policies `__tigrbl_owner_policy__` and `__tigrbl_tenant_policy__`.
347
+ * `transactional` decorator for atomic RPC + REST endpoints.
348
+
349
+ ### Security 🔐
350
+
351
+ * Pluggable `AuthNProvider` interface.
352
+ * `__tigrbl_allow_anon__` to permit anonymous access.
353
+
354
+ ### Default Precedence 🔧
355
+
356
+ When assembling values for persistence, defaults are resolved in this order:
357
+
358
+ 1. Client-supplied value
359
+ 2. API `default_factory`
360
+ 3. ORM default
361
+ 4. Database `server_default`
362
+ 5. HTTP 422 if the field is required and still missing
363
+
364
+ ### Database Guards 🛡️
365
+
366
+ Tigrbl executes each phase under database guards that temporarily replace
367
+ `commit` and `flush` on the SQLAlchemy session. Guards prevent writes or
368
+ commits outside their allowed phases and only permit commits when Tigrbl
369
+ owns the transaction. See the
370
+ [runtime documentation](tigrbl/v3/runtime/README.md#db-guards) for the full
371
+ matrix of phase policies.
372
+
373
+ The `START_TX` phase opens a transaction and disables `session.flush`,
374
+ allowing validation and hooks to run before any statements hit the
375
+ database. Once the transaction exists, `PRE_HANDLER`, `HANDLER`, and
376
+ `POST_HANDLER` phases permit flushes so pending writes reach the database
377
+ without committing. The workflow concludes in `END_TX`, which performs a
378
+ final flush and commits the transaction when the runtime owns it. ✅
379
+
380
+ ### Response and Template Specs 📑
381
+
382
+ Customize outbound responses with `ResponseSpec` and `TemplateSpec`. These dataclasses
383
+ control headers, status codes, and optional template rendering. See
384
+ [tigrbl/v3/response/README.md](tigrbl/v3/response/README.md) for field descriptions and examples.
385
+
386
+ ### Dependencies 📦
387
+
388
+ * SQLAlchemy for ORM integration.
389
+ * Pydantic for schema generation.
390
+ * FastAPI for routing and dependency injection.
391
+
392
+ ### Engine & Provider examples 🛠️
393
+
394
+ ```python
395
+ from tigrbl.engine.shortcuts import engine_spec, prov
396
+ from tigrbl.engine._engine import Engine, Provider
397
+
398
+ # Build an EngineSpec from a DSN string
399
+ spec = engine_spec("sqlite://:memory:")
400
+
401
+ # Or from keyword arguments
402
+ spec_pg = engine_spec(kind="postgres", async_=True, host="db", name="app_db")
403
+
404
+ # Lazy Provider from the spec
405
+ provider = prov(spec) # same as Provider(spec)
406
+ with provider.session() as session:
407
+ session.execute("SELECT 1")
408
+
409
+ # Engine façade wrapping a Provider
410
+ eng = Engine(spec_pg)
411
+ async with eng.asession() as session:
412
+ await session.execute("SELECT 1")
413
+
414
+ # Direct Provider construction is also supported
415
+ provider_pg = Provider(spec_pg)
416
+ ```
417
+
418
+ ### Attaching engine contexts 🔌
419
+
420
+ `engine_ctx` binds database configuration to different layers. It accepts a
421
+ DSN string, a mapping, an `EngineSpec`, a `Provider`, or an `Engine`. The
422
+ resolver chooses the most specific binding in the order
423
+ `op > table > api > app`.
424
+
425
+ #### Engine precedence 🥇
426
+
427
+ When engine contexts are declared at multiple scopes, Tigrbl resolves them
428
+ with strict precedence:
429
+
430
+ 1. **Op level** – bindings attached directly to an operation take highest priority.
431
+ 2. **Table/Model level** – definitions on a model or table override API and app defaults.
432
+ 3. **API level** – bindings on the API class apply when no model-specific context exists.
433
+ 4. **App level** – the default engine supplied to the application is used last.
434
+
435
+ This ordering ensures that the most specific engine context always wins.
436
+
437
+ #### Declarative bindings 📝
438
+
439
+ ```python
440
+ from types import SimpleNamespace
441
+ from tigrbl.engine.shortcuts import prov, engine
442
+
443
+ app = SimpleNamespace(db=prov(kind="sqlite", mode="memory"))
444
+ alt = SimpleNamespace(db=engine(kind="sqlite", mode="memory"))
445
+
446
+ class API:
447
+ db = {"kind": "sqlite", "memory": True}
448
+
449
+ class Item:
450
+ __tablename__ = "items"
451
+ table_config = {"db": {"kind": "sqlite", "memory": True}}
452
+
453
+ async def create(payload, *, db=None):
454
+ ...
455
+
456
+ create.__tigrbl_engine_ctx__ = {
457
+ "kind": "postgres",
458
+ "async": True,
459
+ "host": "db",
460
+ "name": "op_db",
461
+ }
462
+ ```
463
+
464
+ #### Decorative bindings 🎛️
465
+
466
+ ```python
467
+ from tigrbl.engine.decorators import engine_ctx
468
+ from tigrbl.engine.shortcuts import prov, engine
469
+
470
+ @engine_ctx(prov(kind="sqlite", mode="memory"))
471
+ class App:
472
+ pass
473
+
474
+ @engine_ctx(engine(kind="sqlite", mode="memory"))
475
+ class DecoratedAPI:
476
+ pass
477
+
478
+ @engine_ctx(kind="sqlite", mode="memory")
479
+ class DecoratedItem:
480
+ __tablename__ = "items"
481
+
482
+ @engine_ctx(kind="postgres", async_=True, host="db", name="op_db")
483
+ async def decorated_create(payload, *, db=None):
484
+ ...
485
+ ```
486
+
487
+ ## Glossary 📖
488
+
489
+ 1. Tables
490
+ 2. Schemas
491
+ 3. Schema Overlays (Request Extras)
492
+ 4. Phases
493
+ 5. Phase Lifecycle
494
+ 6. Request
495
+ 7. Request Ctx
496
+ 8. Default Flush
497
+ 9. Core
498
+ 10. Core\_Raw
499
+
500
+
501
+