Tags
Note
Tags, or Air Tag, are explained in the concepts document about 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.
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)
Bases: Transparent
Alias for the Transparent tag; use it if it improves clarity.
Source code in src/air/tags/models/special.py
38 39 40 41 42 | |
Raw
Raw(text_child='', /, **kwargs)
Bases: UnSafeTag, Transparent
Renders raw HTML content without escaping.
Raises:
| Type | Description |
|---|---|
TypeError
|
If non-string content is provided |
Example: Raw('Bold text') # Produces 'Bold text' # Use with other tags Div( P("Safe content"), Raw('
'), P("More safe content") )
Source code in src/air/tags/models/special.py
82 83 84 85 86 87 88 89 90 | |
Children
Children(*children)
Bases: Transparent
Alias for the Transparent tag; use it if it improves clarity.
Source code in src/air/tags/models/special.py
38 39 40 41 42 | |
SafeStr
Bases: UserString
String subclass that bypasses HTML escaping when rendered.
BaseTag
BaseTag(*children, **attributes)
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
children
|
Renderable
|
Renderable objects that become the tag's inner content. |
()
|
attributes
|
AttributeType
|
Attribute names and values applied to the tag element. |
{}
|
Source code in src/air/tags/models/base.py
72 73 74 75 76 77 78 79 80 81 82 | |
__eq__
__eq__(other)
Compare tags by their rendered HTML.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
Object to compare against. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when the rendered HTML matches. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If compared to a non-BaseTag object. |
Source code in src/air/tags/models/base.py
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
__hash__
__hash__()
Return the hash of the rendered HTML representation.
Returns:
| Type | Description |
|---|---|
int
|
Hash derived from the rendered HTML string. |
Source code in src/air/tags/models/base.py
808 809 810 811 812 813 814 | |
__init_subclass__
__init_subclass__()
Register subclasses so they can be restored from serialized data.
Source code in src/air/tags/models/base.py
786 787 788 789 | |
__new__
__new__(*children, **attributes)
Create a tag instance while preventing direct BaseTag instantiation.
Raises:
| Type | Description |
|---|---|
TypeError
|
If code attempts to instantiate BaseTag directly. |
Source code in src/air/tags/models/base.py
84 85 86 87 88 89 90 91 92 93 | |
__repr__
__repr__()
Return a concise representation showing the tag name and summary.
Returns:
| Type | Description |
|---|---|
str
|
A readable string representation for debugging. |
Source code in src/air/tags/models/base.py
299 300 301 302 303 304 305 306 | |
__str__
__str__()
Render the HTML representation of the tag.
Returns:
| Type | Description |
|---|---|
str
|
The rendered HTML string. |
Source code in src/air/tags/models/base.py
291 292 293 294 295 296 297 | |
attrs
cached
property
attrs
Return the formatted HTML attributes string.
Returns:
| Type | Description |
|---|---|
str
|
A string containing formatted attributes prefixed with a space, |
str
|
or an empty string when no attributes are present. |
children
cached
property
children
Render all child nodes into a single HTML string.
Returns:
| Type | Description |
|---|---|
str
|
Concatenated child HTML, or an empty string when no children exist. |
compact_html
cached
property
compact_html
Render the compact-formatted HTML representation of the tag.
Returns:
| Type | Description |
|---|---|
str
|
A minimized HTML string produced by |
compact_render
compact_render()
Render the compact-formatted HTML representation of the tag.
Returns:
| Type | Description |
|---|---|
str
|
A minimized HTML string produced by |
Source code in src/air/tags/models/base.py
232 233 234 235 236 237 238 | |
first_attribute
property
first_attribute
Return the first attribute key-value pair or None when none exist.
Returns:
| Type | Description |
|---|---|
tuple[str, AttributeType] | None
|
The first attribute pair, or None if no attributes are set. |
first_child
property
first_child
Return the first child or None when no children are present.
Returns:
| Type | Description |
|---|---|
Renderable | None
|
The first child value, or None if there are no children. |
from_dict
classmethod
from_dict(source_dict)
Instantiate a tag hierarchy from serialized data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_dict
|
TagDictType
|
The dictionary produced by |
required |
Returns:
| Type | Description |
|---|---|
BaseTag
|
The restored tag instance. |
Source code in src/air/tags/models/base.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | |
from_html
classmethod
from_html(html_source)
Reconstruct the corresponding air-tag tree from the given HTML content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
html_source
|
str
|
HTML content to parse. |
required |
Returns:
| Type | Description |
|---|---|
BaseTag
|
The root air-tag built from the provided HTML content. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If the markup is not valid HTML. |
Source code in src/air/tags/models/base.py
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
from_html_to_source
classmethod
from_html_to_source(html_source)
Reconstruct the instantiable-formatted representation of the tag from the given HTML content.
For converting the corresponding air-tag tree from the given HTML content, into the instantiable-formatted representation of the tag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
html_source
|
str
|
HTML content to parse. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The formatted instantiation call for this tag and its children. |
Source code in src/air/tags/models/base.py
687 688 689 690 691 692 693 694 695 696 697 698 699 700 | |
from_json
classmethod
from_json(source_json)
Instantiate a tag hierarchy from JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_json
|
str
|
The JSON string produced by |
required |
Returns:
| Type | Description |
|---|---|
BaseTag
|
The restored tag instance. |
Source code in src/air/tags/models/base.py
648 649 650 651 652 653 654 655 656 657 658 | |
full_repr
full_repr()
Return an expanded representation including attributes and children.
Returns:
| Type | Description |
|---|---|
str
|
The expanded string representation of the tag hierarchy. |
Source code in src/air/tags/models/base.py
317 318 319 320 321 322 323 324 325 326 327 328 | |
has_attributes
property
has_attributes
Return True when the tag defines one or more attributes.
Returns:
| Type | Description |
|---|---|
bool
|
True when attributes are present; otherwise False. |
has_children
property
has_children
Return True when the tag contains one or more children.
Returns:
| Type | Description |
|---|---|
bool
|
True when children are present; otherwise False. |
html
cached
property
html
Render the HTML representation of the tag.
Returns:
| Type | Description |
|---|---|
str
|
The rendered HTML string. |
is_attribute_free_void_element
property
is_attribute_free_void_element
Check whether the tag has neither attributes nor children.
Returns:
| Type | Description |
|---|---|
bool
|
True when the tag has no attributes and no children. |
last_attribute
property
last_attribute
Return the last attribute key-value pair or None when none exist.
Returns:
| Type | Description |
|---|---|
tuple[str, AttributeType] | None
|
The last attribute pair, or None if no attributes are set. |
last_child
property
last_child
Return the last child or None when no children are present.
Returns:
| Type | Description |
|---|---|
Renderable | None
|
The last child value, or None if there are no children. |
name
property
name
Return the normalized tag name.
Returns:
| Type | Description |
|---|---|
str
|
The lowercase tag name for use in HTML. |
num_of_attributes
property
num_of_attributes
Return the number of defined attributes.
Returns:
| Type | Description |
|---|---|
int
|
The count of attributes. |
num_of_direct_children
property
num_of_direct_children
Return the number of the direct children for an element.
Returns:
| Type | Description |
|---|---|
int
|
The count of children. |
pretty_display_in_the_browser
pretty_display_in_the_browser()
Display pretty-formatted HTML in the browser.
Source code in src/air/tags/models/base.py
260 261 262 | |
pretty_html
cached
property
pretty_html
Render prettified-formatted HTML representation of the tag.
Returns:
| Type | Description |
|---|---|
str
|
The prettified-formatted HTML string, |
pretty_print
pretty_print()
Display pretty-formatted HTML in the console with syntax highlighting.
Source code in src/air/tags/models/base.py
240 241 242 | |
pretty_render
pretty_render(
*, with_body=False, with_head=False, with_doctype=False
)
Render the prettified-formatted HTML representation of the tag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
with_body
|
bool
|
Whether to wrap the HTML inside a |
False
|
with_head
|
bool
|
Whether to generate a |
False
|
with_doctype
|
bool
|
Whether to prefix the output with a doctype declaration. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The pretty-formatted HTML string. |
Source code in src/air/tags/models/base.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
pretty_render_in_the_browser
pretty_render_in_the_browser()
Render pretty-formatted HTML and open the result in a browser tab.
Source code in src/air/tags/models/base.py
209 210 211 | |
pretty_save
pretty_save(*, file_path)
Persist pretty-formatted HTML to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
StrPath
|
Destination path for the pretty HTML file. |
required |
Source code in src/air/tags/models/base.py
252 253 254 255 256 257 258 | |
print_source
classmethod
print_source(html_source)
Display the instantiable-formatted representation of the tag in the console with syntax highlighting.
- Reconstruct the corresponding air-tag tree from the given HTML content.
- Convert air-tag tree into the instantiable-formatted representation of the tag.
- Display it with syntax highlighting inside a styled terminal panel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
html_source
|
str
|
HTML content to parse. |
required |
Source code in src/air/tags/models/base.py
660 661 662 663 664 665 666 667 668 669 670 671 | |
render
render()
Render the HTML representation of the tag.
Returns:
| Type | Description |
|---|---|
str
|
The rendered HTML string. |
Source code in src/air/tags/models/base.py
197 198 199 200 201 202 203 | |
render_in_the_browser
render_in_the_browser()
Render the tag and open the result in a browser tab.
Source code in src/air/tags/models/base.py
205 206 207 | |
save
save(*, file_path)
Persist the rendered HTML to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
StrPath
|
Destination path for the HTML file. |
required |
Source code in src/air/tags/models/base.py
244 245 246 247 248 249 250 | |
save_source
classmethod
save_source(*, file_path, html_source)
Save the instantiable-formatted representation of the tag to disk.
- Reconstruct the corresponding air-tag tree from the given HTML content.
- Convert air-tag tree into the instantiable-formatted representation of the tag.
- Save the Python expression that reconstructs this tag to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
html_source
|
str
|
HTML content to parse. |
required |
file_path
|
StrPath
|
Destination path for the .py file. |
required |
Source code in src/air/tags/models/base.py
673 674 675 676 677 678 679 680 681 682 683 684 685 | |
tag_id
property
tag_id
Return the tag's id_ attribute when present.
Returns:
| Type | Description |
|---|---|
AttributeType | None
|
The |
to_dict
to_dict()
Convert the tag into a JSON-serializable dictionary.
Returns:
| Type | Description |
|---|---|
TagDictType
|
A mapping with the tag name, attributes, and serialized children. |
Source code in src/air/tags/models/base.py
578 579 580 581 582 583 584 585 586 587 588 | |
to_json
to_json(*, indent_size=None)
Serialize the tag to JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indent_size
|
int | None
|
Indentation width to use for pretty-printing. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The JSON string representation of the tag. |
Source code in src/air/tags/models/base.py
598 599 600 601 602 603 604 605 606 607 | |
to_pretty_dict
to_pretty_dict(
*,
max_width=170,
max_length=7,
max_depth=4,
max_string=25,
expand_all=False,
)
Produce a human-friendly mapping view of the tag.
Returns:
| Type | Description |
|---|---|
str
|
A formatted string produced by the rich pretty printer when available, |
str
|
otherwise the standard string form of the mapping. |
Source code in src/air/tags/models/base.py
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |
to_pretty_json
to_pretty_json()
Serialize the tag to formatted JSON.
Returns:
| Type | Description |
|---|---|
str
|
The indented JSON string representation of the tag. |
Source code in src/air/tags/models/base.py
609 610 611 612 613 614 615 | |
to_source
to_source()
Return a Python expression that reconstructs this tag.
Convert this air-tag into the instantiable-formatted representation of the tag.
Returns:
| Type | Description |
|---|---|
str
|
The formatted instantiation call for this tag and its children. |
Source code in src/air/tags/models/base.py
330 331 332 333 334 335 336 337 338 | |