TigrblApi(
*,
engine=None,
jsonrpc_prefix="/rpc",
system_prefix="/system",
api_hooks=None,
**router_kwargs,
)
Bases: Api
Canonical router-focused facade that owns
• containers (models, schemas, handlers, hooks, rpc, rest, routers, columns, table_config, core proxies)
• model inclusion (REST + RPC wiring)
• JSON-RPC / diagnostics mounting
• (optional) auth knobs recognized by some middlewares/dispatchers
It composes v3 primitives; you can still use the functions directly if you prefer.
Source code in tigrbl/api/tigrbl_api.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90 | def __init__(
self,
*,
engine: EngineCfg | None = None,
jsonrpc_prefix: str = "/rpc",
system_prefix: str = "/system",
api_hooks: Mapping[str, Iterable[Callable]]
| Mapping[str, Mapping[str, Iterable[Callable]]]
| None = None,
**router_kwargs: Any,
) -> None:
_Api.__init__(self, engine=engine, **router_kwargs)
self.jsonrpc_prefix = jsonrpc_prefix
self.system_prefix = system_prefix
# public containers (mirrors used by bindings.api)
self.models: Dict[str, type] = {}
self.schemas = SimpleNamespace()
self.handlers = SimpleNamespace()
self.hooks = SimpleNamespace()
self.rpc = SimpleNamespace()
self.rest = SimpleNamespace()
self.routers: Dict[str, Any] = {}
self.tables = AttrDict()
self.columns: Dict[str, Tuple[str, ...]] = {}
self.table_config: Dict[str, Dict[str, Any]] = {}
self.core = SimpleNamespace()
self.core_raw = SimpleNamespace()
# API-level hooks map (merged into each model at include-time; precedence handled in bindings.hooks)
self._api_hooks_map = copy.deepcopy(api_hooks) if api_hooks else None
|
PREFIX
class-attribute
instance-attribute
APIS
class-attribute
instance-attribute
MODELS
class-attribute
instance-attribute
jsonrpc_prefix
instance-attribute
jsonrpc_prefix = jsonrpc_prefix
system_prefix
instance-attribute
system_prefix = system_prefix
models
instance-attribute
schemas
instance-attribute
schemas = SimpleNamespace()
handlers
instance-attribute
handlers = SimpleNamespace()
hooks
instance-attribute
hooks = SimpleNamespace()
routers
instance-attribute
tables
instance-attribute
columns
instance-attribute
table_config
instance-attribute
core_raw
instance-attribute
core_raw = SimpleNamespace()
initialize
class-attribute
instance-attribute
name
instance-attribute
name = getattr(self, 'NAME', 'api')
prefix
instance-attribute
engine
instance-attribute
engine = (
engine
if engine is not None
else getattr(self, "ENGINE", None)
)
tags = list(getattr(self, 'TAGS', []))
ops
instance-attribute
ops = tuple(getattr(self, 'OPS', ()))
security_deps
instance-attribute
security_deps = tuple(getattr(self, 'SECURITY_DEPS', ()))
deps
instance-attribute
deps = tuple(getattr(self, 'DEPS', ()))
response
instance-attribute
response = getattr(self, 'RESPONSE', None)
TABLES
class-attribute
instance-attribute
include_model
include_model(model, *, prefix=None, mount_router=True)
Bind a model, mount its REST router, and attach all namespaces to this facade.
Source code in tigrbl/api/tigrbl_api.py
131
132
133
134
135
136
137
138
139
140
141 | def include_model(
self, model: type, *, prefix: str | None = None, mount_router: bool = True
) -> Tuple[type, Any]:
"""
Bind a model, mount its REST router, and attach all namespaces to this facade.
"""
# inject API-level hooks so the binder merges them
self._merge_api_hooks_into_model(model, self._api_hooks_map)
return _include_model(
self, model, app=None, prefix=prefix, mount_router=mount_router
)
|
include_models
include_models(
models, *, base_prefix=None, mount_router=True
)
Source code in tigrbl/api/tigrbl_api.py
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158 | def include_models(
self,
models: Sequence[type],
*,
base_prefix: str | None = None,
mount_router: bool = True,
) -> Dict[str, Any]:
for m in models:
self._merge_api_hooks_into_model(m, self._api_hooks_map)
return _include_models(
self,
models,
app=None,
base_prefix=base_prefix,
mount_router=mount_router,
)
|
rpc_call
async
rpc_call(
model_or_name,
method,
payload=None,
*,
db,
request=None,
ctx=None,
)
Source code in tigrbl/api/tigrbl_api.py
160
161
162
163
164
165
166
167
168
169
170
171
172 | async def rpc_call(
self,
model_or_name: type | str,
method: str,
payload: Any = None,
*,
db: Any,
request: Any = None,
ctx: Optional[Dict[str, Any]] = None,
) -> Any:
return await _rpc_call(
self, model_or_name, method, payload, db=db, request=request, ctx=ctx
)
|
mount_jsonrpc
mount_jsonrpc(*, prefix=None)
Mount a JSON-RPC router onto this TigrblApi instance.
Source code in tigrbl/api/tigrbl_api.py
176
177
178
179
180
181
182
183
184
185
186
187 | def mount_jsonrpc(self, *, prefix: str | None = None) -> Any:
"""Mount a JSON-RPC router onto this TigrblApi instance."""
px = prefix if prefix is not None else self.jsonrpc_prefix
prov = _resolver.resolve_provider(api=self)
get_db = prov.get_db if prov else None
router = _mount_jsonrpc(
self,
self,
prefix=px,
get_db=get_db,
)
return router
|
attach_diagnostics
attach_diagnostics(*, prefix=None, app=None)
Mount a diagnostics router onto this TigrblApi instance or app.
Source code in tigrbl/api/tigrbl_api.py
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204 | def attach_diagnostics(
self, *, prefix: str | None = None, app: Any | None = None
) -> Any:
"""Mount a diagnostics router onto this TigrblApi instance or ``app``."""
px = prefix if prefix is not None else self.system_prefix
prov = _resolver.resolve_provider(api=self)
get_db = prov.get_db if prov else None
router = _mount_diagnostics(self, get_db=get_db)
include_self = getattr(self, "include_router", None)
if callable(include_self):
include_self(router, prefix=px)
if app is not None and app is not self:
include_other = getattr(app, "include_router", None)
if callable(include_other):
include_other(router, prefix=px)
return router
|
registry
Return the per-model OpspecRegistry.
Source code in tigrbl/api/tigrbl_api.py
| def registry(self, model: type):
"""Return the per-model OpspecRegistry."""
return get_registry(model)
|
bind
Bind/rebuild a model in place (without mounting).
Source code in tigrbl/api/tigrbl_api.py
| def bind(self, model: type) -> Tuple[OpSpec, ...]:
"""Bind/rebuild a model in place (without mounting)."""
self._merge_api_hooks_into_model(model, self._api_hooks_map)
return _bind(model)
|
rebind
rebind(model, *, changed_keys=None)
Targeted rebuild of a bound model.
Source code in tigrbl/api/tigrbl_api.py
| def rebind(
self, model: type, *, changed_keys: Optional[set[tuple[str, str]]] = None
) -> Tuple[OpSpec, ...]:
"""Targeted rebuild of a bound model."""
return _rebind(model, changed_keys=changed_keys)
|
set_auth
set_auth(
*,
authn=None,
allow_anon=None,
authorize=None,
optional_authn_dep=None,
)
Source code in tigrbl/api/tigrbl_api.py
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243 | def set_auth(
self,
*,
authn: Any = None,
allow_anon: Optional[bool] = None,
authorize: Any = None,
optional_authn_dep: Any = None,
) -> None:
if authn is not None:
self._authn = authn
if allow_anon is not None:
self._allow_anon = bool(allow_anon)
if authorize is not None:
self._authorize = authorize
if optional_authn_dep is not None:
self._optional_authn_dep = optional_authn_dep
# Refresh already-included models so routers pick up new auth settings
if self.models:
self._refresh_security()
|
install_engines
install_engines(*, api=None, models=None)
Source code in tigrbl/api/_api.py
62
63
64
65
66
67
68
69
70
71
72 | def install_engines(
self, *, api: Any = None, models: tuple[Any, ...] | None = None
) -> None:
# If class declared APIS/MODELS, use them unless explicit args are passed.
apis = (api,) if api is not None else self.APIS
models = models if models is not None else self.MODELS
if apis:
for a in apis:
install_from_objects(app=self, api=a, models=models)
else:
install_from_objects(app=self, api=None, models=models)
|