Skip to content

Element

Immutable descriptor for a single node in PythonNative's virtual view tree. Element instances are produced by the component factories and consumed by the Reconciler.

You almost never construct an Element by hand; the factory functions exist precisely so app code stays in plain Python.

Lightweight element descriptors for the virtual view tree.

An Element is an immutable description of a UI node, analogous to a React element. It captures a type (name string or component function), a props dict, and an ordered list of children without creating any native platform objects. The reconciler consumes these trees to determine what native views must be created, updated, or removed.

Elements are produced by built-in factories such as Text, Button, and Column, or by calling functions decorated with component.

Example
from pythonnative import Element

node = Element("Text", {"text": "Hello"}, [])

Classes:

Name Description
Element

Immutable description of a single UI node.

Element

Element(type_name: Union[str, Any], props: Dict[str, Any], children: List[Element], key: Optional[str] = None)

Immutable description of a single UI node.

Built-in elements use a string type ("Text", "Button", "Column", etc.); function components use the function itself as type. The reconciler dispatches on this distinction when mounting the tree.

Attributes:

Name Type Description
type

A string for built-in elements or a callable for function components decorated with component.

props

Dict of properties passed to the native handler or component function.

children

Ordered list of child Element instances.

key

Optional stable identity used by the reconciler when diffing keyed lists. Two elements with the same type and key are treated as the same logical node across renders.

Next steps