API Reference
animaid
Animaid - Create beautiful HTML from Python data structures.
- Quick Start:
>>> from animaid import HTMLString, HTMLList, HTMLDict
# Styled text - chain methods for easy styling >>> HTMLString(“Hello”).bold().red().render() ‘<span style=”font-weight: bold; color: red”>Hello</span>’
# Styled lists - use presets for common patterns >>> HTMLList([“Apple”, “Banana”, “Cherry”]).pills().render()
# Styled dicts - display key-value data beautifully >>> HTMLDict({“name”: “Alice”, “age”: 30}).card().render()
- Beginner Tips:
Use method shortcuts: .bold(), .red(), .large() instead of .styled(…)
Use presets: .cards(), .pills(), .badge(), .highlight() for common styles
Chain methods: HTMLString(“Hi”).bold().red().large()
Methods modify in-place and return self for chaining
- class animaid.AlignContent(value)[source]
Bases:
EnumCSS align-content values for multi-line flex/grid containers.
- CENTER = 'center'
- END = 'end'
- SPACE_AROUND = 'space-around'
- SPACE_BETWEEN = 'space-between'
- SPACE_EVENLY = 'space-evenly'
- START = 'start'
- STRETCH = 'stretch'
- class animaid.AlignItems(value)[source]
Bases:
EnumCSS align-items values.
- BASELINE = 'baseline'
- CENTER = 'center'
- END = 'end'
- FLEX_END = 'flex-end'
- FLEX_START = 'flex-start'
- START = 'start'
- STRETCH = 'stretch'
- class animaid.App(port: int = 8200, title: str = 'AnimAID', auto_open: bool = True, window: WindowConfig | None = None, width: int | None = None, height: int | None = None, theme: str = 'light')[source]
Bases:
objectA Tkinter-like interactive GUI environment using HTML.
The browser becomes the display surface, and AnimAID objects become widgets that can be added, updated, and removed programmatically with real-time visual feedback.
Examples
>>> from animaid import App, HTMLString >>> app = App() >>> app.run() # Starts server, opens browser >>> app.add(HTMLString("Hello").bold) 'string_1' >>> app.add(HTMLString("World").italic) 'string_2' >>> app.stop()
# Context manager support >>> with App() as app: … app.add(HTMLString(“Temporary display”)) # Server stops when context exits
# With window configuration >>> with App(title=”Dashboard”, theme=”dark”) as app: … app.window.set_title(“Loading…”) … app.add(HTMLString(“Content”))
Note
The class was previously named
Animate. That name still works but is deprecated. Please useAppinstead.- add(item: HTMLObject | str, id: str | None = None) str[source]
Add an item to the display.
- Parameters:
item – An HTMLObject or string to display.
id – Optional custom ID for the item. Auto-generated if not provided.
- Returns:
The ID of the added item.
- clear(item_or_id: HTMLObject | str) bool[source]
Remove an item by ID or by object reference.
- Parameters:
item_or_id – The ID of the item to remove, or the item object itself.
- Returns:
True if the item was found and removed, False otherwise.
- get(id: str) Any[source]
Get an item by ID.
- Parameters:
id – The ID of the item to retrieve.
- Returns:
The item if found, None otherwise.
- get_events() list[InputEvent][source]
Get all pending events without blocking.
- Returns:
A list of all pending InputEvent objects. Empty list if none.
Examples
>>> events = anim.get_events() >>> for event in events: ... print(f"Event: {event.event_type} on {event.id}")
- get_full_state() list[dict[str, str]][source]
Get the full state as a list of rendered items.
- Returns:
…, “html”: …} dicts.
- Return type:
A list of {“id”
- handle_input_event(message: dict[str, Any]) None[source]
Handle an input event from the browser.
This is called by the server when an input event is received. It updates the item’s internal value, calls registered callbacks, and queues the event for polling.
- Parameters:
message – The event message containing id, event type, and value.
- handle_window_event(message: dict[str, Any]) None[source]
Handle a window event from the browser.
This is called by the server when a window event is received.
- Parameters:
message – The event message containing event type and data.
- items() list[tuple[str, Any]][source]
Get a copy of all items.
- Returns:
A list of (id, item) tuples.
- refresh(id: str) bool[source]
Re-render and broadcast a single item.
Use this to manually refresh an item after external changes.
- Parameters:
id – The ID of the item to refresh.
- Returns:
True if item was found and refreshed, False otherwise.
- refresh_all() None[source]
Re-render and broadcast all items.
Use this to manually refresh all items after external changes.
- register_connection(websocket: Any) None[source]
Register a WebSocket connection.
This is called by the server when a new client connects.
- Parameters:
websocket – The WebSocket connection to register.
- remove(item_or_id: HTMLObject | str) bool[source]
Remove an item by ID or by object reference.
- Parameters:
item_or_id – The ID of the item to remove, or the item object itself.
- Returns:
True if the item was found and removed, False otherwise.
- run() App[source]
Start the server in a background thread and open the browser.
- Returns:
Self for method chaining.
- unregister_connection(websocket: Any) None[source]
Unregister a WebSocket connection.
This is called by the server when a client disconnects.
- Parameters:
websocket – The WebSocket connection to unregister.
- update(id: str, item: HTMLObject | str) bool[source]
Update an existing item by ID.
- Parameters:
id – The ID of the item to update.
item – The new content to display.
- Returns:
True if the item was found and updated, False otherwise.
- wait_for_event(timeout: float | None = None) InputEvent | None[source]
Block until an input event occurs.
- Parameters:
timeout – Maximum time to wait in seconds. None means wait forever.
- Returns:
The InputEvent if one occurred, None if timeout expired.
Examples
>>> event = anim.wait_for_event(timeout=1.0) >>> if event and event.event_type == "click": ... print(f"Button {event.id} was clicked!")
- class animaid.Border(width: Size | str | int | float = '1px', style: BorderStyle | str = BorderStyle.SOLID, color: Color | str = 'black')[source]
Bases:
CSSValueRepresents a CSS border value (width + style + color).
Examples
>>> Border(Size.px(1), BorderStyle.SOLID, Color.black) Border('1px solid black') >>> Border.solid(2, "red") Border('2px solid red') >>> Border().width(Size.px(2)).dashed().color(Color.blue) Border('2px dashed blue')
- classmethod dashed(width: Size | str | int | float = 1, color: Color | str = 'black') Border[source]
Create a dashed border.
- Parameters:
width – Border width (default 1px)
color – Border color (default black)
Examples
>>> Border.dashed() Border('1px dashed black') >>> Border.dashed(2, "blue") Border('2px dashed blue')
- classmethod dotted(width: Size | str | int | float = 1, color: Color | str = 'black') Border[source]
Create a dotted border.
- Parameters:
width – Border width (default 1px)
color – Border color (default black)
Examples
>>> Border.dotted() Border('1px dotted black')
- classmethod double(width: Size | str | int | float = 3, color: Color | str = 'black') Border[source]
Create a double border.
- Parameters:
width – Border width (default 3px - minimum for double to show)
color – Border color (default black)
Examples
>>> Border.double() Border('3px double black')
- classmethod medium(color: Color | str = 'black', style: BorderStyle | str = BorderStyle.SOLID) Border[source]
Create a medium border (2px).
- Parameters:
color – Border color (default black)
style – Border style (default solid)
Examples
>>> Border.medium() Border('2px solid black')
- classmethod none() Border[source]
Create a border with no visible style.
Examples
>>> Border.none() Border('1px none black')
- classmethod solid(width: Size | str | int | float = 1, color: Color | str = 'black') Border[source]
Create a solid border.
- Parameters:
width – Border width (default 1px)
color – Border color (default black)
Examples
>>> Border.solid() Border('1px solid black') >>> Border.solid(2, "red") Border('2px solid red')
- style(s: BorderStyle | str) Border[source]
Return a new Border with the specified style.
- property style_value: BorderStyle
The border style.
- classmethod thick(color: Color | str = 'black', style: BorderStyle | str = BorderStyle.SOLID) Border[source]
Create a thick border (4px).
- Parameters:
color – Border color (default black)
style – Border style (default solid)
Examples
>>> Border.thick() Border('4px solid black') >>> Border.thick("navy") Border('4px solid navy')
- classmethod thin(color: Color | str = 'black', style: BorderStyle | str = BorderStyle.SOLID) Border[source]
Create a thin border (1px).
- Parameters:
color – Border color (default black)
style – Border style (default solid)
Examples
>>> Border.thin() Border('1px solid black') >>> Border.thin("red") Border('1px solid red')
- class animaid.BorderStyle(value)[source]
Bases:
EnumCSS border-style values.
- DASHED = 'dashed'
- DOTTED = 'dotted'
- DOUBLE = 'double'
- GROOVE = 'groove'
- HIDDEN = 'hidden'
- INSET = 'inset'
- NONE = 'none'
- OUTSET = 'outset'
- RIDGE = 'ridge'
- SOLID = 'solid'
- animaid.Button
alias of
HTMLButton
- class animaid.CSSValue[source]
Bases:
ABCBase class for all CSS value types.
All CSS value classes must implement to_css() which returns the CSS string representation. They also support str() conversion for backward compatibility.
- animaid.Checkbox
alias of
HTMLCheckbox
- class animaid.Color(value: str)[source]
Bases:
CSSValueRepresents a CSS color value.
Supports named colors, hex codes, rgb(), rgba(), hsl(), and hsla().
Examples
>>> Color.red Color('red') >>> Color.hex("#2563eb") Color('#2563eb') >>> Color.rgb(255, 128, 0) Color('rgb(255, 128, 0)') >>> Color.rgba(255, 128, 0, 0.5) Color('rgba(255, 128, 0, 0.5)')
- NAMED_COLORS: ClassVar[set[str]] = {'aqua', 'black', 'blue', 'brown', 'currentcolor', 'cyan', 'fuchsia', 'gray', 'green', 'grey', 'inherit', 'initial', 'lime', 'magenta', 'maroon', 'navy', 'olive', 'orange', 'pink', 'purple', 'red', 'silver', 'teal', 'transparent', 'unset', 'white', 'yellow'}
- classmethod hex(code: str) Color[source]
Create a color from a hex code.
- Parameters:
code – Hex code with or without ‘#’ prefix
- classmethod hsl(h: int, s: int, lightness: int) Color[source]
Create an HSL color.
- Parameters:
h – Hue (0-360)
s – Saturation (0-100)
lightness – Lightness (0-100)
- classmethod hsla(h: int, s: int, lightness: int, a: float) Color[source]
Create an HSLA color with alpha.
- Parameters:
h – Hue (0-360)
s – Saturation (0-100)
lightness – Lightness (0-100)
a – Alpha (0.0-1.0)
- classmethod rgb(r: int, g: int, b: int) Color[source]
Create an RGB color.
- Parameters:
r – Red component (0-255)
g – Green component (0-255)
b – Blue component (0-255)
- animaid.Column
alias of
HTMLColumn
- animaid.Container
alias of
HTMLContainer
- class animaid.Display(value)[source]
Bases:
EnumCSS display values.
- BLOCK = 'block'
- CONTENTS = 'contents'
- FLEX = 'flex'
- GRID = 'grid'
- INLINE = 'inline'
- INLINE_BLOCK = 'inline-block'
- INLINE_FLEX = 'inline-flex'
- INLINE_GRID = 'inline-grid'
- NONE = 'none'
- animaid.Divider
alias of
HTMLDivider
- class animaid.DividerStyle(value)[source]
Bases:
EnumDivider line styles (maps to border-style).
- DASHED = 'dashed'
- DOTTED = 'dotted'
- DOUBLE = 'double'
- SOLID = 'solid'
- class animaid.FlexDirection(value)[source]
Bases:
EnumCSS flex-direction values.
- COLUMN = 'column'
- COLUMN_REVERSE = 'column-reverse'
- ROW = 'row'
- ROW_REVERSE = 'row-reverse'
- class animaid.FlexWrap(value)[source]
Bases:
EnumCSS flex-wrap values.
- NOWRAP = 'nowrap'
- WRAP = 'wrap'
- WRAP_REVERSE = 'wrap-reverse'
- class animaid.FontStyle(value)[source]
Bases:
EnumCSS font-style values.
- ITALIC = 'italic'
- NORMAL = 'normal'
- OBLIQUE = 'oblique'
- class animaid.FontWeight(value)[source]
Bases:
EnumCSS font-weight values.
- BOLD = 'bold'
- BOLDER = 'bolder'
- LIGHTER = 'lighter'
- NORMAL = 'normal'
- W100 = '100'
- W200 = '200'
- W300 = '300'
- W400 = '400'
- W500 = '500'
- W600 = '600'
- W700 = '700'
- W800 = '800'
- W900 = '900'
- class animaid.GridAutoFlow(value)[source]
Bases:
EnumCSS grid-auto-flow values.
- COLUMN = 'column'
- COLUMN_DENSE = 'column dense'
- ROW = 'row'
- ROW_DENSE = 'row dense'
- class animaid.HTMLButton(label: str)[source]
Bases:
objectA clickable button widget for use with App.
Buttons support click callbacks and styled presets for common use cases.
Examples
>>> button = HTMLButton("Click Me") >>> button = HTMLButton("Submit").primary() >>> button = HTMLButton("Delete").danger().on_click(handle_delete)
# With App >>> with App() as app: … def on_click(): … print(“Button clicked!”) … app.add(HTMLButton(“Click”).on_click(on_click))
- add_class(*class_names: str) HTMLButton[source]
Return a copy with additional CSS classes.
- Parameters:
*class_names – CSS class names to add.
- Returns:
A new instance with the additional classes.
- danger() HTMLButton[source]
Return a copy styled as a danger button (red).
- Returns:
A new instance with danger styling.
- large() HTMLButton[source]
Return a copy styled with larger text and padding.
- Returns:
A new instance with large styling.
- on_click(callback: Callable[[], None]) HTMLButton[source]
Register a callback for button clicks.
The callback is called whenever the button is clicked in the browser. The callback takes no arguments.
- Parameters:
callback – A function to call when the button is clicked.
- Returns:
Self for method chaining.
Examples
>>> def handle_click(): ... print("Button was clicked!") >>> button = HTMLButton("Click Me").on_click(handle_click)
- primary() HTMLButton[source]
Return a copy styled as a primary button (blue).
- Returns:
A new instance with primary styling.
- render() str[source]
Return HTML representation of this button.
- Returns:
A string containing valid HTML for the button.
- small() HTMLButton[source]
Return a copy styled with smaller text and padding.
- Returns:
A new instance with small styling.
- styled(**styles: str) HTMLButton[source]
Return a copy with additional inline styles.
Style names use Python convention (underscores) and are converted to CSS convention (hyphens) automatically.
- Parameters:
**styles – CSS property-value pairs, e.g., font_size=”16px”
- Returns:
A new instance with the combined styles.
- success() HTMLButton[source]
Return a copy styled as a success button (green).
- Returns:
A new instance with success styling.
- warning() HTMLButton[source]
Return a copy styled as a warning button (orange).
- Returns:
A new instance with warning styling.
- class animaid.HTMLCard(children: list[Any] | None = None, *, title: str | None = None, **styles: str | CSSValue)[source]
Bases:
HTMLContainerA visual card container for grouping related content.
HTMLCard provides a bordered/shadowed container with optional title, commonly used for dashboard panels, info cards, and grouped content.
Examples
>>> from animaid import HTMLCard, HTMLString >>> card = HTMLCard([ ... HTMLString("User Profile").bold(), ... HTMLString("Name: Alice"), ... ])
>>> # Card with title >>> card = HTMLCard( ... title="User Profile", ... children=[HTMLString("Name: Alice")], ... )
>>> # Styled card >>> card = HTMLCard(content).shadow().rounded() >>> card = HTMLCard(content).elevated() # Preset with larger shadow
- background(color: Color | str) HTMLCard[source]
Set the background color.
- Parameters:
color – Background color.
- Returns:
Self for method chaining.
- bordered(color: Color | str = '#e5e7eb') HTMLCard[source]
Add a border to the card.
- Parameters:
color – Border color.
- Returns:
Self for method chaining.
- default() HTMLCard[source]
Apply default card styling (light border, subtle shadow).
- Returns:
Self for method chaining.
- elevated() HTMLCard[source]
Apply elevated card styling (prominent shadow).
- Returns:
Self for method chaining.
- filled(color: Color | str = '#f9fafb') HTMLCard[source]
Apply filled card styling with background color.
- Parameters:
color – Background color.
- Returns:
Self for method chaining.
- flat() HTMLCard[source]
Apply flat card styling (no border or shadow).
- Returns:
Self for method chaining.
- no_rounded() HTMLCard[source]
Remove border radius (sharp corners).
- Returns:
Self for method chaining.
- outlined() HTMLCard[source]
Apply outlined card styling (border only, no shadow).
- Returns:
Self for method chaining.
- render() str[source]
Render the card with optional title.
- Returns:
HTML string with card structure.
- rounded(size: RadiusSize | str = RadiusSize.DEFAULT) HTMLCard[source]
Set the border radius (rounded corners).
- Parameters:
size – RadiusSize enum or CSS radius string.
- Returns:
Self for method chaining.
Example
>>> card.rounded() # Default rounding >>> card.rounded(RadiusSize.LG) # More rounded
- set_title(text: str | None) HTMLCard[source]
Set or change the card title.
- Parameters:
text – Title text, or None to remove title.
- Returns:
Self for method chaining.
- shadow(size: ShadowSize | str = ShadowSize.DEFAULT) HTMLCard[source]
Add a box shadow to the card.
- Parameters:
size – ShadowSize enum or CSS shadow string.
- Returns:
Self for method chaining.
Example
>>> card.shadow() # Default shadow >>> card.shadow(ShadowSize.LG) # Larger shadow
- class animaid.HTMLCheckbox(label: str, checked: bool = False)[source]
Bases:
objectA checkbox widget with two-way boolean binding.
The checked property is automatically synced from the browser when the user toggles the checkbox.
Examples
>>> checkbox = HTMLCheckbox("Accept terms", checked=False) >>> checkbox = HTMLCheckbox("Enable feature").on_change(handle_change)
# With App - two-way binding >>> with App() as app: … terms = HTMLCheckbox(“I accept the terms”) … app.add(terms) … # Later, read the current value: … print(terms.checked) # True/False synced from browser
- add_class(*class_names: str) HTMLCheckbox[source]
Return a copy with additional CSS classes.
- Parameters:
*class_names – CSS class names to add.
- Returns:
A new instance with the additional classes.
- property checked: bool
Get the current checked state (thread-safe).
The value is automatically synced from the browser when the user toggles the checkbox.
- Returns:
True if checked, False otherwise.
- large() HTMLCheckbox[source]
Return a copy with larger text and checkbox.
- Returns:
A new instance with large styling.
- on_change(callback: Callable[[bool], None]) HTMLCheckbox[source]
Register a callback for state changes.
The callback is called when the user toggles the checkbox.
- Parameters:
callback – A function that takes the new checked state as argument.
- Returns:
Self for method chaining.
Examples
>>> def handle_change(checked): ... print(f"Checkbox is now: {'checked' if checked else 'unchecked'}") >>> checkbox = HTMLCheckbox("Enable").on_change(handle_change)
- render() str[source]
Return HTML representation of this checkbox.
- Returns:
A string containing valid HTML for the checkbox.
- small() HTMLCheckbox[source]
Return a copy with smaller text and checkbox.
- Returns:
A new instance with small styling.
- styled(**styles: str) HTMLCheckbox[source]
Return a copy with additional inline styles.
- Parameters:
**styles – CSS property-value pairs.
- Returns:
A new instance with the combined styles.
- class animaid.HTMLColumn(children: list[Any] | None = None, **styles: str | CSSValue)[source]
Bases:
HTMLContainerA vertical flex container for arranging items in a column.
HTMLColumn uses CSS flexbox with flex-direction: column to arrange children vertically. It provides methods for controlling alignment, justification, and spacing.
Examples
>>> from animaid import HTMLColumn, HTMLString >>> column = HTMLColumn([ ... HTMLString("Title").bold().xl(), ... HTMLString("Subtitle").muted(), ... HTMLString("Content here..."), ... ]).gap(8)
>>> # Form-style layout >>> column = HTMLColumn(form_fields).form()
>>> # Stacked layout with consistent spacing >>> column = HTMLColumn(items).stack()
- add_class(*class_names: str) HTMLColumn[source]
Add CSS classes.
- Parameters:
*class_names – CSS class names to add.
- Returns:
Self for method chaining.
- align(value: AlignItems | str) HTMLColumn[source]
Set horizontal alignment of items within the column.
- Parameters:
value – AlignItems enum or CSS string (start, center, end, stretch, baseline).
- Returns:
Self for method chaining.
Example
>>> column.align(AlignItems.CENTER) >>> column.align("center") # Also works
- centered() HTMLColumn[source]
Center all items both horizontally and vertically.
- Returns:
Self for method chaining.
- end() HTMLColumn[source]
Align items to the end (bottom).
- Returns:
Self for method chaining.
- form() HTMLColumn[source]
Apply form-style layout preset.
Creates a column with appropriate spacing for form fields and full-width stretching.
- Returns:
Self for method chaining.
- gap(size: Size | str | int) HTMLColumn[source]
Set the gap between child elements.
- Parameters:
size – Gap size.
- Returns:
Self for method chaining.
- height(size: Size | str | int) HTMLColumn[source]
Set container height.
- Parameters:
size – Height.
- Returns:
Self for method chaining.
- justify(value: JustifyContent | str) HTMLColumn[source]
Set vertical distribution of items within the column.
- Parameters:
value – JustifyContent enum or CSS string (start, center, end, space-between, space-around, space-evenly).
- Returns:
Self for method chaining.
Example
>>> column.justify(JustifyContent.SPACE_BETWEEN) >>> column.justify("space-between") # Also works
- margin(size: Spacing | Size | str | int) HTMLColumn[source]
Set external margin.
- Parameters:
size – Margin size.
- Returns:
Self for method chaining.
- padding(size: Spacing | Size | str | int) HTMLColumn[source]
Set internal padding.
- Parameters:
size – Padding size.
- Returns:
Self for method chaining.
- reverse() HTMLColumn[source]
Reverse the order of items (bottom to top).
- Returns:
Self for method chaining.
- spaced() HTMLColumn[source]
Distribute items with space between them.
- Returns:
Self for method chaining.
- stack() HTMLColumn[source]
Apply simple stacked layout preset.
Creates a column with consistent 8px gap between items.
- Returns:
Self for method chaining.
- start() HTMLColumn[source]
Align items to the start (top).
- Returns:
Self for method chaining.
- stretch() HTMLColumn[source]
Stretch items to fill the column width.
- Returns:
Self for method chaining.
- styled(**styles: str | CSSValue) HTMLColumn[source]
Apply additional inline styles.
- Parameters:
**styles – CSS property-value pairs.
- Returns:
Self for method chaining.
- width(size: Size | str | int) HTMLColumn[source]
Set container width.
- Parameters:
size – Width.
- Returns:
Self for method chaining.
- wrap(value: FlexWrap | str = FlexWrap.WRAP) HTMLColumn[source]
Allow items to wrap to the next column (rarely used).
- Parameters:
value – FlexWrap enum or CSS string.
- Returns:
Self for method chaining.
- class animaid.HTMLContainer(children: list[Any] | None = None, **styles: str | CSSValue)[source]
Bases:
HTMLObjectBase class for all container widgets.
Containers hold child elements and provide layout capabilities. They can be nested and support reactive updates when children change.
Example
>>> container = HTMLContainer([HTMLString("Hello"), HTMLString("World")]) >>> container.render() '<div>...</div>'
- add_class(*class_names: str) HTMLContainer[source]
Add CSS classes.
- Parameters:
*class_names – CSS class names to add.
- Returns:
Self for method chaining.
- append(child: Any) HTMLContainer[source]
Add a child element and trigger update.
- Parameters:
child – The element to add.
- Returns:
Self for method chaining.
- clear() HTMLContainer[source]
Remove all children.
- Returns:
Self for method chaining.
- expand() HTMLContainer[source]
Make this container expand to fill available space in a flex parent.
Use this on a child container to make it grow and fill remaining space.
- Returns:
Self for method chaining.
Example
>>> # Header, expandable content, footer layout >>> layout = HTMLColumn([ ... HTMLString("Header"), ... HTMLColumn([HTMLString("Content")]).expand(), ... HTMLString("Footer"), ... ]).full_height()
- extend(children: list[Any]) HTMLContainer[source]
Add multiple child elements.
- Parameters:
children – List of elements to add.
- Returns:
Self for method chaining.
- full_height() HTMLContainer[source]
Expand container to fill the full viewport height.
- Returns:
Self for method chaining.
Example
>>> column = HTMLColumn([...]).full_height()
- full_screen() HTMLContainer[source]
Expand container to fill the entire viewport (width and height).
- Returns:
Self for method chaining.
Example
>>> layout = HTMLColumn([...]).full_screen()
- full_width() HTMLContainer[source]
Expand container to fill the full width of its parent.
- Returns:
Self for method chaining.
Example
>>> row = HTMLRow([...]).full_width()
- gap(size: Size | str | int) HTMLContainer[source]
Set the gap between child elements.
- Parameters:
size – Gap size (Size, CSS string like “10px”, or int pixels).
- Returns:
Self for method chaining.
- height(size: Size | str | int) HTMLContainer[source]
Set container height.
- Parameters:
size – Height (Size, CSS string, or int pixels).
- Returns:
Self for method chaining.
- insert(index: int, child: Any) HTMLContainer[source]
Insert a child at a specific position.
- Parameters:
index – Position to insert at.
child – The element to insert.
- Returns:
Self for method chaining.
- margin(size: Spacing | Size | str | int) HTMLContainer[source]
Set external margin.
- Parameters:
size – Margin size (Spacing, Size, CSS string, or int pixels).
- Returns:
Self for method chaining.
- max_height(size: Size | str | int) HTMLContainer[source]
Set maximum container height.
- Parameters:
size – Maximum height (Size, CSS string, or int pixels).
- Returns:
Self for method chaining.
- max_width(size: Size | str | int) HTMLContainer[source]
Set maximum container width.
- Parameters:
size – Maximum width (Size, CSS string, or int pixels).
- Returns:
Self for method chaining.
- min_height(size: Size | str | int) HTMLContainer[source]
Set minimum container height.
- Parameters:
size – Minimum height (Size, CSS string, or int pixels).
- Returns:
Self for method chaining.
- min_width(size: Size | str | int) HTMLContainer[source]
Set minimum container width.
- Parameters:
size – Minimum width (Size, CSS string, or int pixels).
- Returns:
Self for method chaining.
- padding(size: Spacing | Size | str | int) HTMLContainer[source]
Set internal padding.
- Parameters:
size – Padding size (Spacing, Size, CSS string, or int pixels).
- Returns:
Self for method chaining.
- pop(index: int = -1) Any[source]
Remove and return a child at the given position.
- Parameters:
index – Position to remove from (default: last).
- Returns:
The removed child element.
- remove(child: Any) HTMLContainer[source]
Remove a child element.
- Parameters:
child – The element to remove.
- Returns:
Self for method chaining.
- remove_class(*class_names: str) HTMLContainer[source]
Remove CSS classes.
- Parameters:
*class_names – CSS class names to remove.
- Returns:
Self for method chaining.
- render() str[source]
Render the container and all children.
- Returns:
HTML string with container div and rendered children.
- styled(**styles: str | CSSValue) HTMLContainer[source]
Apply additional inline styles.
- Parameters:
**styles – CSS property-value pairs (underscores become hyphens).
- Returns:
Self for method chaining.
- class animaid.HTMLDict(data: dict[Any, Any] | None = None, **styles: str | CSSValue)[source]
Bases:
HTMLObject,dictA dict subclass that renders as styled HTML.
HTMLDict behaves like a regular Python dict but includes methods for applying CSS styles and rendering to HTML. All styling methods modify the object in-place and return self for method chaining. Supports definition list, table, and flexbox layouts.
Examples
>>> d = HTMLDict({"name": "Alice", "age": 30}) >>> d.render() '<dl><dt>name</dt><dd>Alice</dd><dt>age</dt><dd>30</dd></dl>'
>>> d.as_table().render() '<table><tr><td>name</td><td>Alice</td></tr>...</table>'
>>> d.key_bold().key_color("blue").render() '<dl><dt style="font-weight: bold; color: blue">name</dt>...'
- add_class(*class_names: str) Self[source]
Add CSS classes on the container in-place.
- Parameters:
*class_names – CSS class names to add.
- Returns:
Self for method chaining.
- add_key_class(*class_names: str) Self[source]
Add CSS classes to keys in-place.
- Parameters:
*class_names – CSS class names to add to keys.
- add_value_class(*class_names: str) Self[source]
Add CSS classes to values in-place.
- Parameters:
*class_names – CSS class names to add to values.
- background(value: Color | str) Self[source]
Apply container background in-place.
- Parameters:
value – CSS color value (e.g., “white”, Color.white, Color.hex(“#fff”)).
- border(value: Border | str) Self[source]
Apply container border in-place.
- Parameters:
value – CSS border value (e.g., “1px solid black”, Border.solid()).
- border_radius(value: Size | str | int | float) Self[source]
Apply rounded container corners in-place.
- Parameters:
value – CSS border-radius value (e.g., “5px”, Size.px(5), Size.percent(50)).
- bordered() Self[source]
Apply bordered cells style in-place.
Each key-value pair has visible borders.
- card() Self[source]
Apply card style with shadow and rounded corners in-place.
Creates a visually appealing card-style display.
- color(value: Color | str) Self[source]
Apply text color in-place.
- Parameters:
value – CSS color value (e.g., “black”, Color.black).
- compact() Self[source]
Apply compact spacing style in-place.
Minimal padding and spacing for dense displays.
- entry_separator(value: Border | str) Self[source]
Apply separator between entries (border) in-place.
- Parameters:
value – CSS border value for separator (e.g., “1px solid gray”).
- gap(value: Size | str | int | float) Self[source]
Apply gap between entries in-place.
- Parameters:
value – CSS gap value (e.g., “10px”, Size.px(10), Size.rem(1)).
- grid(columns: int = 2) Self[source]
Apply grid layout in-place.
- Parameters:
columns – Number of key-value pairs per row.
- key_background(value: Color | str) Self[source]
Apply background color to keys in-place.
- Parameters:
value – CSS color value (e.g., “yellow”, Color.yellow).
- key_color(value: Color | str) Self[source]
Apply color to keys in-place.
- Parameters:
value – CSS color value (e.g., “blue”, Color.blue, Color.hex(“#00f”)).
- key_padding(value: Spacing | str | int | float) Self[source]
Apply padding to keys in-place.
- Parameters:
value – CSS padding value (e.g., “10px”, Size.px(10), Spacing.all(10)).
- key_styled(**styles: str | CSSValue) Self[source]
Apply styles to keys in-place.
- Parameters:
**styles – CSS property-value pairs for keys. Accepts both strings and CSS type objects (Color, Size, etc.)
- key_width(value: Size | str | int | float) Self[source]
Apply fixed key width in-place.
- Parameters:
value – CSS width value (e.g., “100px”, Size.px(100)).
- labeled() Self[source]
Apply label-style keys in-place.
Keys are styled as small labels above values.
- margin(value: Spacing | str | int | float) Self[source]
Apply container margin in-place.
- Parameters:
value – CSS margin value (e.g., “10px”, Size.px(10), Spacing.all(10)).
- max_width(value: Size | str | int | float) Self[source]
Apply maximum width in-place.
- Parameters:
value – CSS max-width value (e.g., “500px”, Size.px(500), Size.vw(80)).
- padding(value: Spacing | str | int | float) Self[source]
Apply container padding in-place.
- Parameters:
value – CSS padding value (e.g., “10px”, Size.px(10)).
- render() str[source]
Return HTML representation of this dictionary.
- Returns:
A string containing valid HTML.
- separator(value: str) Self[source]
Apply a separator between key and value in-place.
- Parameters:
value – Separator string (e.g., “:”, “ -> “, “ = “).
- simple() Self[source]
Apply simple key: value formatting in-place.
Clean, minimal display with colon separators.
- spaced() Self[source]
Apply generous spacing style in-place.
More padding and gaps for readability.
- striped() Self[source]
Apply striped table style in-place.
Creates an alternating row colors table.
- styled(**styles: str | CSSValue) Self[source]
Apply additional container styles in-place.
- Parameters:
**styles – CSS property-value pairs for the container. Accepts both strings and CSS type objects (Color, Size, etc.)
- Returns:
Self for method chaining.
- value_background(value: Color | str) Self[source]
Apply background color to values in-place.
- Parameters:
value – CSS color value (e.g., “lightgray”, Color.hex(“#eee”)).
- value_color(value: Color | str) Self[source]
Apply color to values in-place.
- Parameters:
value – CSS color value (e.g., “green”, Color.green).
- value_padding(value: Spacing | str | int | float) Self[source]
Apply padding to values in-place.
- Parameters:
value – CSS padding value (e.g., “10px”, Size.px(10), Spacing.all(10)).
- class animaid.HTMLDivider(label: str | None = None, **styles: str | CSSValue)[source]
Bases:
HTMLObjectA visual separator (horizontal or vertical line).
HTMLDivider creates a line to visually separate content sections. It can be horizontal (default) or vertical (for use in rows).
Examples
>>> from animaid import HTMLDivider >>> divider = HTMLDivider() # Simple horizontal line
>>> # With label >>> divider = HTMLDivider("OR")
>>> # Vertical divider for rows >>> divider = HTMLDivider().vertical()
>>> # Styled divider >>> divider = HTMLDivider().dashed().color("gray")
- add_class(*class_names: str) HTMLDivider[source]
Add CSS classes.
- Parameters:
*class_names – CSS class names to add.
- Returns:
Self for method chaining.
- bold() HTMLDivider[source]
Apply bold divider styling (thicker, darker).
- Returns:
Self for method chaining.
- color(value: Color | str) HTMLDivider[source]
Set the divider color.
- Parameters:
value – Color enum or CSS color string.
- Returns:
Self for method chaining.
- dashed() HTMLDivider[source]
Set dashed line style.
- Returns:
Self for method chaining.
- dotted() HTMLDivider[source]
Set dotted line style.
- Returns:
Self for method chaining.
- horizontal() HTMLDivider[source]
Make the divider horizontal (default).
- Returns:
Self for method chaining.
- margin(size: Size | str) HTMLDivider[source]
Set the margin around the divider.
- Parameters:
size – Margin size.
- Returns:
Self for method chaining.
- set_label(text: str | None) HTMLDivider[source]
Set or remove the divider label.
- Parameters:
text – Label text, or None to remove.
- Returns:
Self for method chaining.
- solid() HTMLDivider[source]
Set solid line style.
- Returns:
Self for method chaining.
- style(value: DividerStyle | str) HTMLDivider[source]
Set the line style.
- Parameters:
value – DividerStyle enum or CSS border-style string.
- Returns:
Self for method chaining.
- styled(**styles: str | CSSValue) HTMLDivider[source]
Apply additional inline styles.
- Parameters:
**styles – CSS property-value pairs.
- Returns:
Self for method chaining.
- subtle() HTMLDivider[source]
Apply subtle divider styling (lighter color).
- Returns:
Self for method chaining.
- thickness(size: Size | str | int) HTMLDivider[source]
Set the divider thickness.
- Parameters:
size – Thickness (Size, CSS string, or int pixels).
- Returns:
Self for method chaining.
- vertical() HTMLDivider[source]
Make the divider vertical (for use in flex rows).
- Returns:
Self for method chaining.
- class animaid.HTMLFloat(value: float = 0.0, **styles: str | CSSValue)[source]
Bases:
HTMLObject,floatA float subclass that renders as styled HTML.
HTMLFloat behaves like a regular Python float but includes methods for applying CSS styles, number formatting, and rendering to HTML. All styling methods modify the object in-place and return self for method chaining.
Examples
>>> n = HTMLFloat(3.14159) >>> n.bold().red().render() '<span style="font-weight: bold; color: red">3.14159</span>'
>>> HTMLFloat(1234.5678).comma().render() '<span>1,234.5678</span>'
>>> HTMLFloat(0.856).percent().render() '<span>85.60%</span>'
>>> HTMLFloat(3.14159).decimal(2).render() '<span>3.14</span>'
- add_class(*class_names: str) Self[source]
Add CSS classes in-place.
- Parameters:
*class_names – CSS class names to add.
- Returns:
Self for method chaining.
- border_radius(value: Size | str | int | float) Self[source]
Apply specified border radius in-place.
- comma() Self[source]
Apply thousand separator formatting in-place.
Examples
>>> HTMLFloat(1234567.89).comma().render() '<span>1,234,567.89</span>'
- currency(symbol: str = '$', decimals: int = 2) Self[source]
Apply currency formatting in-place.
- Parameters:
symbol – Currency symbol (default “$”)
decimals – Number of decimal places (default 2)
Examples
>>> HTMLFloat(1000.5).currency().render() '<span>$1,000.50</span>' >>> HTMLFloat(1000.5).currency("€", 0).render() '<span>€1,000</span>'
- decimal(places: int = 2) Self[source]
Apply fixed decimal places formatting in-place.
- Parameters:
places – Number of decimal places (default 2)
Examples
>>> HTMLFloat(3.14159).decimal(2).render() '<span>3.14</span>' >>> HTMLFloat(3.1).decimal(4).render() '<span>3.1000</span>'
- percent(decimals: int = 2) Self[source]
Apply percentage formatting in-place.
The value is multiplied by 100 for display.
- Parameters:
decimals – Number of decimal places (default 2)
Examples
>>> HTMLFloat(0.856).percent().render() '<span>85.60%</span>' >>> HTMLFloat(0.5).percent(0).render() '<span>50%</span>'
- render() str[source]
Return HTML representation of this float.
- Returns:
A string containing valid HTML.
- scientific(precision: int = 2) Self[source]
Apply scientific notation formatting in-place.
- Parameters:
precision – Number of decimal places in mantissa (default 2)
Examples
>>> HTMLFloat(1234567.89).scientific().render() '<span>1.23e+06</span>'
- significant(figures: int = 3) Self[source]
Apply significant figures formatting in-place.
- Parameters:
figures – Number of significant figures (default 3)
Examples
>>> HTMLFloat(3.14159).significant(3).render() '<span>3.14</span>' >>> HTMLFloat(0.00123456).significant(2).render() '<span>0.0012</span>'
- styled(**styles: str | CSSValue) Self[source]
Apply additional inline styles in-place.
- Parameters:
**styles – CSS property-value pairs.
- Returns:
Self for method chaining.
- class animaid.HTMLInt(value: int = 0, **styles: str | CSSValue)[source]
Bases:
HTMLObject,intAn int subclass that renders as styled HTML.
HTMLInt behaves like a regular Python int but includes methods for applying CSS styles, number formatting, and rendering to HTML. All styling methods modify the object in-place and return self for method chaining.
Examples
>>> n = HTMLInt(42) >>> n.bold().red().render() '<span style="font-weight: bold; color: red">42</span>'
>>> HTMLInt(1234567).comma().render() '<span>1,234,567</span>'
>>> HTMLInt(1000).currency("$").bold().render() '<span style="font-weight: bold">$1,000</span>'
>>> HTMLInt(1).ordinal().render() '<span>1st</span>'
- add_class(*class_names: str) Self[source]
Add CSS classes in-place.
- Parameters:
*class_names – CSS class names to add.
- Returns:
Self for method chaining.
- border_radius(value: Size | str | int | float) Self[source]
Apply specified border radius in-place.
- comma() Self[source]
Apply thousand separator formatting in-place.
Examples
>>> HTMLInt(1234567).comma().render() '<span>1,234,567</span>'
- currency(symbol: str = '$') Self[source]
Apply currency formatting in-place.
- Parameters:
symbol – Currency symbol (default “$”)
Examples
>>> HTMLInt(1000).currency().render() '<span>$1,000</span>' >>> HTMLInt(1000).currency("€").render() '<span>€1,000</span>'
- ordinal() Self[source]
Apply ordinal formatting (1st, 2nd, 3rd, etc.) in-place.
Examples
>>> HTMLInt(1).ordinal().render() '<span>1st</span>' >>> HTMLInt(22).ordinal().render() '<span>22nd</span>'
- padded(width: int = 2) Self[source]
Apply zero-padding formatting in-place.
- Parameters:
width – Minimum width (default 2)
Examples
>>> HTMLInt(7).padded(3).render() '<span>007</span>'
- percent() Self[source]
Apply percentage formatting in-place.
Examples
>>> HTMLInt(85).percent().render() '<span>85%</span>'
- render() str[source]
Return HTML representation of this integer.
- Returns:
A string containing valid HTML.
- styled(**styles: str | CSSValue) Self[source]
Apply additional inline styles in-place.
- Parameters:
**styles – CSS property-value pairs.
- Returns:
Self for method chaining.
- class animaid.HTMLList(items: list[Any] | None = None, **styles: str | CSSValue)[source]
Bases:
HTMLObject,listA list subclass that renders as styled HTML.
HTMLList behaves like a regular Python list but includes methods for applying CSS styles and rendering to HTML. All styling methods modify the object in-place and return self for method chaining. Supports vertical, horizontal, and grid layouts.
Examples
>>> items = HTMLList(["Apple", "Banana", "Cherry"]) >>> items.render() '<ul><li>Apple</li><li>Banana</li><li>Cherry</li></ul>'
>>> items.horizontal().gap("10px").render() '<div style="display: flex; flex-direction: row; gap: 10px">...</div>'
>>> HTMLList([1, 2, 3]).ordered().render() '<ol><li>1</li><li>2</li><li>3</li></ol>'
- add_class(*class_names: str) Self[source]
Add CSS classes on the container in-place.
- Parameters:
*class_names – CSS class names to add.
- Returns:
Self for method chaining.
- add_item_class(*class_names: str) Self[source]
Add CSS classes to each item in-place.
- Parameters:
*class_names – CSS class names to add to items.
- align_items(value: AlignItems | str) Self[source]
Apply specified cross-axis alignment in-place.
- Parameters:
value – CSS align-items value (e.g., “center”, AlignItems.CENTER).
- background(value: Color | str) Self[source]
Apply background color on the container in-place.
- Parameters:
value – CSS color value (e.g., “white”, Color.white, Color.hex(“#fff”)).
- border(value: Border | str) Self[source]
Apply border around the container in-place.
- Parameters:
value – CSS border value (e.g., “1px solid black”, Border.solid()).
- border_radius(value: Size | str | int | float) Self[source]
Apply rounded corners on the container in-place.
- Parameters:
value – CSS border-radius value (e.g., “5px”, Size.px(5)).
- cards() Self[source]
Apply card list style with shadows and spacing in-place.
Creates a visually appealing list where each item looks like a card.
- color(value: Color | str) Self[source]
Apply text color in-place.
- Parameters:
value – CSS color value (e.g., “black”, Color.black).
- gap(value: Size | str | int | float) Self[source]
Apply specified gap between items in-place.
- Parameters:
value – CSS gap value (e.g., “10px”, Size.px(10), Size.rem(1)).
- grid(columns: int = 3) Self[source]
Apply CSS grid layout in-place.
- Parameters:
columns – Number of columns in the grid.
- Returns:
Self for method chaining.
- height(value: Size | str | int | float) Self[source]
Apply specified height in-place.
- Parameters:
value – CSS height value (e.g., “200px”, Size.px(200), Size.vh(100)).
- horizontal() Self[source]
Apply horizontal layout in-place.
Items are arranged left to right using flexbox.
- horizontal_reverse() Self[source]
Apply reversed horizontal layout in-place.
Items are arranged right to left.
- inline() Self[source]
Apply inline style in-place.
Creates a simple inline list separated by spacing.
- item_background(value: Color | str) Self[source]
Apply background color on each item in-place.
- Parameters:
value – CSS color value.
- item_border(value: Border | str) Self[source]
Apply border around each item in-place.
- Parameters:
value – CSS border value for items.
- item_border_radius(value: Size | str | int | float) Self[source]
Apply rounded corners on each item in-place.
- Parameters:
value – CSS border-radius value for items.
- item_margin(value: Spacing | str | int | float) Self[source]
Apply margin around each item in-place.
- Parameters:
value – CSS margin value for items.
- item_padding(value: Spacing | str | int | float) Self[source]
Apply padding inside each item in-place.
- Parameters:
value – CSS padding value for items.
- justify_content(value: JustifyContent | str) Self[source]
Apply specified main-axis alignment in-place.
- Parameters:
value – CSS justify-content value (e.g., “space-between”).
- margin(value: Spacing | str | int | float) Self[source]
Apply margin outside the container in-place.
- Parameters:
value – CSS margin value (e.g., “10px”, Size.px(10), Spacing.all(10)).
- max_width(value: Size | str | int | float) Self[source]
Apply maximum width constraint in-place.
- Parameters:
value – CSS max-width value (e.g., “800px”, Size.px(800)).
Apply vertical menu style in-place.
Creates a clean vertical menu suitable for navigation.
- padding(value: Spacing | str | int | float) Self[source]
Apply padding inside the container in-place.
- Parameters:
value – CSS padding value (e.g., “10px”, Size.px(10)).
- pills() Self[source]
Apply pill/badge style in-place.
Creates a horizontal list of pill-shaped items.
- render() str[source]
Return HTML representation of this list.
- Returns:
A string containing valid HTML.
- separator(value: Border | str) Self[source]
Apply separator lines between items in-place.
Unlike item_border, this only adds borders between items, not on the outer edges.
- Parameters:
value – CSS border value for separators.
- styled(**styles: str | CSSValue) Self[source]
Apply additional container styles in-place.
- Parameters:
**styles – CSS property-value pairs for the container. Accepts both strings and CSS type objects (Color, Size, etc.)
- Returns:
Self for method chaining.
- tags() Self[source]
Apply tags/labels style in-place.
Creates a horizontal list of tag-style items.
- class animaid.HTMLObject[source]
Bases:
ABCAbstract base class for all HTML-renderable types.
All HTML* types (HTMLString, HTMLList, HTMLDict) inherit from this to ensure a consistent interface for rendering Python objects as styled HTML. When rendering nested objects, any item that is an HTMLObject will have its render() method called automatically.
- abstractmethod add_class(*class_names: str) Self[source]
Return a copy with additional CSS classes.
- Parameters:
*class_names – CSS class names to add.
- Returns:
A new instance with the additional classes.
- abstractmethod render() str[source]
Return HTML representation of this object.
- Returns:
A string containing valid HTML that can be embedded in a page.
- abstractmethod styled(**styles: str) Self[source]
Return a copy with additional inline styles.
Style names use Python convention (underscores) and are converted to CSS convention (hyphens) automatically.
- Parameters:
**styles – CSS property-value pairs, e.g., font_size=”16px”
- Returns:
A new instance with the combined styles.
- class animaid.HTMLRow(children: list[Any] | None = None, **styles: str | CSSValue)[source]
Bases:
HTMLContainerA horizontal flex container for arranging items in a row.
HTMLRow uses CSS flexbox with flex-direction: row to arrange children horizontally. It provides methods for controlling alignment, justification, wrapping, and spacing.
Examples
>>> from animaid import HTMLRow, HTMLButton >>> row = HTMLRow([ ... HTMLButton("Save").primary(), ... HTMLButton("Cancel"), ... ])
>>> # With alignment and gap >>> row = HTMLRow([item1, item2, item3]).gap(10).align(AlignItems.CENTER)
>>> # Button row preset >>> row = HTMLRow(buttons).buttons()
- add_class(*class_names: str) HTMLRow[source]
Add CSS classes.
- Parameters:
*class_names – CSS class names to add.
- Returns:
Self for method chaining.
- align(value: AlignItems | str) HTMLRow[source]
Set vertical alignment of items within the row.
- Parameters:
value – AlignItems enum or CSS string (start, center, end, stretch, baseline).
- Returns:
Self for method chaining.
Example
>>> row.align(AlignItems.CENTER) >>> row.align("center") # Also works
- buttons() HTMLRow[source]
Apply button row styling preset.
Creates a row with appropriate gap and end-alignment, suitable for action buttons in forms or dialogs.
- Returns:
Self for method chaining.
- centered() HTMLRow[source]
Center all items both horizontally and vertically.
- Returns:
Self for method chaining.
- gap(size: Size | str | int) HTMLRow[source]
Set the gap between child elements.
- Parameters:
size – Gap size.
- Returns:
Self for method chaining.
- height(size: Size | str | int) HTMLRow[source]
Set container height.
- Parameters:
size – Height.
- Returns:
Self for method chaining.
- justify(value: JustifyContent | str) HTMLRow[source]
Set horizontal distribution of items within the row.
- Parameters:
value – JustifyContent enum or CSS string (start, center, end, space-between, space-around, space-evenly).
- Returns:
Self for method chaining.
Example
>>> row.justify(JustifyContent.SPACE_BETWEEN) >>> row.justify("space-between") # Also works
- margin(size: Spacing | Size | str | int) HTMLRow[source]
Set external margin.
- Parameters:
size – Margin size.
- Returns:
Self for method chaining.
- min_item_width(size: Size | str | int) HTMLRow[source]
Set minimum width for child items (via CSS custom property).
This works best with .wrap() to prevent items from becoming too small before wrapping.
- Parameters:
size – Minimum item width.
- Returns:
Self for method chaining.
- nowrap() HTMLRow[source]
Prevent items from wrapping (default behavior).
- Returns:
Self for method chaining.
- padding(size: Spacing | Size | str | int) HTMLRow[source]
Set internal padding.
- Parameters:
size – Padding size.
- Returns:
Self for method chaining.
- spaced() HTMLRow[source]
Distribute items with space between them.
- Returns:
Self for method chaining.
- styled(**styles: str | CSSValue) HTMLRow[source]
Apply additional inline styles.
- Parameters:
**styles – CSS property-value pairs.
- Returns:
Self for method chaining.
- toolbar() HTMLRow[source]
Apply toolbar styling preset.
Creates a compact row suitable for toolbar layouts.
- Returns:
Self for method chaining.
- width(size: Size | str | int) HTMLRow[source]
Set container width.
- Parameters:
size – Width.
- Returns:
Self for method chaining.
- wrap(value: FlexWrap | str = FlexWrap.WRAP) HTMLRow[source]
Allow items to wrap to the next line.
- Parameters:
value – FlexWrap enum or CSS string (wrap, nowrap, wrap-reverse). Default is WRAP.
- Returns:
Self for method chaining.
Example
>>> row.wrap() # Enable wrapping >>> row.wrap(FlexWrap.WRAP_REVERSE) # Wrap in reverse order
- class animaid.HTMLSelect(options: list[str], value: str | None = None)[source]
Bases:
objectA dropdown select widget with two-way binding.
The value property is automatically synced from the browser when the user selects an option.
Examples
>>> select = HTMLSelect(options=["Red", "Green", "Blue"]) >>> select = HTMLSelect( ... options=["Small", "Medium", "Large"], ... value="Medium" ... ).on_change(handle_change)
# With App - two-way binding >>> with App() as app: … color = HTMLSelect(options=[“Red”, “Green”, “Blue”]) … app.add(color) … # Later, read the current value: … print(color.value) # Selected option synced from browser
- add_class(*class_names: str) HTMLSelect[source]
Return a copy with additional CSS classes.
- Parameters:
*class_names – CSS class names to add.
- Returns:
A new instance with the additional classes.
- large() HTMLSelect[source]
Return a copy with larger text and padding.
- Returns:
A new instance with large styling.
- on_change(callback: Callable[[str], None]) HTMLSelect[source]
Register a callback for selection changes.
The callback is called when the user selects a different option.
- Parameters:
callback – A function that takes the new selected value as argument.
- Returns:
Self for method chaining.
Examples
>>> def handle_change(value): ... print(f"Selected: {value}") >>> select = HTMLSelect(["A", "B", "C"]).on_change(handle_change)
- render() str[source]
Return HTML representation of this select.
- Returns:
A string containing valid HTML for the select.
- small() HTMLSelect[source]
Return a copy with smaller text and padding.
- Returns:
A new instance with small styling.
- styled(**styles: str) HTMLSelect[source]
Return a copy with additional inline styles.
- Parameters:
**styles – CSS property-value pairs.
- Returns:
A new instance with the combined styles.
- property value: str
Get the currently selected value (thread-safe).
The value is automatically synced from the browser when the user selects an option.
- Returns:
The currently selected option string.
- wide() HTMLSelect[source]
Return a copy that expands to full width.
- Returns:
A new instance with full width styling.
- class animaid.HTMLSet(items: Iterable[Any] = (), **styles: str | CSSValue)[source]
Bases:
HTMLObject,setA set subclass that renders as styled HTML.
HTMLSet behaves like a regular Python set but includes methods for applying CSS styles and rendering to HTML. All styling methods modify the object in-place and return self for method chaining. Items are automatically deduplicated (set behavior). Mutations trigger notifications for reactive updates.
Examples
>>> s = HTMLSet({1, 2, 3}) >>> s.render() '<span>{1, 2, 3}</span>'
>>> s.horizontal().pills().render() '<div style="display: flex; ...">...</div>'
>>> HTMLSet([1, 1, 2, 2, 3]) # Duplicates removed HTMLSet({1, 2, 3})
- add_class(*class_names: str) Self[source]
Add CSS classes on the container in-place.
- Parameters:
*class_names – CSS class names to add.
- Returns:
Self for method chaining.
- align_items(value: AlignItems | str) Self[source]
Apply specified cross-axis alignment in-place.
- border_radius(value: Size | str | int | float) Self[source]
Apply rounded corners on the container in-place.
- difference(*others: Iterable[Any]) Self[source]
Return difference with other sets, preserving settings.
- grid(columns: int = 3) Self[source]
Apply CSS grid layout in-place.
- Parameters:
columns – Number of columns in the grid.
- intersection(*others: Iterable[Any]) Self[source]
Return intersection with other sets, preserving settings.
- item_border_radius(value: Size | str | int | float) Self[source]
Apply rounded corners on each item in-place.
- item_margin(value: Spacing | str | int | float) Self[source]
Apply margin around each item in-place.
- item_padding(value: Spacing | str | int | float) Self[source]
Apply padding inside each item in-place.
- justify_content(value: JustifyContent | str) Self[source]
Apply specified main-axis alignment in-place.
- margin(value: Spacing | str | int | float) Self[source]
Apply margin outside the container in-place.
- padding(value: Spacing | str | int | float) Self[source]
Apply padding inside the container in-place.
- render() str[source]
Return HTML representation of this set.
- Returns:
A string containing valid HTML.
- styled(**styles: str | CSSValue) Self[source]
Apply additional container styles in-place.
- Parameters:
**styles – CSS property-value pairs for the container.
- Returns:
Self for method chaining.
- symmetric_difference(other: Iterable[Any]) Self[source]
Return symmetric difference with other set, preserving settings.
- class animaid.HTMLSlider(min: float = 0, max: float = 100, value: float | None = None, step: float = 1)[source]
Bases:
objectA range slider widget with two-way numeric binding.
The value property is automatically synced from the browser when the user moves the slider.
Examples
>>> slider = HTMLSlider(min=0, max=100, value=50) >>> slider = HTMLSlider(min=0, max=1, step=0.1).on_change(handle_change)
# With App - two-way binding >>> with App() as app: … volume = HTMLSlider(min=0, max=100, value=75) … app.add(volume) … # Later, read the current value: … print(volume.value) # Numeric value synced from browser
- add_class(*class_names: str) HTMLSlider[source]
Return a copy with additional CSS classes.
- Parameters:
*class_names – CSS class names to add.
- Returns:
A new instance with the additional classes.
- on_change(callback: Callable[[float], None]) HTMLSlider[source]
Register a callback for value changes.
The callback is called when the user moves the slider.
- Parameters:
callback – A function that takes the new value as argument.
- Returns:
Self for method chaining.
Examples
>>> def handle_change(value): ... print(f"Slider value: {value}") >>> slider = HTMLSlider(0, 100).on_change(handle_change)
- render() str[source]
Return HTML representation of this slider.
- Returns:
A string containing valid HTML for the slider.
- styled(**styles: str) HTMLSlider[source]
Return a copy with additional inline styles.
- Parameters:
**styles – CSS property-value pairs.
- Returns:
A new instance with the combined styles.
- thick() HTMLSlider[source]
Return a copy with a thicker slider track.
- Returns:
A new instance with thick styling.
- thin() HTMLSlider[source]
Return a copy with a thinner slider track.
- Returns:
A new instance with thin styling.
- property value: float
Get the current value (thread-safe).
The value is automatically synced from the browser when the user moves the slider.
- Returns:
The current numeric value of the slider.
- wide() HTMLSlider[source]
Return a copy that expands to full width.
- Returns:
A new instance with full width styling.
- class animaid.HTMLSpacer(**styles: str | CSSValue)[source]
Bases:
HTMLObjectAn empty space element for layout control.
HTMLSpacer creates invisible space between elements. It can be fixed-size or flexible (expands to fill available space in flex containers).
Examples
>>> from animaid import HTMLSpacer, HTMLRow, HTMLButton
>>> # Fixed height spacer >>> spacer = HTMLSpacer().height(20)
>>> # Flexible spacer (pushes items apart in flex containers) >>> row = HTMLRow([ ... HTMLButton("Left"), ... HTMLSpacer().flex(), # Takes remaining space ... HTMLButton("Right"), ... ])
>>> # Fixed width spacer in a row >>> row = HTMLRow([item1, HTMLSpacer().width(50), item2])
- add_class(*class_names: str) HTMLSpacer[source]
Add CSS classes.
- Parameters:
*class_names – CSS class names to add.
- Returns:
Self for method chaining.
- flex(grow: int = 1) HTMLSpacer[source]
Make the spacer flexible (expands to fill available space).
In a flex container (HTMLRow or HTMLColumn), a flex spacer will expand to take up any remaining space, pushing other items apart.
- Parameters:
grow – Flex grow value (default 1).
- Returns:
Self for method chaining.
Example
>>> # Push button to the right >>> row = HTMLRow([ ... HTMLString("Title"), ... HTMLSpacer().flex(), ... HTMLButton("Action"), ... ])
- grow(value: int = 1) HTMLSpacer[source]
Set flex-grow value.
- Parameters:
value – Flex grow value.
- Returns:
Self for method chaining.
- height(size: Size | str | int) HTMLSpacer[source]
Set a fixed height.
- Parameters:
size – Height (Size, CSS string, or int pixels).
- Returns:
Self for method chaining.
- lg() HTMLSpacer[source]
Large spacer (24px).
- Returns:
Self for method chaining.
- md() HTMLSpacer[source]
Medium spacer (16px).
- Returns:
Self for method chaining.
- shrink(value: int = 0) HTMLSpacer[source]
Set flex-shrink value.
- Parameters:
value – Flex shrink value.
- Returns:
Self for method chaining.
- size(width: Size | str | int, height: Size | str | int) HTMLSpacer[source]
Set both width and height.
- Parameters:
width – Width value.
height – Height value.
- Returns:
Self for method chaining.
- sm() HTMLSpacer[source]
Small spacer (8px).
- Returns:
Self for method chaining.
- styled(**styles: str | CSSValue) HTMLSpacer[source]
Apply additional inline styles.
- Parameters:
**styles – CSS property-value pairs.
- Returns:
Self for method chaining.
- width(size: Size | str | int) HTMLSpacer[source]
Set a fixed width.
- Parameters:
size – Width (Size, CSS string, or int pixels).
- Returns:
Self for method chaining.
- xl() HTMLSpacer[source]
Extra large spacer (32px).
- Returns:
Self for method chaining.
- xs() HTMLSpacer[source]
Extra small spacer (4px).
- Returns:
Self for method chaining.
- class animaid.HTMLString(content: str = '', **styles: str | CSSValue)[source]
Bases:
HTMLObject,strA string subclass that renders as styled HTML.
HTMLString behaves like a regular Python string but includes methods for applying CSS styles and rendering to HTML. All styling methods modify the object in-place and return self for method chaining.
Examples
>>> s = HTMLString("Hello World") >>> s.bold().color("red").render() '<span style="font-weight: bold; color: red">Hello World</span>'
>>> s = HTMLString("Click me", color="blue", text_decoration="underline") >>> s.render() '<span style="color: blue; text-decoration: underline">Click me</span>'
- add_class(*class_names: str) Self[source]
Add CSS classes in-place.
- Parameters:
*class_names – CSS class names to add.
- Returns:
Self for method chaining.
Example
>>> s = HTMLString("Hello").add_class("highlight", "important") >>> s.render() '<span class="highlight important">Hello</span>'
- background(value: Color | str) Self[source]
Apply specified background color in-place.
- Parameters:
value – CSS color value (e.g., “yellow”, Color.yellow)
- border(value: Border | str) Self[source]
Apply specified border in-place.
- Parameters:
value – CSS border value (e.g., “1px solid black”, Border.solid())
- border_radius(value: Size | str | int | float) Self[source]
Apply specified border radius in-place.
- Parameters:
value – CSS border-radius value (e.g., “5px”, Size.px(5), Size.percent(50))
- color(value: Color | str) Self[source]
Apply specified text color in-place.
- Parameters:
value – CSS color value (e.g., “red”, “#ff0000”, Color.red)
- display(value: Display | str) Self[source]
Apply specified display mode in-place.
- Parameters:
value – CSS display value (e.g., “block”, “flex”, Display.FLEX)
- font_family(value: str) Self[source]
Apply specified font family in-place.
- Parameters:
value – CSS font-family value.
- font_size(value: Size | str | int | float) Self[source]
Apply specified font size in-place.
- Parameters:
value – CSS size value (e.g., “16px”, Size.px(16), Size.em(1.2))
- height(value: Size | str | int | float) Self[source]
Apply specified height in-place.
- Parameters:
value – CSS height value (e.g., “50px”, Size.px(50), Size.vh(100))
- margin(value: Spacing | str | int | float) Self[source]
Apply specified margin in-place.
- Parameters:
value – CSS margin value (e.g., “10px”, Size.px(10), Spacing.all(10))
- opacity(value: str | float) Self[source]
Apply specified opacity in-place.
- Parameters:
value – CSS opacity value (0.0 to 1.0)
- padding(value: Spacing | str | int | float) Self[source]
Apply specified padding in-place.
- Parameters:
value – CSS padding value (e.g., “10px”, Size.px(10))
- render() str[source]
Return HTML representation of this string.
The string content is HTML-escaped to prevent XSS.
- Returns:
A string containing valid HTML.
Example
>>> HTMLString("<script>alert('xss')</script>").render() '<span><script>alert('xss')</script></span>'
- styled(**styles: str | CSSValue) Self[source]
Apply additional inline styles in-place.
Style names use Python convention (underscores) and are converted to CSS convention (hyphens) automatically.
- Parameters:
**styles – CSS property-value pairs. Accepts strings and CSS types. e.g., font_size=”16px” or font_size=Size.px(16)
- Returns:
Self for method chaining.
Example
>>> s = HTMLString("Hello").styled(color="red", font_size="20px") >>> s.render() '<span style="color: red; font-size: 20px">Hello</span>'
>>> s = HTMLString("Hello").styled(color=Color.red, font_size=Size.px(20)) >>> s.render() '<span style="color: red; font-size: 20px">Hello</span>'
- tag(tag_name: str) Self[source]
Change the HTML tag in-place.
- Parameters:
tag_name – The HTML tag to use (e.g., “div”, “p”, “strong”).
- Returns:
Self for method chaining.
Example
>>> s = HTMLString("Hello").tag("strong").render() '<strong>Hello</strong>'
- class animaid.HTMLTextInput(value: str = '', placeholder: str = '')[source]
Bases:
objectA text input widget with two-way value binding.
The value property is automatically synced from the browser when the user types in the input field.
Examples
>>> text = HTMLTextInput(placeholder="Enter your name...") >>> text = HTMLTextInput(value="Default").on_change(handle_change)
# With App - two-way binding >>> with App() as app: … name_input = HTMLTextInput(placeholder=”Name”) … app.add(name_input) … # Later, read the current value: … print(name_input.value) # Value synced from browser
- add_class(*class_names: str) HTMLTextInput[source]
Return a copy with additional CSS classes.
- Parameters:
*class_names – CSS class names to add.
- Returns:
A new instance with the additional classes.
- large() HTMLTextInput[source]
Return a copy with larger text and padding.
- Returns:
A new instance with large styling.
- on_change(callback: Callable[[str], None]) HTMLTextInput[source]
Register a callback for value changes.
The callback is called on each keystroke when the user types.
- Parameters:
callback – A function that takes the new value as argument.
- Returns:
Self for method chaining.
Examples
>>> def handle_change(value): ... print(f"Input changed to: {value}") >>> text = HTMLTextInput().on_change(handle_change)
- on_submit(callback: Callable[[str], None]) HTMLTextInput[source]
Register a callback for submit (Enter key).
The callback is called when the user presses Enter in the input.
- Parameters:
callback – A function that takes the submitted value as argument.
- Returns:
Self for method chaining.
Examples
>>> def handle_submit(value): ... print(f"Submitted: {value}") >>> text = HTMLTextInput().on_submit(handle_submit)
- render() str[source]
Return HTML representation of this text input.
- Returns:
A string containing valid HTML for the input.
- small() HTMLTextInput[source]
Return a copy with smaller text and padding.
- Returns:
A new instance with small styling.
- styled(**styles: str) HTMLTextInput[source]
Return a copy with additional inline styles.
- Parameters:
**styles – CSS property-value pairs.
- Returns:
A new instance with the combined styles.
- property value: str
Get the current value (thread-safe).
The value is automatically synced from the browser when the user types in the input field.
- Returns:
The current text value of the input.
- wide() HTMLTextInput[source]
Return a copy that expands to full width.
- Returns:
A new instance with full width styling.
- class animaid.HTMLTuple(items: tuple[Any, ...] = (), **styles: str | CSSValue)[source]
Bases:
HTMLObject,tupleA tuple subclass that renders as styled HTML.
HTMLTuple behaves like a regular Python tuple but includes methods for applying CSS styles and rendering to HTML. All styling methods modify the object in-place and return self for method chaining. Supports named tuples with field name display.
Examples
>>> t = HTMLTuple((1, 2, 3)) >>> t.render() '<div>(1, 2, 3)</div>'
>>> t.horizontal().pills().render() '<div style="display: flex; ...">...</div>'
>>> from collections import namedtuple >>> Point = namedtuple('Point', ['x', 'y']) >>> HTMLTuple(Point(10, 20)).labeled().render() '<dl><dt>x</dt><dd>10</dd><dt>y</dt><dd>20</dd></dl>'
- align_items(value: AlignItems | str) Self[source]
Apply specified cross-axis alignment in-place.
- border_radius(value: Size | str | int | float) Self[source]
Apply rounded corners on the container in-place.
- item_border_radius(value: Size | str | int | float) Self[source]
Apply rounded corners on each item in-place.
- item_margin(value: Spacing | str | int | float) Self[source]
Apply margin around each item in-place.
- item_padding(value: Spacing | str | int | float) Self[source]
Apply padding inside each item in-place.
- justify_content(value: JustifyContent | str) Self[source]
Apply specified main-axis alignment in-place.
- labeled() Self[source]
Apply labeled format showing field names in-place.
For regular tuples, shows index numbers as labels.
- margin(value: Spacing | str | int | float) Self[source]
Apply margin outside the container in-place.
- padding(value: Spacing | str | int | float) Self[source]
Apply padding inside the container in-place.
- class animaid.InputEvent(id: str, event_type: str, value: Any = None, timestamp: float | None = None)[source]
Bases:
objectRepresents an input event from the browser.
- value
The value associated with the event (if any).
- Type:
Any
- class animaid.JustifyContent(value)[source]
Bases:
EnumCSS justify-content values.
- CENTER = 'center'
- END = 'end'
- FLEX_END = 'flex-end'
- FLEX_START = 'flex-start'
- SPACE_AROUND = 'space-around'
- SPACE_BETWEEN = 'space-between'
- SPACE_EVENLY = 'space-evenly'
- START = 'start'
- STRETCH = 'stretch'
- class animaid.JustifyItems(value)[source]
Bases:
EnumCSS justify-items values for grid containers.
- BASELINE = 'baseline'
- CENTER = 'center'
- END = 'end'
- START = 'start'
- STRETCH = 'stretch'
- class animaid.Overflow(value)[source]
Bases:
EnumCSS overflow values.
- AUTO = 'auto'
- CLIP = 'clip'
- HIDDEN = 'hidden'
- SCROLL = 'scroll'
- VISIBLE = 'visible'
- class animaid.PlaceItems(value)[source]
Bases:
EnumCSS place-items shorthand (align + justify).
- CENTER = 'center'
- END = 'end'
- START = 'start'
- STRETCH = 'stretch'
- class animaid.Position(value)[source]
Bases:
EnumCSS position values.
- ABSOLUTE = 'absolute'
- FIXED = 'fixed'
- RELATIVE = 'relative'
- STATIC = 'static'
- STICKY = 'sticky'
- class animaid.RadiusSize(value)[source]
Bases:
EnumPredefined border-radius sizes.
- DEFAULT = '4px'
- FULL = '9999px'
- LG = '8px'
- MD = '6px'
- NONE = '0'
- SM = '2px'
- XL = '12px'
- XXL = '16px'
- animaid.Select
alias of
HTMLSelect
- class animaid.ShadowSize(value)[source]
Bases:
EnumPredefined box-shadow sizes for cards/containers.
- DEFAULT = '0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1)'
- LG = '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)'
- MD = '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)'
- NONE = 'none'
- SM = '0 1px 2px 0 rgba(0, 0, 0, 0.05)'
- XL = '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1)'
- class animaid.Size(value: float | str, unit: str = '')[source]
Bases:
CSSValueRepresents a CSS size/length value with units.
Examples
>>> Size.px(10) Size('10px') >>> Size.em(1.5) Size('1.5em') >>> Size.percent(50) Size('50%') >>> Size.auto() Size('auto')
- KEYWORDS: ClassVar[set[str]] = {'auto', 'fit-content', 'inherit', 'initial', 'max-content', 'min-content', 'none', 'unset'}
- animaid.Slider
alias of
HTMLSlider
- animaid.Spacer
alias of
HTMLSpacer
- class animaid.Spacing(top: Size | str | int | float, right: Size | str | int | float | None = None, bottom: Size | str | int | float | None = None, left: Size | str | int | float | None = None)[source]
Bases:
CSSValueRepresents CSS spacing (padding/margin) with 1-4 values.
Examples
>>> Spacing.all(Size.px(10)) Spacing('10px') >>> Spacing.symmetric(Size.px(10), Size.px(20)) Spacing('10px 20px') >>> Spacing.edges(Size.px(1), Size.px(2), Size.px(3), Size.px(4)) Spacing('1px 2px 3px 4px')
- classmethod all(value: Size | str | int | float) Spacing[source]
Create uniform spacing on all sides.
- classmethod edges(top: Size | str | int | float, right: Size | str | int | float, bottom: Size | str | int | float, left: Size | str | int | float) Spacing[source]
Create spacing with explicit values for all four edges.
- classmethod horizontal(value: Size | str | int | float) Spacing[source]
Create horizontal-only spacing (left and right).
- classmethod section() Spacing[source]
Create typical section margins (24px top/bottom, 0 left/right).
- classmethod symmetric(vertical: Size | str | int | float, horizontal: Size | str | int | float) Spacing[source]
Create symmetric spacing (vertical and horizontal).
- animaid.String
alias of
HTMLString
- class animaid.TextAlign(value)[source]
Bases:
EnumCSS text-align values.
- CENTER = 'center'
- END = 'end'
- JUSTIFY = 'justify'
- LEFT = 'left'
- RIGHT = 'right'
- START = 'start'
- class animaid.TextDecoration(value)[source]
Bases:
EnumCSS text-decoration values.
- LINE_THROUGH = 'line-through'
- NONE = 'none'
- OVERLINE = 'overline'
- UNDERLINE = 'underline'
- animaid.TextInput
alias of
HTMLTextInput
- class animaid.TextTransform(value)[source]
Bases:
EnumCSS text-transform values.
- CAPITALIZE = 'capitalize'
- LOWERCASE = 'lowercase'
- NONE = 'none'
- UPPERCASE = 'uppercase'
- class animaid.Window(app: App, config: WindowConfig)[source]
Bases:
objectRuntime window control for AnimAID applications.
Access this via the app.window property. Provides methods to dynamically control the browser window appearance and behavior.
Examples
>>> with App() as app: ... app.window.dark() # Switch to dark theme ... app.window.set_title("Processing...") ... app.window.resize(1280, 720)
- dark() Window[source]
Switch to dark theme.
Convenience method equivalent to set_theme(“dark”).
- Returns:
Self for method chaining.
Examples
>>> app.window.dark()
- fullscreen() Window[source]
Request fullscreen mode.
Note: Browsers may require user interaction before allowing fullscreen.
- Returns:
Self for method chaining.
Examples
>>> app.window.fullscreen()
- get_config() dict[str, Any][source]
Get the current window configuration as a dictionary.
Used by the server to send initial configuration to clients.
- Returns:
Dictionary with current window settings.
- handle_window_event(event: str, data: dict[str, Any]) None[source]
Handle a window event from the browser.
This is called internally by the server.
- Parameters:
event – The event type (‘resize’, ‘close’).
data – Event-specific data.
- light() Window[source]
Switch to light theme.
Convenience method equivalent to set_theme(“light”).
- Returns:
Self for method chaining.
Examples
>>> app.window.light()
- on_close(callback: Callable[[], None]) Window[source]
Register a callback for window close events.
- Parameters:
callback – Function called when the window is about to close.
- Returns:
Self for method chaining.
Examples
>>> def handle_close(): ... print("Window closing!") >>> app.window.on_close(handle_close)
- on_resize(callback: Callable[[int, int], None]) Window[source]
Register a callback for window resize events.
- Parameters:
callback – Function that receives (width, height) when window resizes.
- Returns:
Self for method chaining.
Examples
>>> def handle_resize(width, height): ... print(f"Window resized to {width}x{height}") >>> app.window.on_resize(handle_resize)
- resize(width: int, height: int) Window[source]
Resize the browser window.
Note: Some browsers may restrict window resizing for security.
- Parameters:
width – The new width in pixels.
height – The new height in pixels.
- Returns:
Self for method chaining.
Examples
>>> app.window.resize(1280, 720)
- set_background(color: str) Window[source]
Set the page background color.
- Parameters:
color – CSS color value (e.g., ‘#ffffff’, ‘rgb(0,0,0)’, ‘white’).
- Returns:
Self for method chaining.
Examples
>>> app.window.set_background("#1a1a2e")
- set_favicon(url: str) Window[source]
Set the page favicon.
- Parameters:
url – URL to the favicon image.
- Returns:
Self for method chaining.
Examples
>>> app.window.set_favicon("/static/icon.png")
- set_theme(theme: str) Window[source]
Set the color theme.
- Parameters:
theme – The theme to use (‘light’, ‘dark’, or ‘auto’).
- Returns:
Self for method chaining.
Examples
>>> app.window.set_theme("dark")
- class animaid.WindowConfig(title: str = 'AnimAID', width: int | None = None, height: int | None = None, theme: str = 'light', background_color: str = '#fafafa', favicon: str | None = None)[source]
Bases:
objectConfiguration for window initialization.
Use this to configure the initial state of the browser window when creating an App.
Examples
>>> from animaid import App, WindowConfig >>> # Use a preset for quick setup >>> config = WindowConfig.compact(title="My Tool") >>> with App(window=config) as app: ... app.add(HTMLString("Hello"))
>>> # Or configure manually >>> config = WindowConfig( ... title="Dashboard", ... width=1280, ... height=720, ... theme="dark" ... )
- classmethod compact(title: str = 'AnimAID') WindowConfig[source]
Create a compact window configuration (600x400).
- Parameters:
title – The window title.
- Returns:
A WindowConfig for a small, compact window.
- classmethod dark(title: str = 'AnimAID') WindowConfig[source]
Create a dark-themed window configuration.
- Parameters:
title – The window title.
- Returns:
A WindowConfig with dark theme.
- classmethod standard(title: str = 'AnimAID') WindowConfig[source]
Create a standard window configuration (1024x768).
- Parameters:
title – The window title.
- Returns:
A WindowConfig for a standard-sized window.
- classmethod wide(title: str = 'AnimAID') WindowConfig[source]
Create a wide window configuration (1280x720).
- Parameters:
title – The window title.
- Returns:
window.
- Return type:
A WindowConfig for a wide (16
- animaid.h_string
alias of
HTMLString
Interactive Display
App
- class animaid.App(port: int = 8200, title: str = 'AnimAID', auto_open: bool = True, window: WindowConfig | None = None, width: int | None = None, height: int | None = None, theme: str = 'light')[source]
Bases:
objectA Tkinter-like interactive GUI environment using HTML.
The browser becomes the display surface, and AnimAID objects become widgets that can be added, updated, and removed programmatically with real-time visual feedback.
Examples
>>> from animaid import App, HTMLString >>> app = App() >>> app.run() # Starts server, opens browser >>> app.add(HTMLString("Hello").bold) 'string_1' >>> app.add(HTMLString("World").italic) 'string_2' >>> app.stop()
# Context manager support >>> with App() as app: … app.add(HTMLString(“Temporary display”)) # Server stops when context exits
# With window configuration >>> with App(title=”Dashboard”, theme=”dark”) as app: … app.window.set_title(“Loading…”) … app.add(HTMLString(“Content”))
Note
The class was previously named
Animate. That name still works but is deprecated. Please useAppinstead.- add(item: HTMLObject | str, id: str | None = None) str[source]
Add an item to the display.
- Parameters:
item – An HTMLObject or string to display.
id – Optional custom ID for the item. Auto-generated if not provided.
- Returns:
The ID of the added item.
- clear(item_or_id: HTMLObject | str) bool[source]
Remove an item by ID or by object reference.
- Parameters:
item_or_id – The ID of the item to remove, or the item object itself.
- Returns:
True if the item was found and removed, False otherwise.
- get(id: str) Any[source]
Get an item by ID.
- Parameters:
id – The ID of the item to retrieve.
- Returns:
The item if found, None otherwise.
- get_events() list[InputEvent][source]
Get all pending events without blocking.
- Returns:
A list of all pending InputEvent objects. Empty list if none.
Examples
>>> events = anim.get_events() >>> for event in events: ... print(f"Event: {event.event_type} on {event.id}")
- get_full_state() list[dict[str, str]][source]
Get the full state as a list of rendered items.
- Returns:
…, “html”: …} dicts.
- Return type:
A list of {“id”
- handle_input_event(message: dict[str, Any]) None[source]
Handle an input event from the browser.
This is called by the server when an input event is received. It updates the item’s internal value, calls registered callbacks, and queues the event for polling.
- Parameters:
message – The event message containing id, event type, and value.
- handle_window_event(message: dict[str, Any]) None[source]
Handle a window event from the browser.
This is called by the server when a window event is received.
- Parameters:
message – The event message containing event type and data.
- items() list[tuple[str, Any]][source]
Get a copy of all items.
- Returns:
A list of (id, item) tuples.
- refresh(id: str) bool[source]
Re-render and broadcast a single item.
Use this to manually refresh an item after external changes.
- Parameters:
id – The ID of the item to refresh.
- Returns:
True if item was found and refreshed, False otherwise.
- refresh_all() None[source]
Re-render and broadcast all items.
Use this to manually refresh all items after external changes.
- register_connection(websocket: Any) None[source]
Register a WebSocket connection.
This is called by the server when a new client connects.
- Parameters:
websocket – The WebSocket connection to register.
- remove(item_or_id: HTMLObject | str) bool[source]
Remove an item by ID or by object reference.
- Parameters:
item_or_id – The ID of the item to remove, or the item object itself.
- Returns:
True if the item was found and removed, False otherwise.
- run() App[source]
Start the server in a background thread and open the browser.
- Returns:
Self for method chaining.
- unregister_connection(websocket: Any) None[source]
Unregister a WebSocket connection.
This is called by the server when a client disconnects.
- Parameters:
websocket – The WebSocket connection to unregister.
- update(id: str, item: HTMLObject | str) bool[source]
Update an existing item by ID.
- Parameters:
id – The ID of the item to update.
item – The new content to display.
- Returns:
True if the item was found and updated, False otherwise.
- wait_for_event(timeout: float | None = None) InputEvent | None[source]
Block until an input event occurs.
- Parameters:
timeout – Maximum time to wait in seconds. None means wait forever.
- Returns:
The InputEvent if one occurred, None if timeout expired.
Examples
>>> event = anim.wait_for_event(timeout=1.0) >>> if event and event.event_type == "click": ... print(f"Button {event.id} was clicked!")
HTML Types
HTMLString
- class animaid.HTMLString(content: str = '', **styles: str | CSSValue)[source]
Bases:
HTMLObject,strA string subclass that renders as styled HTML.
HTMLString behaves like a regular Python string but includes methods for applying CSS styles and rendering to HTML. All styling methods modify the object in-place and return self for method chaining.
Examples
>>> s = HTMLString("Hello World") >>> s.bold().color("red").render() '<span style="font-weight: bold; color: red">Hello World</span>'
>>> s = HTMLString("Click me", color="blue", text_decoration="underline") >>> s.render() '<span style="color: blue; text-decoration: underline">Click me</span>'
- add_class(*class_names: str) Self[source]
Add CSS classes in-place.
- Parameters:
*class_names – CSS class names to add.
- Returns:
Self for method chaining.
Example
>>> s = HTMLString("Hello").add_class("highlight", "important") >>> s.render() '<span class="highlight important">Hello</span>'
- background(value: Color | str) Self[source]
Apply specified background color in-place.
- Parameters:
value – CSS color value (e.g., “yellow”, Color.yellow)
- border(value: Border | str) Self[source]
Apply specified border in-place.
- Parameters:
value – CSS border value (e.g., “1px solid black”, Border.solid())
- border_radius(value: Size | str | int | float) Self[source]
Apply specified border radius in-place.
- Parameters:
value – CSS border-radius value (e.g., “5px”, Size.px(5), Size.percent(50))
- color(value: Color | str) Self[source]
Apply specified text color in-place.
- Parameters:
value – CSS color value (e.g., “red”, “#ff0000”, Color.red)
- display(value: Display | str) Self[source]
Apply specified display mode in-place.
- Parameters:
value – CSS display value (e.g., “block”, “flex”, Display.FLEX)
- font_family(value: str) Self[source]
Apply specified font family in-place.
- Parameters:
value – CSS font-family value.
- font_size(value: Size | str | int | float) Self[source]
Apply specified font size in-place.
- Parameters:
value – CSS size value (e.g., “16px”, Size.px(16), Size.em(1.2))
- height(value: Size | str | int | float) Self[source]
Apply specified height in-place.
- Parameters:
value – CSS height value (e.g., “50px”, Size.px(50), Size.vh(100))
- margin(value: Spacing | str | int | float) Self[source]
Apply specified margin in-place.
- Parameters:
value – CSS margin value (e.g., “10px”, Size.px(10), Spacing.all(10))
- opacity(value: str | float) Self[source]
Apply specified opacity in-place.
- Parameters:
value – CSS opacity value (0.0 to 1.0)
- padding(value: Spacing | str | int | float) Self[source]
Apply specified padding in-place.
- Parameters:
value – CSS padding value (e.g., “10px”, Size.px(10))
- render() str[source]
Return HTML representation of this string.
The string content is HTML-escaped to prevent XSS.
- Returns:
A string containing valid HTML.
Example
>>> HTMLString("<script>alert('xss')</script>").render() '<span><script>alert('xss')</script></span>'
- styled(**styles: str | CSSValue) Self[source]
Apply additional inline styles in-place.
Style names use Python convention (underscores) and are converted to CSS convention (hyphens) automatically.
- Parameters:
**styles – CSS property-value pairs. Accepts strings and CSS types. e.g., font_size=”16px” or font_size=Size.px(16)
- Returns:
Self for method chaining.
Example
>>> s = HTMLString("Hello").styled(color="red", font_size="20px") >>> s.render() '<span style="color: red; font-size: 20px">Hello</span>'
>>> s = HTMLString("Hello").styled(color=Color.red, font_size=Size.px(20)) >>> s.render() '<span style="color: red; font-size: 20px">Hello</span>'
- tag(tag_name: str) Self[source]
Change the HTML tag in-place.
- Parameters:
tag_name – The HTML tag to use (e.g., “div”, “p”, “strong”).
- Returns:
Self for method chaining.
Example
>>> s = HTMLString("Hello").tag("strong").render() '<strong>Hello</strong>'
HTMLList
- class animaid.HTMLList(items: list[Any] | None = None, **styles: str | CSSValue)[source]
Bases:
HTMLObject,listA list subclass that renders as styled HTML.
HTMLList behaves like a regular Python list but includes methods for applying CSS styles and rendering to HTML. All styling methods modify the object in-place and return self for method chaining. Supports vertical, horizontal, and grid layouts.
Examples
>>> items = HTMLList(["Apple", "Banana", "Cherry"]) >>> items.render() '<ul><li>Apple</li><li>Banana</li><li>Cherry</li></ul>'
>>> items.horizontal().gap("10px").render() '<div style="display: flex; flex-direction: row; gap: 10px">...</div>'
>>> HTMLList([1, 2, 3]).ordered().render() '<ol><li>1</li><li>2</li><li>3</li></ol>'
- add_class(*class_names: str) Self[source]
Add CSS classes on the container in-place.
- Parameters:
*class_names – CSS class names to add.
- Returns:
Self for method chaining.
- add_item_class(*class_names: str) Self[source]
Add CSS classes to each item in-place.
- Parameters:
*class_names – CSS class names to add to items.
- align_items(value: AlignItems | str) Self[source]
Apply specified cross-axis alignment in-place.
- Parameters:
value – CSS align-items value (e.g., “center”, AlignItems.CENTER).
- background(value: Color | str) Self[source]
Apply background color on the container in-place.
- Parameters:
value – CSS color value (e.g., “white”, Color.white, Color.hex(“#fff”)).
- border(value: Border | str) Self[source]
Apply border around the container in-place.
- Parameters:
value – CSS border value (e.g., “1px solid black”, Border.solid()).
- border_radius(value: Size | str | int | float) Self[source]
Apply rounded corners on the container in-place.
- Parameters:
value – CSS border-radius value (e.g., “5px”, Size.px(5)).
- cards() Self[source]
Apply card list style with shadows and spacing in-place.
Creates a visually appealing list where each item looks like a card.
- color(value: Color | str) Self[source]
Apply text color in-place.
- Parameters:
value – CSS color value (e.g., “black”, Color.black).
- gap(value: Size | str | int | float) Self[source]
Apply specified gap between items in-place.
- Parameters:
value – CSS gap value (e.g., “10px”, Size.px(10), Size.rem(1)).
- grid(columns: int = 3) Self[source]
Apply CSS grid layout in-place.
- Parameters:
columns – Number of columns in the grid.
- Returns:
Self for method chaining.
- height(value: Size | str | int | float) Self[source]
Apply specified height in-place.
- Parameters:
value – CSS height value (e.g., “200px”, Size.px(200), Size.vh(100)).
- horizontal() Self[source]
Apply horizontal layout in-place.
Items are arranged left to right using flexbox.
- horizontal_reverse() Self[source]
Apply reversed horizontal layout in-place.
Items are arranged right to left.
- inline() Self[source]
Apply inline style in-place.
Creates a simple inline list separated by spacing.
- item_background(value: Color | str) Self[source]
Apply background color on each item in-place.
- Parameters:
value – CSS color value.
- item_border(value: Border | str) Self[source]
Apply border around each item in-place.
- Parameters:
value – CSS border value for items.
- item_border_radius(value: Size | str | int | float) Self[source]
Apply rounded corners on each item in-place.
- Parameters:
value – CSS border-radius value for items.
- item_margin(value: Spacing | str | int | float) Self[source]
Apply margin around each item in-place.
- Parameters:
value – CSS margin value for items.
- item_padding(value: Spacing | str | int | float) Self[source]
Apply padding inside each item in-place.
- Parameters:
value – CSS padding value for items.
- justify_content(value: JustifyContent | str) Self[source]
Apply specified main-axis alignment in-place.
- Parameters:
value – CSS justify-content value (e.g., “space-between”).
- margin(value: Spacing | str | int | float) Self[source]
Apply margin outside the container in-place.
- Parameters:
value – CSS margin value (e.g., “10px”, Size.px(10), Spacing.all(10)).
- max_width(value: Size | str | int | float) Self[source]
Apply maximum width constraint in-place.
- Parameters:
value – CSS max-width value (e.g., “800px”, Size.px(800)).
Apply vertical menu style in-place.
Creates a clean vertical menu suitable for navigation.
- padding(value: Spacing | str | int | float) Self[source]
Apply padding inside the container in-place.
- Parameters:
value – CSS padding value (e.g., “10px”, Size.px(10)).
- pills() Self[source]
Apply pill/badge style in-place.
Creates a horizontal list of pill-shaped items.
- render() str[source]
Return HTML representation of this list.
- Returns:
A string containing valid HTML.
- separator(value: Border | str) Self[source]
Apply separator lines between items in-place.
Unlike item_border, this only adds borders between items, not on the outer edges.
- Parameters:
value – CSS border value for separators.
- styled(**styles: str | CSSValue) Self[source]
Apply additional container styles in-place.
- Parameters:
**styles – CSS property-value pairs for the container. Accepts both strings and CSS type objects (Color, Size, etc.)
- Returns:
Self for method chaining.
- tags() Self[source]
Apply tags/labels style in-place.
Creates a horizontal list of tag-style items.
HTMLDict
- class animaid.HTMLDict(data: dict[Any, Any] | None = None, **styles: str | CSSValue)[source]
Bases:
HTMLObject,dictA dict subclass that renders as styled HTML.
HTMLDict behaves like a regular Python dict but includes methods for applying CSS styles and rendering to HTML. All styling methods modify the object in-place and return self for method chaining. Supports definition list, table, and flexbox layouts.
Examples
>>> d = HTMLDict({"name": "Alice", "age": 30}) >>> d.render() '<dl><dt>name</dt><dd>Alice</dd><dt>age</dt><dd>30</dd></dl>'
>>> d.as_table().render() '<table><tr><td>name</td><td>Alice</td></tr>...</table>'
>>> d.key_bold().key_color("blue").render() '<dl><dt style="font-weight: bold; color: blue">name</dt>...'
- add_class(*class_names: str) Self[source]
Add CSS classes on the container in-place.
- Parameters:
*class_names – CSS class names to add.
- Returns:
Self for method chaining.
- add_key_class(*class_names: str) Self[source]
Add CSS classes to keys in-place.
- Parameters:
*class_names – CSS class names to add to keys.
- add_value_class(*class_names: str) Self[source]
Add CSS classes to values in-place.
- Parameters:
*class_names – CSS class names to add to values.
- background(value: Color | str) Self[source]
Apply container background in-place.
- Parameters:
value – CSS color value (e.g., “white”, Color.white, Color.hex(“#fff”)).
- border(value: Border | str) Self[source]
Apply container border in-place.
- Parameters:
value – CSS border value (e.g., “1px solid black”, Border.solid()).
- border_radius(value: Size | str | int | float) Self[source]
Apply rounded container corners in-place.
- Parameters:
value – CSS border-radius value (e.g., “5px”, Size.px(5), Size.percent(50)).
- bordered() Self[source]
Apply bordered cells style in-place.
Each key-value pair has visible borders.
- card() Self[source]
Apply card style with shadow and rounded corners in-place.
Creates a visually appealing card-style display.
- color(value: Color | str) Self[source]
Apply text color in-place.
- Parameters:
value – CSS color value (e.g., “black”, Color.black).
- compact() Self[source]
Apply compact spacing style in-place.
Minimal padding and spacing for dense displays.
- entry_separator(value: Border | str) Self[source]
Apply separator between entries (border) in-place.
- Parameters:
value – CSS border value for separator (e.g., “1px solid gray”).
- gap(value: Size | str | int | float) Self[source]
Apply gap between entries in-place.
- Parameters:
value – CSS gap value (e.g., “10px”, Size.px(10), Size.rem(1)).
- grid(columns: int = 2) Self[source]
Apply grid layout in-place.
- Parameters:
columns – Number of key-value pairs per row.
- key_background(value: Color | str) Self[source]
Apply background color to keys in-place.
- Parameters:
value – CSS color value (e.g., “yellow”, Color.yellow).
- key_color(value: Color | str) Self[source]
Apply color to keys in-place.
- Parameters:
value – CSS color value (e.g., “blue”, Color.blue, Color.hex(“#00f”)).
- key_padding(value: Spacing | str | int | float) Self[source]
Apply padding to keys in-place.
- Parameters:
value – CSS padding value (e.g., “10px”, Size.px(10), Spacing.all(10)).
- key_styled(**styles: str | CSSValue) Self[source]
Apply styles to keys in-place.
- Parameters:
**styles – CSS property-value pairs for keys. Accepts both strings and CSS type objects (Color, Size, etc.)
- key_width(value: Size | str | int | float) Self[source]
Apply fixed key width in-place.
- Parameters:
value – CSS width value (e.g., “100px”, Size.px(100)).
- labeled() Self[source]
Apply label-style keys in-place.
Keys are styled as small labels above values.
- margin(value: Spacing | str | int | float) Self[source]
Apply container margin in-place.
- Parameters:
value – CSS margin value (e.g., “10px”, Size.px(10), Spacing.all(10)).
- max_width(value: Size | str | int | float) Self[source]
Apply maximum width in-place.
- Parameters:
value – CSS max-width value (e.g., “500px”, Size.px(500), Size.vw(80)).
- padding(value: Spacing | str | int | float) Self[source]
Apply container padding in-place.
- Parameters:
value – CSS padding value (e.g., “10px”, Size.px(10)).
- render() str[source]
Return HTML representation of this dictionary.
- Returns:
A string containing valid HTML.
- separator(value: str) Self[source]
Apply a separator between key and value in-place.
- Parameters:
value – Separator string (e.g., “:”, “ -> “, “ = “).
- simple() Self[source]
Apply simple key: value formatting in-place.
Clean, minimal display with colon separators.
- spaced() Self[source]
Apply generous spacing style in-place.
More padding and gaps for readability.
- striped() Self[source]
Apply striped table style in-place.
Creates an alternating row colors table.
- styled(**styles: str | CSSValue) Self[source]
Apply additional container styles in-place.
- Parameters:
**styles – CSS property-value pairs for the container. Accepts both strings and CSS type objects (Color, Size, etc.)
- Returns:
Self for method chaining.
- value_background(value: Color | str) Self[source]
Apply background color to values in-place.
- Parameters:
value – CSS color value (e.g., “lightgray”, Color.hex(“#eee”)).
- value_color(value: Color | str) Self[source]
Apply color to values in-place.
- Parameters:
value – CSS color value (e.g., “green”, Color.green).
- value_padding(value: Spacing | str | int | float) Self[source]
Apply padding to values in-place.
- Parameters:
value – CSS padding value (e.g., “10px”, Size.px(10), Spacing.all(10)).
HTMLSet
- class animaid.HTMLSet(items: Iterable[Any] = (), **styles: str | CSSValue)[source]
Bases:
HTMLObject,setA set subclass that renders as styled HTML.
HTMLSet behaves like a regular Python set but includes methods for applying CSS styles and rendering to HTML. All styling methods modify the object in-place and return self for method chaining. Items are automatically deduplicated (set behavior). Mutations trigger notifications for reactive updates.
Examples
>>> s = HTMLSet({1, 2, 3}) >>> s.render() '<span>{1, 2, 3}</span>'
>>> s.horizontal().pills().render() '<div style="display: flex; ...">...</div>'
>>> HTMLSet([1, 1, 2, 2, 3]) # Duplicates removed HTMLSet({1, 2, 3})
- add_class(*class_names: str) Self[source]
Add CSS classes on the container in-place.
- Parameters:
*class_names – CSS class names to add.
- Returns:
Self for method chaining.
- align_items(value: AlignItems | str) Self[source]
Apply specified cross-axis alignment in-place.
- border_radius(value: Size | str | int | float) Self[source]
Apply rounded corners on the container in-place.
- difference(*others: Iterable[Any]) Self[source]
Return difference with other sets, preserving settings.
- grid(columns: int = 3) Self[source]
Apply CSS grid layout in-place.
- Parameters:
columns – Number of columns in the grid.
- intersection(*others: Iterable[Any]) Self[source]
Return intersection with other sets, preserving settings.
- item_border_radius(value: Size | str | int | float) Self[source]
Apply rounded corners on each item in-place.
- item_margin(value: Spacing | str | int | float) Self[source]
Apply margin around each item in-place.
- item_padding(value: Spacing | str | int | float) Self[source]
Apply padding inside each item in-place.
- justify_content(value: JustifyContent | str) Self[source]
Apply specified main-axis alignment in-place.
- margin(value: Spacing | str | int | float) Self[source]
Apply margin outside the container in-place.
- padding(value: Spacing | str | int | float) Self[source]
Apply padding inside the container in-place.
- render() str[source]
Return HTML representation of this set.
- Returns:
A string containing valid HTML.
- styled(**styles: str | CSSValue) Self[source]
Apply additional container styles in-place.
- Parameters:
**styles – CSS property-value pairs for the container.
- Returns:
Self for method chaining.
- symmetric_difference(other: Iterable[Any]) Self[source]
Return symmetric difference with other set, preserving settings.
CSS Types
Size
- class animaid.Size(value: float | str, unit: str = '')[source]
Bases:
CSSValueRepresents a CSS size/length value with units.
Examples
>>> Size.px(10) Size('10px') >>> Size.em(1.5) Size('1.5em') >>> Size.percent(50) Size('50%') >>> Size.auto() Size('auto')
- KEYWORDS: ClassVar[set[str]] = {'auto', 'fit-content', 'inherit', 'initial', 'max-content', 'min-content', 'none', 'unset'}
Color
- class animaid.Color(value: str)[source]
Bases:
CSSValueRepresents a CSS color value.
Supports named colors, hex codes, rgb(), rgba(), hsl(), and hsla().
Examples
>>> Color.red Color('red') >>> Color.hex("#2563eb") Color('#2563eb') >>> Color.rgb(255, 128, 0) Color('rgb(255, 128, 0)') >>> Color.rgba(255, 128, 0, 0.5) Color('rgba(255, 128, 0, 0.5)')
- NAMED_COLORS: ClassVar[set[str]] = {'aqua', 'black', 'blue', 'brown', 'currentcolor', 'cyan', 'fuchsia', 'gray', 'green', 'grey', 'inherit', 'initial', 'lime', 'magenta', 'maroon', 'navy', 'olive', 'orange', 'pink', 'purple', 'red', 'silver', 'teal', 'transparent', 'unset', 'white', 'yellow'}
- classmethod hex(code: str) Color[source]
Create a color from a hex code.
- Parameters:
code – Hex code with or without ‘#’ prefix
- classmethod hsl(h: int, s: int, lightness: int) Color[source]
Create an HSL color.
- Parameters:
h – Hue (0-360)
s – Saturation (0-100)
lightness – Lightness (0-100)
- classmethod hsla(h: int, s: int, lightness: int, a: float) Color[source]
Create an HSLA color with alpha.
- Parameters:
h – Hue (0-360)
s – Saturation (0-100)
lightness – Lightness (0-100)
a – Alpha (0.0-1.0)
- classmethod rgb(r: int, g: int, b: int) Color[source]
Create an RGB color.
- Parameters:
r – Red component (0-255)
g – Green component (0-255)
b – Blue component (0-255)
Border
- class animaid.Border(width: Size | str | int | float = '1px', style: BorderStyle | str = BorderStyle.SOLID, color: Color | str = 'black')[source]
Bases:
CSSValueRepresents a CSS border value (width + style + color).
Examples
>>> Border(Size.px(1), BorderStyle.SOLID, Color.black) Border('1px solid black') >>> Border.solid(2, "red") Border('2px solid red') >>> Border().width(Size.px(2)).dashed().color(Color.blue) Border('2px dashed blue')
- classmethod dashed(width: Size | str | int | float = 1, color: Color | str = 'black') Border[source]
Create a dashed border.
- Parameters:
width – Border width (default 1px)
color – Border color (default black)
Examples
>>> Border.dashed() Border('1px dashed black') >>> Border.dashed(2, "blue") Border('2px dashed blue')
- classmethod dotted(width: Size | str | int | float = 1, color: Color | str = 'black') Border[source]
Create a dotted border.
- Parameters:
width – Border width (default 1px)
color – Border color (default black)
Examples
>>> Border.dotted() Border('1px dotted black')
- classmethod double(width: Size | str | int | float = 3, color: Color | str = 'black') Border[source]
Create a double border.
- Parameters:
width – Border width (default 3px - minimum for double to show)
color – Border color (default black)
Examples
>>> Border.double() Border('3px double black')
- classmethod medium(color: Color | str = 'black', style: BorderStyle | str = BorderStyle.SOLID) Border[source]
Create a medium border (2px).
- Parameters:
color – Border color (default black)
style – Border style (default solid)
Examples
>>> Border.medium() Border('2px solid black')
- classmethod none() Border[source]
Create a border with no visible style.
Examples
>>> Border.none() Border('1px none black')
- classmethod solid(width: Size | str | int | float = 1, color: Color | str = 'black') Border[source]
Create a solid border.
- Parameters:
width – Border width (default 1px)
color – Border color (default black)
Examples
>>> Border.solid() Border('1px solid black') >>> Border.solid(2, "red") Border('2px solid red')
- style(s: BorderStyle | str) Border[source]
Return a new Border with the specified style.
- property style_value: BorderStyle
The border style.
- classmethod thick(color: Color | str = 'black', style: BorderStyle | str = BorderStyle.SOLID) Border[source]
Create a thick border (4px).
- Parameters:
color – Border color (default black)
style – Border style (default solid)
Examples
>>> Border.thick() Border('4px solid black') >>> Border.thick("navy") Border('4px solid navy')
- classmethod thin(color: Color | str = 'black', style: BorderStyle | str = BorderStyle.SOLID) Border[source]
Create a thin border (1px).
- Parameters:
color – Border color (default black)
style – Border style (default solid)
Examples
>>> Border.thin() Border('1px solid black') >>> Border.thin("red") Border('1px solid red')
Spacing
- class animaid.Spacing(top: Size | str | int | float, right: Size | str | int | float | None = None, bottom: Size | str | int | float | None = None, left: Size | str | int | float | None = None)[source]
Bases:
CSSValueRepresents CSS spacing (padding/margin) with 1-4 values.
Examples
>>> Spacing.all(Size.px(10)) Spacing('10px') >>> Spacing.symmetric(Size.px(10), Size.px(20)) Spacing('10px 20px') >>> Spacing.edges(Size.px(1), Size.px(2), Size.px(3), Size.px(4)) Spacing('1px 2px 3px 4px')
- classmethod all(value: Size | str | int | float) Spacing[source]
Create uniform spacing on all sides.
- classmethod edges(top: Size | str | int | float, right: Size | str | int | float, bottom: Size | str | int | float, left: Size | str | int | float) Spacing[source]
Create spacing with explicit values for all four edges.
- classmethod horizontal(value: Size | str | int | float) Spacing[source]
Create horizontal-only spacing (left and right).
- classmethod section() Spacing[source]
Create typical section margins (24px top/bottom, 0 left/right).
- classmethod symmetric(vertical: Size | str | int | float, horizontal: Size | str | int | float) Spacing[source]
Create symmetric spacing (vertical and horizontal).