Skip to content

Class tigrbl.app._app.App

tigrbl.app._app.App

App(*, engine=None, **fastapi_kwargs)

Bases: AppSpec, FastAPI

Source code in tigrbl/app/_app.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def __init__(
    self, *, engine: EngineCfg | None = None, **fastapi_kwargs: Any
) -> None:
    # Manually mirror ``AppSpec`` fields so the dataclass-generated ``repr``
    # and friends have expected attributes while runtime structures remain
    # mutable dictionaries or lists as needed.
    self.title = self.TITLE
    self.version = self.VERSION
    self.engine = engine if engine is not None else getattr(self, "ENGINE", None)
    self.apis = tuple(getattr(self, "APIS", ()))
    self.ops = tuple(getattr(self, "OPS", ()))
    # Runtime registries use mutable containers (dict/namespace), but the
    # dataclass fields expect sequences. Storing a dict here satisfies both.
    self.models = {}
    self.schemas = tuple(getattr(self, "SCHEMAS", ()))
    self.hooks = tuple(getattr(self, "HOOKS", ()))
    self.security_deps = tuple(getattr(self, "SECURITY_DEPS", ()))
    self.deps = tuple(getattr(self, "DEPS", ()))
    self.response = getattr(self, "RESPONSE", None)
    self.jsonrpc_prefix = getattr(self, "JSONRPC_PREFIX", "/rpc")
    self.system_prefix = getattr(self, "SYSTEM_PREFIX", "/system")
    self.middlewares = tuple(getattr(self, "MIDDLEWARES", ()))
    self.lifespan = self.LIFESPAN

    FastAPI.__init__(
        self,
        title=self.title,
        version=self.version,
        lifespan=self.lifespan,
        **fastapi_kwargs,
    )
    _engine_ctx = self.engine
    if _engine_ctx is not None:
        _resolver.set_default(_engine_ctx)
        _resolver.resolve_provider()
    for mw in getattr(self, "MIDDLEWARES", []):
        self.add_middleware(mw.__class__, **getattr(mw, "kwargs", {}))

title instance-attribute

title = TITLE

version instance-attribute

version = VERSION

engine instance-attribute

engine = (
    engine
    if engine is not None
    else getattr(self, "ENGINE", None)
)

apis instance-attribute

apis = tuple(getattr(self, 'APIS', ()))

ops instance-attribute

ops = tuple(getattr(self, 'OPS', ()))

models instance-attribute

models = {}

schemas instance-attribute

schemas = tuple(getattr(self, 'SCHEMAS', ()))

hooks instance-attribute

hooks = tuple(getattr(self, 'HOOKS', ()))

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)

jsonrpc_prefix instance-attribute

jsonrpc_prefix = getattr(self, 'JSONRPC_PREFIX', '/rpc')

system_prefix instance-attribute

system_prefix = getattr(self, 'SYSTEM_PREFIX', '/system')

middlewares instance-attribute

middlewares = tuple(getattr(self, 'MIDDLEWARES', ()))

lifespan instance-attribute

lifespan = LIFESPAN

install_engines

install_engines(*, api=None, models=None)
Source code in tigrbl/app/_app.py
51
52
53
54
55
56
57
58
59
60
61
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)