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.
- tigrbl/README.md +94 -0
- tigrbl/__init__.py +139 -14
- tigrbl/api/__init__.py +6 -0
- tigrbl/api/_api.py +72 -0
- tigrbl/api/api_spec.py +30 -0
- tigrbl/api/mro_collect.py +43 -0
- tigrbl/api/shortcuts.py +56 -0
- tigrbl/api/tigrbl_api.py +286 -0
- tigrbl/app/__init__.py +0 -0
- tigrbl/app/_app.py +61 -0
- tigrbl/app/app_spec.py +42 -0
- tigrbl/app/mro_collect.py +67 -0
- tigrbl/app/shortcuts.py +65 -0
- tigrbl/app/tigrbl_app.py +314 -0
- tigrbl/bindings/__init__.py +73 -0
- tigrbl/bindings/api/__init__.py +12 -0
- tigrbl/bindings/api/common.py +109 -0
- tigrbl/bindings/api/include.py +256 -0
- tigrbl/bindings/api/resource_proxy.py +149 -0
- tigrbl/bindings/api/rpc.py +111 -0
- tigrbl/bindings/columns.py +49 -0
- tigrbl/bindings/handlers/__init__.py +11 -0
- tigrbl/bindings/handlers/builder.py +119 -0
- tigrbl/bindings/handlers/ctx.py +74 -0
- tigrbl/bindings/handlers/identifiers.py +228 -0
- tigrbl/bindings/handlers/namespaces.py +51 -0
- tigrbl/bindings/handlers/steps.py +276 -0
- tigrbl/bindings/hooks.py +311 -0
- tigrbl/bindings/model.py +194 -0
- tigrbl/bindings/model_helpers.py +139 -0
- tigrbl/bindings/model_registry.py +77 -0
- tigrbl/bindings/rest/__init__.py +7 -0
- tigrbl/bindings/rest/attach.py +34 -0
- tigrbl/bindings/rest/collection.py +265 -0
- tigrbl/bindings/rest/common.py +116 -0
- tigrbl/bindings/rest/fastapi.py +76 -0
- tigrbl/bindings/rest/helpers.py +119 -0
- tigrbl/bindings/rest/io.py +317 -0
- tigrbl/bindings/rest/member.py +367 -0
- tigrbl/bindings/rest/router.py +292 -0
- tigrbl/bindings/rest/routing.py +133 -0
- tigrbl/bindings/rpc.py +364 -0
- tigrbl/bindings/schemas/__init__.py +11 -0
- tigrbl/bindings/schemas/builder.py +348 -0
- tigrbl/bindings/schemas/defaults.py +260 -0
- tigrbl/bindings/schemas/utils.py +193 -0
- tigrbl/column/README.md +62 -0
- tigrbl/column/__init__.py +72 -0
- tigrbl/column/_column.py +96 -0
- tigrbl/column/column_spec.py +40 -0
- tigrbl/column/field_spec.py +31 -0
- tigrbl/column/infer/__init__.py +25 -0
- tigrbl/column/infer/core.py +92 -0
- tigrbl/column/infer/jsonhints.py +44 -0
- tigrbl/column/infer/planning.py +133 -0
- tigrbl/column/infer/types.py +102 -0
- tigrbl/column/infer/utils.py +59 -0
- tigrbl/column/io_spec.py +133 -0
- tigrbl/column/mro_collect.py +59 -0
- tigrbl/column/shortcuts.py +89 -0
- tigrbl/column/storage_spec.py +65 -0
- tigrbl/config/__init__.py +19 -0
- tigrbl/config/constants.py +224 -0
- tigrbl/config/defaults.py +29 -0
- tigrbl/config/resolver.py +295 -0
- tigrbl/core/__init__.py +47 -0
- tigrbl/core/crud/__init__.py +36 -0
- tigrbl/core/crud/bulk.py +168 -0
- tigrbl/core/crud/helpers/__init__.py +76 -0
- tigrbl/core/crud/helpers/db.py +92 -0
- tigrbl/core/crud/helpers/enum.py +86 -0
- tigrbl/core/crud/helpers/filters.py +162 -0
- tigrbl/core/crud/helpers/model.py +123 -0
- tigrbl/core/crud/helpers/normalize.py +99 -0
- tigrbl/core/crud/ops.py +235 -0
- tigrbl/ddl/__init__.py +344 -0
- tigrbl/decorators.py +17 -0
- tigrbl/deps/__init__.py +20 -0
- tigrbl/deps/fastapi.py +45 -0
- tigrbl/deps/favicon.svg +4 -0
- tigrbl/deps/jinja.py +27 -0
- tigrbl/deps/pydantic.py +10 -0
- tigrbl/deps/sqlalchemy.py +94 -0
- tigrbl/deps/starlette.py +36 -0
- tigrbl/engine/__init__.py +26 -0
- tigrbl/engine/_engine.py +130 -0
- tigrbl/engine/bind.py +33 -0
- tigrbl/engine/builders.py +236 -0
- tigrbl/engine/collect.py +111 -0
- tigrbl/engine/decorators.py +108 -0
- tigrbl/engine/engine_spec.py +261 -0
- tigrbl/engine/resolver.py +224 -0
- tigrbl/engine/shortcuts.py +216 -0
- tigrbl/hook/__init__.py +21 -0
- tigrbl/hook/_hook.py +22 -0
- tigrbl/hook/decorators.py +28 -0
- tigrbl/hook/hook_spec.py +24 -0
- tigrbl/hook/mro_collect.py +98 -0
- tigrbl/hook/shortcuts.py +44 -0
- tigrbl/hook/types.py +76 -0
- tigrbl/op/__init__.py +50 -0
- tigrbl/op/_op.py +31 -0
- tigrbl/op/canonical.py +31 -0
- tigrbl/op/collect.py +11 -0
- tigrbl/op/decorators.py +238 -0
- tigrbl/op/model_registry.py +301 -0
- tigrbl/op/mro_collect.py +99 -0
- tigrbl/op/resolver.py +216 -0
- tigrbl/op/types.py +136 -0
- tigrbl/orm/__init__.py +1 -0
- tigrbl/orm/mixins/_RowBound.py +83 -0
- tigrbl/orm/mixins/__init__.py +95 -0
- tigrbl/orm/mixins/bootstrappable.py +113 -0
- tigrbl/orm/mixins/bound.py +47 -0
- tigrbl/orm/mixins/edges.py +40 -0
- tigrbl/orm/mixins/fields.py +165 -0
- tigrbl/orm/mixins/hierarchy.py +54 -0
- tigrbl/orm/mixins/key_digest.py +44 -0
- tigrbl/orm/mixins/lifecycle.py +115 -0
- tigrbl/orm/mixins/locks.py +51 -0
- tigrbl/orm/mixins/markers.py +16 -0
- tigrbl/orm/mixins/operations.py +57 -0
- tigrbl/orm/mixins/ownable.py +337 -0
- tigrbl/orm/mixins/principals.py +98 -0
- tigrbl/orm/mixins/tenant_bound.py +301 -0
- tigrbl/orm/mixins/upsertable.py +111 -0
- tigrbl/orm/mixins/utils.py +49 -0
- tigrbl/orm/tables/__init__.py +72 -0
- tigrbl/orm/tables/_base.py +8 -0
- tigrbl/orm/tables/audit.py +56 -0
- tigrbl/orm/tables/client.py +25 -0
- tigrbl/orm/tables/group.py +29 -0
- tigrbl/orm/tables/org.py +30 -0
- tigrbl/orm/tables/rbac.py +76 -0
- tigrbl/orm/tables/status.py +106 -0
- tigrbl/orm/tables/tenant.py +22 -0
- tigrbl/orm/tables/user.py +39 -0
- tigrbl/response/README.md +34 -0
- tigrbl/response/__init__.py +33 -0
- tigrbl/response/bind.py +12 -0
- tigrbl/response/decorators.py +37 -0
- tigrbl/response/resolver.py +83 -0
- tigrbl/response/shortcuts.py +144 -0
- tigrbl/response/types.py +49 -0
- tigrbl/rest/__init__.py +27 -0
- tigrbl/runtime/README.md +129 -0
- tigrbl/runtime/__init__.py +20 -0
- tigrbl/runtime/atoms/__init__.py +102 -0
- tigrbl/runtime/atoms/emit/__init__.py +42 -0
- tigrbl/runtime/atoms/emit/paired_post.py +158 -0
- tigrbl/runtime/atoms/emit/paired_pre.py +106 -0
- tigrbl/runtime/atoms/emit/readtime_alias.py +120 -0
- tigrbl/runtime/atoms/out/__init__.py +38 -0
- tigrbl/runtime/atoms/out/masking.py +135 -0
- tigrbl/runtime/atoms/refresh/__init__.py +38 -0
- tigrbl/runtime/atoms/refresh/demand.py +130 -0
- tigrbl/runtime/atoms/resolve/__init__.py +40 -0
- tigrbl/runtime/atoms/resolve/assemble.py +167 -0
- tigrbl/runtime/atoms/resolve/paired_gen.py +147 -0
- tigrbl/runtime/atoms/response/__init__.py +17 -0
- tigrbl/runtime/atoms/response/negotiate.py +30 -0
- tigrbl/runtime/atoms/response/negotiation.py +43 -0
- tigrbl/runtime/atoms/response/render.py +36 -0
- tigrbl/runtime/atoms/response/renderer.py +116 -0
- tigrbl/runtime/atoms/response/template.py +44 -0
- tigrbl/runtime/atoms/response/templates.py +88 -0
- tigrbl/runtime/atoms/schema/__init__.py +40 -0
- tigrbl/runtime/atoms/schema/collect_in.py +21 -0
- tigrbl/runtime/atoms/schema/collect_out.py +21 -0
- tigrbl/runtime/atoms/storage/__init__.py +38 -0
- tigrbl/runtime/atoms/storage/to_stored.py +167 -0
- tigrbl/runtime/atoms/wire/__init__.py +45 -0
- tigrbl/runtime/atoms/wire/build_in.py +166 -0
- tigrbl/runtime/atoms/wire/build_out.py +87 -0
- tigrbl/runtime/atoms/wire/dump.py +206 -0
- tigrbl/runtime/atoms/wire/validate_in.py +227 -0
- tigrbl/runtime/context.py +206 -0
- tigrbl/runtime/errors/__init__.py +61 -0
- tigrbl/runtime/errors/converters.py +214 -0
- tigrbl/runtime/errors/exceptions.py +124 -0
- tigrbl/runtime/errors/mappings.py +71 -0
- tigrbl/runtime/errors/utils.py +150 -0
- tigrbl/runtime/events.py +209 -0
- tigrbl/runtime/executor/__init__.py +6 -0
- tigrbl/runtime/executor/guards.py +132 -0
- tigrbl/runtime/executor/helpers.py +88 -0
- tigrbl/runtime/executor/invoke.py +150 -0
- tigrbl/runtime/executor/types.py +84 -0
- tigrbl/runtime/kernel.py +628 -0
- tigrbl/runtime/labels.py +353 -0
- tigrbl/runtime/opview.py +87 -0
- tigrbl/runtime/ordering.py +256 -0
- tigrbl/runtime/system.py +279 -0
- tigrbl/runtime/trace.py +330 -0
- tigrbl/schema/__init__.py +38 -0
- tigrbl/schema/_schema.py +27 -0
- tigrbl/schema/builder/__init__.py +17 -0
- tigrbl/schema/builder/build_schema.py +209 -0
- tigrbl/schema/builder/cache.py +24 -0
- tigrbl/schema/builder/compat.py +16 -0
- tigrbl/schema/builder/extras.py +85 -0
- tigrbl/schema/builder/helpers.py +51 -0
- tigrbl/schema/builder/list_params.py +117 -0
- tigrbl/schema/builder/strip_parent_fields.py +70 -0
- tigrbl/schema/collect.py +55 -0
- tigrbl/schema/decorators.py +68 -0
- tigrbl/schema/get_schema.py +86 -0
- tigrbl/schema/schema_spec.py +20 -0
- tigrbl/schema/shortcuts.py +42 -0
- tigrbl/schema/types.py +34 -0
- tigrbl/schema/utils.py +143 -0
- tigrbl/shortcuts.py +22 -0
- tigrbl/specs.py +44 -0
- tigrbl/system/__init__.py +12 -0
- tigrbl/system/diagnostics/__init__.py +24 -0
- tigrbl/system/diagnostics/compat.py +31 -0
- tigrbl/system/diagnostics/healthz.py +41 -0
- tigrbl/system/diagnostics/hookz.py +51 -0
- tigrbl/system/diagnostics/kernelz.py +20 -0
- tigrbl/system/diagnostics/methodz.py +43 -0
- tigrbl/system/diagnostics/router.py +73 -0
- tigrbl/system/diagnostics/utils.py +43 -0
- tigrbl/table/__init__.py +9 -0
- tigrbl/table/_base.py +237 -0
- tigrbl/table/_table.py +54 -0
- tigrbl/table/mro_collect.py +69 -0
- tigrbl/table/shortcuts.py +57 -0
- tigrbl/table/table_spec.py +28 -0
- tigrbl/transport/__init__.py +74 -0
- tigrbl/transport/jsonrpc/__init__.py +19 -0
- tigrbl/transport/jsonrpc/dispatcher.py +352 -0
- tigrbl/transport/jsonrpc/helpers.py +115 -0
- tigrbl/transport/jsonrpc/models.py +41 -0
- tigrbl/transport/rest/__init__.py +25 -0
- tigrbl/transport/rest/aggregator.py +132 -0
- tigrbl/types/__init__.py +174 -0
- tigrbl/types/allow_anon_provider.py +19 -0
- tigrbl/types/authn_abc.py +30 -0
- tigrbl/types/nested_path_provider.py +22 -0
- tigrbl/types/op.py +35 -0
- tigrbl/types/op_config_provider.py +17 -0
- tigrbl/types/op_verb_alias_provider.py +33 -0
- tigrbl/types/request_extras_provider.py +22 -0
- tigrbl/types/response_extras_provider.py +22 -0
- tigrbl/types/table_config_provider.py +13 -0
- tigrbl-0.3.0.dev3.dist-info/LICENSE +201 -0
- tigrbl-0.3.0.dev3.dist-info/METADATA +501 -0
- tigrbl-0.3.0.dev3.dist-info/RECORD +249 -0
- tigrbl/ExampleAgent.py +0 -1
- tigrbl-0.0.1.dev1.dist-info/METADATA +0 -18
- tigrbl-0.0.1.dev1.dist-info/RECORD +0 -5
- {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
|
+

|
|
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
|
+
|