tatami.router 🛣️¶
This module provides the base router() function used to define route classes in Tatami. Routers group related HTTP endpoints under a common path prefix and act as the entry point for request routing.
- class tatami.router.BaseRouter(title=None, description=None, summary=None, version='0.0.1', path=None, tags=None)[source]¶
Bases:
TatamiObject
- Parameters:
title (str | None)
description (str | None)
summary (str | None)
version (str)
path (str | None)
tags (list[str] | None)
- __init__(title=None, description=None, summary=None, version='0.0.1', path=None, tags=None)[source]¶
- Parameters:
title (str | None)
description (str | None)
summary (str | None)
version (str)
path (str | None)
tags (list[str] | None)
- include_router(incl_router)[source]¶
- Parameters:
incl_router (BaseRouter)
- Return type:
Self
- property routers: list[BaseRouter]¶
- run(host='localhost', port=8000, openapi_url='/openapi.json', swagger_url='/docs/swagger', redoc_url='/docs/redoc', rapidoc_url='/docs/rapidoc', docs_landing_page=True)[source]¶
Run the Tatami application using Uvicorn, and optionally serve OpenAPI and documentation UIs.
This function: - Sets the app root path to ‘’. - Adds routes to serve the OpenAPI JSON spec and interactive API docs (Swagger UI, ReDoc, RapiDoc) at the specified URLs. - Starts the Uvicorn server on the specified host and port.
- Parameters:
app (Tatami) – The Tatami application instance to run.
host (str) – Hostname to bind the server to. Defaults to ‘localhost’.
port (int) – Port to bind the server to. Defaults to 8000.
openapi_url (Optional[str]) – URL path to serve OpenAPI JSON spec. Defaults to ‘/openapi.json’. Set to None to disable.
swagger_url (Optional[str]) – URL path to serve Swagger UI. Defaults to ‘/docs/swagger’. Set to None to disable.
redoc_url (Optional[str]) – URL path to serve ReDoc UI. Defaults to ‘/docs/redoc’. Set to None to disable.
rapidoc_url (Optional[str]) – URL path to serve RapiDoc UI. Defaults to ‘/docs/rapidoc’. Set to None to disable.
docs_landing_page (bool)
- Return type:
NoReturn
Usage example:
app = Tatami(title="My API") # Run the app with default docs URLs run(app, host="0.0.0.0", port=8080)
Note
Requires uvicorn to be installed.
- class tatami.router.ConventionRouter[source]¶
Bases:
BaseRouter
- class tatami.router.DecoratedRouter(title=None, description=None, summary=None, version='0.0.1', path=None, tags=None)[source]¶
Bases:
BaseRouter
- Parameters:
title (str | None)
description (str | None)
summary (str | None)
version (str)
path (str | None)
tags (list[str] | None)
- class tatami.router.ProjectIntrospection(*, config_file=None, routers=<factory>, services=<factory>, models=<factory>, models_source=None, middleware=<factory>, static_path=None, templates_path=None, favicon_path=None, mounts=<factory>)[source]¶
Bases:
BaseModel
Comprehensive introspection data for a Tatami project.
- Parameters:
config_file (str | None)
routers (list[dict])
services (list[dict])
models (dict[str, type])
models_source (str | None)
middleware (list[dict])
static_path (str | None)
templates_path (str | None)
favicon_path (str | None)
mounts (list[dict])
- config_file: str | None¶
- favicon_path: str | None¶
- middleware: list[dict]¶
- property middleware_count: int¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- property model_count: int¶
- models: dict[str, type]¶
- models_source: str | None¶
- property mount_count: int¶
- mounts: list[dict]¶
- property router_count: int¶
- routers: list[dict]¶
- services: list[dict]¶
- static_path: str | None¶
- templates_path: str | None¶
- class tatami.router.Summary(*, config_file=None, routers=0, middleware=0, models=0, static=None, templates=None)[source]¶
Bases:
BaseModel
- Parameters:
config_file (str | None)
routers (int)
middleware (int)
models (int)
static (str | None)
templates (str | None)
- config_file: str | None¶
- middleware: int¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- models: int¶
- routers: int¶
- static: str | None¶
- templates: str | None¶
- tatami.router.router(path)[source]¶
- Parameters:
path (str)
- Return type:
Type[DecoratedRouter]