httk.serve¶
Provide unified web-serving, application-composition, and OPTIMADE capabilities.
Submodules¶
Attributes¶
The httk-serve serving application type (a Starlette app; branded so consumers need not import Starlette). |
|
An immutable JSON value snapshot. |
|
A JSON scalar -- string, number, boolean, or null. |
|
An arbitrary JSON value modelled with ordinary mutable containers. |
Classes¶
Associate a Starlette application with an explicit absolute path. |
Functions¶
|
Compose Starlette applications at caller-selected URL paths. |
|
Freeze a JSON-compatible value without retaining caller-owned containers. |
|
Return an independent ordinary JSON value from an immutable snapshot. |
Package Contents¶
- class httk.serve.ASGIAppMount[source]¶
Associate a Starlette application with an explicit absolute path.
- Parameters:
path – Canonical absolute URL path, with
/reserved for a root fallback.app – Starlette application to mount.
The composed application owns the mounted applications for the duration of its lifespan and enters each distinct child’s Starlette lifespan once. Constructing a mount or a composition does not close or otherwise mutate caller-owned applications when validation fails.
- httk.serve.compose_asgi_apps(mounts, *, root=None)[source]¶
Compose Starlette applications at caller-selected URL paths.
More-specific paths are routed before their ancestors regardless of caller order. At application startup, each distinct mounted child is entered in that deterministic route order and is exited in reverse order; a failed startup unwinds children that already started. The returned parent owns lifespan coordination but not application configuration or data.
- Parameters:
mounts (collections.abc.Iterable[ASGIAppMount]) – Service mounts with paths other than
/.root (ASGIAppMount | None) – Optional
ASGIAppMountat/used as the fallback route.
- Returns:
Parent Starlette application containing the requested mounts.
- Raises:
TypeError – If a descriptor or application has the wrong type.
ValueError – If paths are malformed, noncanonical, or duplicated.
- Return type:
- type httk.serve.ServeApp = Starlette[source]¶
The httk-serve serving application type (a Starlette app; branded so consumers need not import Starlette).
Annotation-only: this is a type alias, not the
Starletteclass, so useStarletteitself forisinstance/subclass checks.
- type httk.serve.FrozenJsonValue = JsonScalar | tuple['FrozenJsonValue', ...] | Mapping[str, 'FrozenJsonValue'][source]¶
An immutable JSON value snapshot.
The mapping arm is typed as
Mappingso a plain mutabledictsatisfies it statically, whilefreeze_json()guarantees aMappingProxyTypeat runtime. This static/runtime gap is intentional and is not closed here.
- type httk.serve.JsonScalar = str | int | float | bool | None[source]¶
A JSON scalar – string, number, boolean, or null.
- type httk.serve.JsonValue = JsonScalar | list['JsonValue'] | dict[str, 'JsonValue'][source]¶
An arbitrary JSON value modelled with ordinary mutable containers.
- httk.serve.freeze_json(value)[source]¶
Freeze a JSON-compatible value without retaining caller-owned containers.
- Parameters:
value (object) – JSON-compatible value to copy into an immutable representation.
- Returns:
An immutable JSON-compatible value.
- Raises:
TypeError – If
valueis not JSON-compatible.ValueError – If a floating-point value is non-finite.
- Return type:
- httk.serve.thaw_json(value)[source]¶
Return an independent ordinary JSON value from an immutable snapshot.
- Parameters:
value (FrozenJsonValue) – Immutable JSON-compatible value to copy.
- Returns:
Plain JSON-compatible lists and dictionaries.
- Return type: