Skip to content

Application

rn_forge.fastapi.app

Construct FastAPI applications with the standard rn-forge adapters.

AppConfig(*, registry=default_registry(), checks=dict[str, Check](), required_checks=(), check_timeout=2.0, realm=None, tracing=True, log=None, liveness_path=LIVENESS_PATH, readiness_path=READINESS_PATH, legacy_liveness_path=LEGACY_LIVENESS_PATH, max_body_bytes=1048576, api_catalog=True, security_headers=True, hsts=False, cors=None) dataclass

The standard adapter configuration for :class:FastApiApp.

Parameters:

Name Type Description Default
registry ProblemRegistry

Domain exception mappings. Register application exceptions before constructing this configuration.

default_registry()
checks Mapping[str, Check]

Readiness checks, keyed by their wire-visible names.

dict[str, Check]()
required_checks Collection[str]

Check names whose failure returns 503 from the readiness path.

()
check_timeout float | None

Maximum seconds a single readiness check may run.

2.0
realm str | None

Optional Bearer authentication realm for problem responses.

None
tracing bool

Instrument the application with FastAPIInstrumentor.instrument_app and, when nothing else has, set a :class:~opentelemetry.instrumentation.propagators.TraceResponsePropagator as the global response propagator. This alone decides whether server spans are recorded: FastApiApp turns off FastAPI's native tracing unless telemetry= is passed.

True
log Log | None

Optional sink for problem.server_error events, called for every 5xx problem response with the exception under "exc".

None
liveness_path str

The liveness path.

LIVENESS_PATH
readiness_path str

The readiness path.

READINESS_PATH
legacy_liveness_path str | None

An alias of liveness_path, marked deprecated in the OpenAPI document. None serves no alias.

LEGACY_LIVENESS_PATH
max_body_bytes int | None

The largest request body admitted, per RFC 9110 §15.5.14. None disables the limit; uvicorn itself sets none.

1048576
api_catalog bool

Serve RFC 9727's /.well-known/api-catalog, pointing at the OpenAPI document and docs UI.

True
security_headers bool

Install the OWASP REST Security Cheat Sheet response headers (rn_forge.web.security.API_SECURITY_HEADERS).

True
hsts bool

Also add Strict-Transport-Security. Off by default: sending it over plain HTTP tells a browser to refuse a future connection that isn't HTTPS, so it is opt-in for deployments that terminate TLS themselves rather than at a front end that already sets it.

False
cors CorsPolicy | None

A CORS policy to install, or None (the default) to install none — the application owns whether it has a CORS policy at all.

None

FastApiApp(config=None, *, routers=(), lifespan=None, title='FastAPI', description='', version='0.1.0', **fastapi_kwargs)

Bases: FastAPI

A :class:fastapi.FastAPI with the standard rn-forge wiring installed.

FastAPI is inherited rather than wrapped, so @app.get(), add_middleware and the full :class:~fastapi.FastAPI constructor keyword set remain available.

Initialize the application and install the standard adapters.

Parameters:

Name Type Description Default
config AppConfig | None

Standard adapter configuration. Defaults to AppConfig().

None
routers Sequence[APIRouter]

Application routers to include in order.

()
lifespan Lifespan[FastAPI] | None

Application startup and shutdown hook.

None
title str

OpenAPI document title.

'FastAPI'
description str

OpenAPI document description.

''
version str

OpenAPI document version.

'0.1.0'
**fastapi_kwargs Any

Forwarded to the :class:fastapi.FastAPI constructor. generate_unique_id_function defaults to :func:operation_id and telemetry to {"tracing": False}; both may be overridden here.

{}

openapi()

Return the OpenAPI document, repaired for problem-response accuracy.

Builds through super().openapi() — which caches the document the way plain :class:~fastapi.FastAPI does — and repairs the cached document exactly once. A consumer subclass adds further repairs by overriding this method and calling super().openapi() first.