Skip to content

API Reference

holm.App(*, app=None, htmy=None)

Creates a FastAPI application with all the routes that are defined in the application package.

Parameters:

Name Type Description Default
app FastAPI | None

Optional FastAPI application to use. If None, a new instance will be created.

None
htmy HTMY | None

Optional fasthx.htmy.HTMY instance to use for server-side rendering. If None, a default instance will be created.

None
Source code in holm/app.py
def App(*, app: FastAPI | None = None, htmy: HTMY | None = None) -> FastAPI:
    """
    Creates a FastAPI application with all the routes that are defined in the application package.

    Arguments:
        app: Optional FastAPI application to use. If `None`, a new instance will be created.
        htmy: Optional `fasthx.htmy.HTMY` instance to use for server-side rendering. If `None`,
            a default instance will be created.
    """
    if app is None:
        app = FastAPI()

    if htmy is None:
        htmy = HTMY()

    config = AppConfig.default()
    packages = _discover_app_packages(config)
    root_node = _build_app_tree(packages)

    # Register error handlers
    if pkg := root_node.package:
        register_error_handlers(app, pkg.import_module("error", is_error_handler_owner), htmy=htmy)

    # Build the API
    app.include_router(_build_api(root_node, htmy=htmy))

    return app

holm.Metadata

Bases: ContextAware

Context-aware metadata provider.

The class implements the Mapping protocol as a means of giving convenient access to the metadata it contains.

Source code in holm/modules/_metadata.py
class Metadata(ContextAware):
    """
    Context-aware metadata provider.

    The class implements the `Mapping` protocol as a means of giving convenient access to
    the metadata it contains.
    """

    __slots__ = ("_metadata",)

    def __init__(self, metadata: MetadataMapping) -> None:
        """
        Initialization.

        Arguments:
            metadata: The actual metadata mapping.
        """
        self._metadata = metadata
        """The metadata mapping."""

    @overload
    def get(self, key: Any, default: None = None) -> Any | None: ...

    @overload
    def get(self, key: Any, default: Any) -> Any: ...

    def get(self, key: Any, default: Any | None = None) -> Any | None:
        """Implements `Mapping.get()`."""
        return self._metadata.get(key, default)

    def __contains__(self, key: Any) -> bool:
        """Implements the `Container` protocol."""
        return key in self._metadata

    def __eq__(self, other: Any) -> bool:
        return isinstance(other, Metadata) and self._metadata == other._metadata

    def __getitem__(self, key: Any) -> Any:
        """Implements the `Sequence` protocol."""
        return self._metadata[key]

    def __iter__(self) -> Iterator[Any]:
        """Implements the `Iterable` protocol."""
        return iter(self._metadata)

    def __len__(self) -> int:
        """Implements the `Sized` protocol."""
        return len(self._metadata)

    def __ne__(self, other: Any) -> bool:
        return not self.__eq__(other)

    def items(self) -> ItemsView[Any, Any]:
        """Implements `Mapping.items()`."""
        return self._metadata.items()

    def keys(self) -> KeysView[Any]:
        """Implements `Mapping.keys()`."""
        return self._metadata.keys()

    def values(self) -> ValuesView[Any]:
        """Implements `Mapping.values()`."""
        return self._metadata.values()

__contains__(key)

Implements the Container protocol.

Source code in holm/modules/_metadata.py
def __contains__(self, key: Any) -> bool:
    """Implements the `Container` protocol."""
    return key in self._metadata

__getitem__(key)

Implements the Sequence protocol.

Source code in holm/modules/_metadata.py
def __getitem__(self, key: Any) -> Any:
    """Implements the `Sequence` protocol."""
    return self._metadata[key]

__iter__()

Implements the Iterable protocol.

Source code in holm/modules/_metadata.py
def __iter__(self) -> Iterator[Any]:
    """Implements the `Iterable` protocol."""
    return iter(self._metadata)

__len__()

Implements the Sized protocol.

Source code in holm/modules/_metadata.py
def __len__(self) -> int:
    """Implements the `Sized` protocol."""
    return len(self._metadata)

get(key, default=None)

get(key: Any, default: None = None) -> Any | None
get(key: Any, default: Any) -> Any

Implements Mapping.get().

Source code in holm/modules/_metadata.py
def get(self, key: Any, default: Any | None = None) -> Any | None:
    """Implements `Mapping.get()`."""
    return self._metadata.get(key, default)

items()

Implements Mapping.items().

Source code in holm/modules/_metadata.py
def items(self) -> ItemsView[Any, Any]:
    """Implements `Mapping.items()`."""
    return self._metadata.items()

keys()

Implements Mapping.keys().

Source code in holm/modules/_metadata.py
def keys(self) -> KeysView[Any]:
    """Implements `Mapping.keys()`."""
    return self._metadata.keys()

values()

Implements Mapping.values().

Source code in holm/modules/_metadata.py
def values(self) -> ValuesView[Any]:
    """Implements `Mapping.values()`."""
    return self._metadata.values()