Skip to content

Tags

Note

Tags, or Air Tag, are explained in the [concepts document about tags][air-tags].

In the spirit of helping our users, every Air Tag has copious documentation—enough that sometimes it breaks the documentation build process. Therefore, Air Tag that directly correspond to their HTML equivalents can be found in smaller, easier-to-compile pages.

  • [HTML Air Tags A-D][tags-a-d]
  • [HTML Air Tags E-M][tags-e-m]
  • [HTML Air Tags N-S][tags-n-s]
  • [HTML Air Tags T-Z][tags-t-z]

What remains on this page are core Air Tag that either have great utility (Raw and Children come to mind), or are base classes for other tags.

Tag

Tag(*children, **kwargs)

Base tag for all other tags.

Sets four attributes, name, module, children, and attrs. These are important for Starlette view responses, as nested objects get auto-serialized to JSON and need to be rebuilt. With the values of these attributes, the object reconstruction can occur.

kwargs: Keyword arguments transformed into tag attributes.
Source code in src/air/tags/models/base.py
21
22
23
24
25
26
27
28
29
def __init__(self, *children: Any, **kwargs: str | int | float | bool):
    """
    Args:
        children: Tags, strings, or other rendered content.
        kwargs: Keyword arguments transformed into tag attributes.
    """
    self._name = self.__class__.__name__
    self._module = self.__class__.__module__
    self._children, self._attrs = children, kwargs

Raw

Raw(*args, **kwargs)

Bases: Tag

Renders raw HTML content without escaping.

Parameters:

Name Type Description Default
args Any

A single string containing raw text to render

()

Raises:

Type Description
TypeError

If non-string content is provided

ValueError

If multiple arguments are provided

Example:

# Produces '<strong>Bold</strong> text'
Raw('<strong>Bold</strong> text')

# Use with other tags
Div(
    P("Safe content"),
    Raw('<hr class="divider">'),
    P("More safe content")
)

Parameters:

Name Type Description Default
*args Any

Should be exactly one string argument

()
**kwargs str | int | float | bool

Ignored (for consistency with Tag interface)

{}
Source code in src/air/tags/models/special.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def __init__(self, *args: Any, **kwargs: str | int | float | bool):
    """Initialize Raw with a single string argument.

    Args:
        *args: Should be exactly one string argument
        **kwargs: Ignored (for consistency with Tag interface)
    """
    if len(args) > 1:
        msg = "Raw accepts only one string argument"
        raise ValueError(msg)

    raw_string: str = args[0] if args else ""

    if not isinstance(raw_string, str):
        msg = "Raw only accepts string content"
        raise TypeError(msg)

    super().__init__(raw_string)

render

render()

Render the string without escaping.

Source code in src/air/tags/models/special.py
57
58
59
def render(self) -> str:
    """Render the string without escaping."""
    return self._children[0] if self._children else ""

Children

Children(*children, **kwargs)

Bases: Tag

Source code in src/air/tags/models/base.py
21
22
23
24
25
26
27
28
29
def __init__(self, *children: Any, **kwargs: str | int | float | bool):
    """
    Args:
        children: Tags, strings, or other rendered content.
        kwargs: Keyword arguments transformed into tag attributes.
    """
    self._name = self.__class__.__name__
    self._module = self.__class__.__module__
    self._children, self._attrs = children, kwargs

SafeStr

Bases: str

A string subclass that doesn't trigger html.escape() when called by Tag.render()

Example

sample = SafeStr('Hello, world')