Component libraries
Engine-neutral component definitions, explicit manifests, and per-Citry installations.
ComponentLibrary class
Declare one ordered, engine-neutral collection of library components.
Construct the manifest after all class decorators have completed. A valid manifest seals its definitions against later class-attribute mutation.
Attributes
namestr- Stable lowercase package identity inside one Citry instance.componentsSequence[type[LibraryComponent]]- Definitions in their deterministic registration order.required_extensionsSequence[str]- Exact extension names required before any class is materialized.
LibraryComponent class
Define a component once for materialization into multiple Citry instances.
A subclass has the same authored surface as Component: templates, methods, nested schemas, extension declarations, and assets all live on the class. Defining it has no registry side effects. Calling it returns a LibraryComponentInvocation that resolves through the Citry instance active at render time.
name attribute
name: str | NoneOptional explicit registry name, with the same behavior as Component.name.
LibraryComponentInvocation class
Remember one engine-neutral component call until rendering selects Citry.
Attributes
definitiontype[LibraryComponent]- The exact inert definition object that was called.kwargsMapping[str, Any]- A read-only copy of the component keyword arguments.slotsMapping[str, Any]- A read-only copy of the reserved slot-fill mapping.
identity attribute
identity: LibraryComponentIdentityReturn the definition's logical source identity for diagnostics.
resolve function
resolve(citry: Citry) -> CitryElementResolve this invocation to a concrete component element.
Parameters
citryCitry- The Citry instance whose installed concrete class should be used.
Returns
CitryElement: A normal [`CitryElement`](/reference/rendering/#citry-citryelement) associated with the
Raises
TypeError- If ``citry`` is not a Citry instance.LibraryNotInstalled- If no active installation contains this exact definition generation.
render function
render(citry: Citry | None = None, template_globals: Mapping[str, Any] | None = None) -> CitryRenderRender this invocation through an explicit Citry instance.
Parameters
citryCitry | None- The instance with the component's library installed.template_globalsMapping[str, Any] | None- Values added to this render's template globals.
Returns
CitryRender: The resulting deferred render tree.
Raises
LibraryComponentContextError- If ``citry`` is omitted. Contextual resolution is supplied automatically only when the invocation appears inside another component tree.
LibraryInstallation class
An immutable handle to one committed generation installed into Citry.
Retaining this handle does not make it active after Citry.clear(). Component access validates the exact active generation before returning a class.
Attributes
libraryComponentLibrary- The manifest used for this generation.engine_idstr- The receiving Citry instance's stable runtime identity.
is_active attribute
is_active: boolReturn whether this is still the Citry instance's exact active record.
classes attribute
Return concrete component classes in manifest order if this record is active.
definitions attribute
definitions: tuple[type[LibraryComponent], ...]Return the engine-neutral definitions in manifest order.
component function
component(definition: type[LibraryComponent]) -> type[Component]Return the installed concrete class for an exact definition generation.
Parameters
definitiontype[LibraryComponent]- One exact definition object from this manifest.
Returns
type[Component]: The concrete Component class associated with this installation.
Raises
LibraryInstallationStale- If the Citry instance was cleared or a newer installation generation is active.KeyError- If the definition is outside this library.
ComponentLike class
Bases: Protocol
A value that composes a component for the Citry instance rendering it.
Implement this structural protocol when a third-party object should work in template expressions or slot values without itself being a Component. Citry resolves the object once at the render site and verifies that the returned element belongs to the exact active instance.
Example
::
class NoticeValue: def __citry_element__(self, citry, /): Notice = citry.get("Notice") return Notice(message="Saved")
LibraryComponentContextError class
Bases: RuntimeError
Report that a library invocation has no Citry instance to resolve through.
LibraryInstallationStale class
Bases: RuntimeError
Report that a retained installation is not the Citry instance's active generation.
LibraryManifestChanged class
Bases: RuntimeError
Report an incompatible manifest for an already installed library name.
LibraryNotInstalled class
Bases: RuntimeError
Report that no active library installation can satisfy an invocation.