Python Components¶
Component definitions.
All CamelCase names in the namespace should be components.
FormField
module-attribute
¶
FormField = Union[FormFieldInput, FormFieldTextarea, FormFieldBoolean, FormFieldFile, FormFieldSelect, FormFieldSelectSearch]
Union of all form field types.
CodeStyle
module-attribute
¶
Code style to apply to a Code
component.
Attributes:
Name | Type | Description |
---|---|---|
codeStyle |
The code style to apply. If None, no style is applied. |
See Also
AnyComponent
module-attribute
¶
AnyComponent = Annotated[Union[Text, Paragraph, PageTitle, Div, Page, Heading, Markdown, Code, Json, Button, Link, LinkList, Navbar, Footer, Modal, ServerLoad, Image, Iframe, Video, FireEvent, Error, Spinner, Custom, Table, Pagination, Display, Details, Form, FormField, ModelForm, Toast], Field(discriminator='type')]
Union of all components.
Pydantic discriminator field is set to 'type' to allow for efficient serialization and deserialization of the components.
Details ¶
Bases: BaseModel
Details associated with displaying a data model.
fields
class-attribute
instance-attribute
¶
fields: Union[List[Union[DisplayLookup, Display]], None] = None
Fields to display.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the details component.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'Details'.
Display ¶
Bases: DisplayBase
Description of how to display a value, either in a table or detail view.
mode
class-attribute
instance-attribute
¶
Display mode for the value.
title
class-attribute
instance-attribute
¶
Title to display for the value.
on_click
class-attribute
instance-attribute
¶
Event to trigger when the value is clicked.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'Display'.
Form ¶
Bases: BaseForm
Form component.
initial
class-attribute
instance-attribute
¶
Initial values for the form fields, mapping field names to values.
method
class-attribute
instance-attribute
¶
HTTP method to use for the form submission.
display_mode
class-attribute
instance-attribute
¶
Display mode for the form.
submit_on_change
class-attribute
instance-attribute
¶
Whether to submit the form on change.
submit_trigger
class-attribute
instance-attribute
¶
Event to trigger form submission.
loading
class-attribute
instance-attribute
¶
loading: Union[List[AnyComponent], None] = None
Components to display while the form is submitting.
footer
class-attribute
instance-attribute
¶
footer: Union[List[AnyComponent], None] = None
Components to display in the form footer.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the form's HTML component.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'Form'.
FormFieldBoolean ¶
Bases: BaseFormField
Form field for boolean input.
title
instance-attribute
¶
Title of the field to display. Can be a list of strings for multi-line titles.
required
class-attribute
instance-attribute
¶
Whether the field is required. Defaults to False.
error
class-attribute
instance-attribute
¶
Error message to display if the field is invalid.
locked
class-attribute
instance-attribute
¶
Whether the field is locked. Defaults to False.
description
class-attribute
instance-attribute
¶
Description of the field.
display_mode
class-attribute
instance-attribute
¶
Display mode for the field.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the field's HTML component.
initial
class-attribute
instance-attribute
¶
Initial value for the field.
mode
class-attribute
instance-attribute
¶
Mode for the boolean field.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'FormFieldBoolean'.
FormFieldFile ¶
Bases: BaseFormField
Form field for file input.
title
instance-attribute
¶
Title of the field to display. Can be a list of strings for multi-line titles.
required
class-attribute
instance-attribute
¶
Whether the field is required. Defaults to False.
error
class-attribute
instance-attribute
¶
Error message to display if the field is invalid.
locked
class-attribute
instance-attribute
¶
Whether the field is locked. Defaults to False.
description
class-attribute
instance-attribute
¶
Description of the field.
display_mode
class-attribute
instance-attribute
¶
Display mode for the field.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the field's HTML component.
multiple
class-attribute
instance-attribute
¶
Whether multiple files can be selected.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'FormFieldFile'.
FormFieldInput ¶
Bases: BaseFormField
Form field for basic input.
title
instance-attribute
¶
Title of the field to display. Can be a list of strings for multi-line titles.
required
class-attribute
instance-attribute
¶
Whether the field is required. Defaults to False.
error
class-attribute
instance-attribute
¶
Error message to display if the field is invalid.
locked
class-attribute
instance-attribute
¶
Whether the field is locked. Defaults to False.
description
class-attribute
instance-attribute
¶
Description of the field.
display_mode
class-attribute
instance-attribute
¶
Display mode for the field.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the field's HTML component.
html_type
class-attribute
instance-attribute
¶
HTML input type for the field.
initial
class-attribute
instance-attribute
¶
Initial value for the field.
placeholder
class-attribute
instance-attribute
¶
Placeholder text for the field.
autocomplete
class-attribute
instance-attribute
¶
Autocomplete value for the field.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'FormFieldInput'.
FormFieldSelect ¶
Bases: BaseFormField
Form field for select input.
title
instance-attribute
¶
Title of the field to display. Can be a list of strings for multi-line titles.
required
class-attribute
instance-attribute
¶
Whether the field is required. Defaults to False.
error
class-attribute
instance-attribute
¶
Error message to display if the field is invalid.
locked
class-attribute
instance-attribute
¶
Whether the field is locked. Defaults to False.
description
class-attribute
instance-attribute
¶
Description of the field.
display_mode
class-attribute
instance-attribute
¶
Display mode for the field.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the field's HTML component.
multiple
class-attribute
instance-attribute
¶
Whether multiple options can be selected.
initial
class-attribute
instance-attribute
¶
Initial value for the field.
vanilla
class-attribute
instance-attribute
¶
Whether to use a vanilla (plain) select element.
placeholder
class-attribute
instance-attribute
¶
Placeholder text for the field.
autocomplete
class-attribute
instance-attribute
¶
Autocomplete value for the field.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'FormFieldSelect'.
FormFieldSelectSearch ¶
Bases: BaseFormField
Form field for searchable select input.
title
instance-attribute
¶
Title of the field to display. Can be a list of strings for multi-line titles.
required
class-attribute
instance-attribute
¶
Whether the field is required. Defaults to False.
error
class-attribute
instance-attribute
¶
Error message to display if the field is invalid.
locked
class-attribute
instance-attribute
¶
Whether the field is locked. Defaults to False.
description
class-attribute
instance-attribute
¶
Description of the field.
display_mode
class-attribute
instance-attribute
¶
Display mode for the field.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the field's HTML component.
multiple
class-attribute
instance-attribute
¶
Whether multiple options can be selected.
initial
class-attribute
instance-attribute
¶
Initial value for the field.
debounce
class-attribute
instance-attribute
¶
Time in milliseconds to debounce requests by. Defaults to 300ms.
placeholder
class-attribute
instance-attribute
¶
Placeholder text for the field.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'FormFieldSelectSearch'.
ModelForm ¶
Bases: BaseForm
Form component generated from a Pydantic model.
initial
class-attribute
instance-attribute
¶
Initial values for the form fields, mapping field names to values.
method
class-attribute
instance-attribute
¶
HTTP method to use for the form submission.
display_mode
class-attribute
instance-attribute
¶
Display mode for the form.
submit_on_change
class-attribute
instance-attribute
¶
Whether to submit the form on change.
submit_trigger
class-attribute
instance-attribute
¶
Event to trigger form submission.
loading
class-attribute
instance-attribute
¶
loading: Union[List[AnyComponent], None] = None
Components to display while the form is submitting.
footer
class-attribute
instance-attribute
¶
footer: Union[List[AnyComponent], None] = None
Components to display in the form footer.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the form's HTML component.
model
class-attribute
instance-attribute
¶
Pydantic model from which to generate the form.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'ModelForm'.
Pagination ¶
Bases: BaseModel
Pagination component to use with tables.
page_query_param
class-attribute
instance-attribute
¶
The query parameter to use for the page number.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the pagination's HTML component.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'Pagination'.
Table ¶
Bases: BaseModel
Table component.
data
instance-attribute
¶
Sequence of data models to display in the table.
columns
class-attribute
instance-attribute
¶
List of columns to display in the table. If not provided, columns will be inferred from the data model.
data_model
class-attribute
instance-attribute
¶
Data model to use for the table. If not provided, the model will be inferred from the first data item.
no_data_message
class-attribute
instance-attribute
¶
Message to display when there is no data.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the paragraph's HTML component.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'Table'.
Text ¶
Paragraph ¶
PageTitle ¶
Div ¶
Bases: BaseModel
A generic container component.
components
instance-attribute
¶
components: List[AnyComponent]
List of components to render inside the div.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the div's HTML component.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'Div'.
Page ¶
Bases: BaseModel
Similar to container
in many UI frameworks, this acts as a root component for most pages.
components
instance-attribute
¶
components: List[AnyComponent]
List of components to render on the page.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the page's HTML component.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'Page'.
Heading ¶
Bases: BaseModel
Heading component.
level
class-attribute
instance-attribute
¶
The level of the heading. 1 is the largest, 6 is the smallest.
html_id
class-attribute
instance-attribute
¶
Optional HTML ID to apply to the heading's HTML component.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the page's HTML component.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'Heading'.
Markdown ¶
Bases: BaseModel
Markdown component that renders markdown text.
code_style
class-attribute
instance-attribute
¶
code_style: CodeStyle = None
Optional code style to apply to the markdown text.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the page's HTML component.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'Markdown'.
Code ¶
Bases: BaseModel
Code component that renders code with syntax highlighting.
language
class-attribute
instance-attribute
¶
Optional language of the code. If None, no syntax highlighting is applied.
code_style
class-attribute
instance-attribute
¶
code_style: CodeStyle = None
Optional code style to apply to the code.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the page's HTML component.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'Code'.
Json ¶
Button ¶
Bases: BaseModel
Button component.
on_click
class-attribute
instance-attribute
¶
Optional event to trigger when the button is clicked.
html_type
class-attribute
instance-attribute
¶
Optional HTML type of the button. If None, defaults to 'button'.
named_style
class-attribute
instance-attribute
¶
Optional named style to apply to the button.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the button's HTML component.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'Button'.
Link ¶
Bases: BaseModel
Link component.
components
instance-attribute
¶
components: List[AnyComponent]
List of components to render attached to the link.
on_click
class-attribute
instance-attribute
¶
Optional event to trigger when the link is clicked.
mode
class-attribute
instance-attribute
¶
Optional mode of the link.
active
class-attribute
instance-attribute
¶
Optional active state of the link.
locked
class-attribute
instance-attribute
¶
Optional locked state of the link.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the link's HTML component.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'Link'.
LinkList ¶
Bases: BaseModel
List of Link components.
Navbar ¶
Bases: BaseModel
Navbar component used for moving between pages.
title
class-attribute
instance-attribute
¶
Optional title to display in the navbar.
title_event
class-attribute
instance-attribute
¶
Optional event to trigger when the title is clicked. Often used to navigate to the home page.
start_links
class-attribute
instance-attribute
¶
start_links: List[Link] = []
List of links to render at the start of the navbar.
end_links
class-attribute
instance-attribute
¶
end_links: List[Link] = []
List of links to render at the end of the navbar.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the navbar's HTML component.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'Navbar'.
Footer ¶
Bases: BaseModel
Footer component.
Modal ¶
Bases: BaseModel
Modal component that displays a modal dialog.
footer
class-attribute
instance-attribute
¶
footer: Union[List[AnyComponent], None] = None
Optional list of components to render in the modal footer.
open_trigger
class-attribute
instance-attribute
¶
Optional event to trigger when the modal is opened.
open_context
class-attribute
instance-attribute
¶
Optional context to pass to the open trigger event.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the modal's HTML component.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'Modal'.
ServerLoad ¶
Bases: BaseModel
A component that will be replaced by the server with the component returned by the given URL.
load_trigger
class-attribute
instance-attribute
¶
Optional event to trigger when the component is loaded.
components
class-attribute
instance-attribute
¶
components: Union[List[AnyComponent], None] = None
Optional list of components to render while the server is loading the new component(s).
sse
class-attribute
instance-attribute
¶
Optional flag to enable server-sent events (SSE) for the server load.
sse_retry
class-attribute
instance-attribute
¶
Optional time in milliseconds to retry the SSE connection.
method
class-attribute
instance-attribute
¶
Optional HTTP method to use when loading the component.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'ServerLoad'.
Image ¶
Bases: BaseModel
Image container component.
alt
class-attribute
instance-attribute
¶
Optional alt text for the image.
width
class-attribute
instance-attribute
¶
Optional width used to display the image.
height
class-attribute
instance-attribute
¶
Optional height used to display the image.
referrer_policy
class-attribute
instance-attribute
¶
referrer_policy: Union[Literal['no-referrer', 'no-referrer-when-downgrade', 'origin', 'origin-when-cross-origin', 'same-origin', 'strict-origin', 'strict-origin-when-cross-origin', 'unsafe-url'], None] = None
Optional referrer policy for the image. Specifies what information to send when fetching the image.
For more info, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy.
loading
class-attribute
instance-attribute
¶
Optional loading strategy for the image.
on_click
class-attribute
instance-attribute
¶
Optional event to trigger when the image is clicked.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the image's HTML component.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'Image'.
Iframe ¶
Bases: BaseModel
Iframe component that displays content from a URL.
title
class-attribute
instance-attribute
¶
Optional title for the iframe.
width
class-attribute
instance-attribute
¶
Optional width used to display the iframe.
height
class-attribute
instance-attribute
¶
Optional height used to display the iframe.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the iframe's HTML component.
srcdoc
class-attribute
instance-attribute
¶
Optional HTML content to display in the iframe.
sandbox
class-attribute
instance-attribute
¶
Optional sandbox policy for the iframe. Specifies restrictions on the HTML content in the iframe.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'Iframe'.
Video ¶
Bases: BaseModel
Video component that displays a video or multiple videos.
autoplay
class-attribute
instance-attribute
¶
Optional flag to enable autoplay for the video.
controls
class-attribute
instance-attribute
¶
Optional flag to enable controls (pause, play, etc) for the video.
loop
class-attribute
instance-attribute
¶
Optional flag to enable looping for the video.
muted
class-attribute
instance-attribute
¶
Optional flag to mute the video.
poster
class-attribute
instance-attribute
¶
Optional URL to an image to display as the video poster (what is shown when the video is loading or until the user plays it).
width
class-attribute
instance-attribute
¶
Optional width used to display the video.
height
class-attribute
instance-attribute
¶
Optional height used to display the video.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the video's HTML component.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'Video'.
FireEvent ¶
Error ¶
Bases: BaseModel
Utility component used to display an error.
Spinner ¶
Bases: BaseModel
Spinner component that displays a loading spinner.
Toast ¶
Bases: BaseModel
Toast component that displays a toast message (small temporary message).
position
class-attribute
instance-attribute
¶
position: Union[Literal['top-start', 'top-center', 'top-end', 'middle-start', 'middle-center', 'middle-end', 'bottom-start', 'bottom-center', 'bottom-end'], None] = None
Optional position of the toast.
open_trigger
class-attribute
instance-attribute
¶
Optional event to trigger when the toast is opened.
open_context
class-attribute
instance-attribute
¶
Optional context to pass to the open trigger event.
class_name
class-attribute
instance-attribute
¶
Optional class name to apply to the toast's HTML component.
type
class-attribute
instance-attribute
¶
The type of the component. Always 'Toast'.
Custom ¶
Bases: BaseModel
Custom component that allows for special data to be rendered.