Rendering
The three-phase render pipeline and its output structs.
CitryElement class
Intermediate representation of a component invocation.
Created by Component(). Holds the component class and the kwargs/slots that were passed. Rendering is deferred until .render() is called.
Attributes
comp_cls- The Component subclass to render.kwargs- The keyword arguments passed to the component.slots- The slot fills passed to the component. Filled from either channel: the reserved ``slots=`` kwarg when composing from Python (``MyComp(title="x", slots={...})``), or the collected ``<c-fill>`` tags / implicit default body when composed by a parent template. Values are raw inputs here (strings, functions, elements, Slots); they normalize to ``Slot`` instances when the component instance is created at render time.morph_key- The evaluated ``#c-key`` value from the parent's template tag, or ``None`` when the tag carried no key. Framework metadata, not an input: the render pipeline stamps it (scoped by the child's ``class_id``) onto the child's root element(s) as the ``data-citry-key`` attribute, so the client can keep the child instance's identity across the parent's re-renders (see docs/design/events.md section 5.3). Set by ``ComponentNode``; in v1 the key is template-authored only.component_tag_client_bindings- The final source-ordered ``$c-props``, Alpine event, and Citry event contributions captured from a component tag. They are framework metadata, not Python kwargs.ownership_invocation_id- The render-local component call record that this element will bind to its concrete component instance.ownership_graph- The render-local graph that allocated ``ownership_invocation_id``. Retained explicitly so a lazy value invoked during another root render cannot bind a graph-local ID against the wrong graph.forward_ownership_invocation- Whether this element is the transparent dynamic selector and must forward the invocation to its selected target instead of consuming it.
render function
render(template_globals: Mapping[str, Any] | None = None) -> CitryRenderRender this component into a CitryRender.
Each call mints fresh per-instance state (render_id, etc.), so the same CitryElement can be rendered multiple times with distinct identities.
template_globals adds or overrides template variables for this one render, layered on top of the instance's citry.template_globals and under each component's own template_data. They reach every component in the render, including nested children, embedded elements, and slot content, which suits per-request values (the current user, a request id) that should not be stored on the shared instance.
Returns a CitryRender (the render-phase output), not a string. Call .serialize() on it (or str()) to get the HTML. str() on the element itself runs the full chain with sensible defaults (and no template_globals).
CitryRender class
The result of rendering a CitryElement (the render-phase output).
Attributes
parts- Ordered list of ``str`` or nested ``CitryRender`` fragments.context- The ``CitryContext`` used to produce this render.is_component_rootbool- True only for the render that is a component's whole output (produced by the render pipeline, one per component instance). Interior renders (a ``<c-if>``/``<c-for>`` block, a nested template, slot-fill content rendered in the enclosing scope) are False. Serialization uses this to tell a completed child-component subtree (which becomes its own marked frame) from content that joins into the surrounding frame; the component on the context cannot tell these apart, because slot-fill content carries the context of the component that wrote it, not the one it renders inside.
is_component_root attribute
is_component_root: boolWhether this render is the whole output frame of one component.
serialize function
serialize(deps_strategy: DepsStrategy = 'document', deps_position: DepsPosition = 'smart') -> strTurn this render into a final HTML string.
Each component's root element(s) get a data-cid-<id> marker so the rendered HTML records which component produced which part of the page, and the JS/CSS collected from the rendered components is placed into the output per the chosen strategy and position.
Raises RuntimeError if any child component was left unrendered (a DeferredComponent still in the parts), which can only happen if this render did not come from render().
Parameters
deps_strategyDepsStrategy- How to handle the collected JS/CSS. - ``"document"`` (default): emit the tags, plus the client-side dependency manager and the page manifest when any component registered a per-instance callback (``$component``), so ``js_data()`` reaches the browser. - ``"simple"``: the tags only, no JavaScript runtime. For static pages and emails; per-instance JS does not run (CSS variables still work, they are pure CSS). - ``"fragment"``: HTML meant to be inserted into an already-loaded page (an HTMX swap, ``fetch`` + ``innerHTML``, ...): nothing is inlined; the output ends with a JSON manifest of URLs the client-side manager fetches, each once per page however many fragments need it. Requires a mounted web integration. - ``"ignore"``: no tags inserted.deps_positionDepsPosition- Where the tags go (``document``/``simple`` only). - ``"smart"`` (default): into the ``<c-js>``/``<c-css>`` placeholders when present, else CSS before the first ``</head>`` and JS before the last ``</body>``, else CSS is prepended and JS appended. - ``"prepend"`` / ``"append"``: all tags before/after the whole output.
CitryContext class
Render-scoped state for a single component render.
Attributes
variables- The per-component template variables (the ``template_data`` output). Read by nodes when evaluating expressions.component- The ``Component`` instance currently rendering. Gives a node access to the component tree (its ``citry`` registry for resolving child component names, and its ``parent``/``root`` linkage). The current component is stored on the context, so each component render gets its own ``CitryContext``.extra- Tree-wide scratch space for extensions (for example the collected JS/CSS dependency records). Top-level keys are namespaced by owner; see the module docstring.provides- The provide/inject entries active at this point of the render. Values are immutable payloads or a private blocked marker. Read-only by convention; ``Component.provide`` and ``Component.unprovide`` build a new mapping rather than mutating this one.
CitryTemplate class
A component's loaded template: the source string, its origin, and its compiled form (once first rendered).
Attributes
sourcestr- The template string, after ``on_template_loaded`` hooks ran.originstr- Where the template came from, for error messages and debugging. The absolute file path for a file template, or ``"<module file>::<ClassName>"`` for an inline one.filepathPath | None- The resolved template file, or ``None`` when the template was inlined on the class.generateCallable[[], list[BodyItem]] | None- Internal. The compiled body-generating function; calling it yields a fresh node list. ``None`` until the render pipeline compiles the template on first render.used_varsfrozenset[str]- Internal. Every variable name the template uses, including in nested tags (the parse-time ``Template.used_variables``). Empty until compiled. The ``Const`` optimization keys its cache only on these.declared_slotstuple[DeclaredSlot, ...]- Internal. The ``<c-slot>`` tags the template declares (static names only), used to check the component against its ``Slots`` schema. Empty until compiled.
Placeholder class
A spot in the output whose final text is supplied at serialize time.
Rendered output is normally text and nested renders, fixed once rendered. A Placeholder marks a position whose content is only known when the whole page is serialized: the <c-js> / <c-css> built-ins render one each, and the dependencies extension fills them with the collected script/style tags via the on_serialize hook.
Attributes
key- What belongs at this spot (e.g. ``"deps:js"``). The serializer reports each occurrence to the ``on_serialize`` hook under this key plus a counter and a private per-serialization identity. An extension that knows the key supplies the text; an occurrence no extension fills serializes to nothing. The private identity keeps cleanup from matching an authored ``<template c-render-id>`` with the same key and counter.
RenderFrame class
Immutable identity needed to traverse and serialize one render frame.
from_context function
from_context(context: CitryContext, is_component_root: bool) -> RenderFrameSnapshot the identity-bearing portion of one live render context.