Skip to content

Latest commit

 

History

History
119 lines (64 loc) · 4.36 KB

streamlit_pydantic.ui_renderer.md

File metadata and controls

119 lines (64 loc) · 4.36 KB

module streamlit_pydantic.ui_renderer


function pydantic_input

pydantic_input(
    key: str,
    model: Type[BaseModel],
    group_optional_fields: GroupOptionalFieldsStrategy = 'no',
    lowercase_labels: bool = False,
    ignore_empty_values: bool = False
) → Dict

Auto-generates input UI elements for a selected Pydantic class.

Args:

  • key (str): A string that identifies the form. Each form must have its own key.
  • model (Type[BaseModel]): The input model. Either a class or instance based on Pydantic BaseModel or Python dataclass.
  • group_optional_fields (str, optional): If sidebar, optional input elements will be rendered on the sidebar. If expander, optional input elements will be rendered inside an expander element. Defaults to no.
  • lowercase_labels (bool): If True, all input element labels will be lowercased. Defaults to False.
  • ignore_empty_values (bool): If True, empty values for strings and numbers will not be stored in the session state. Defaults to False.

Returns:

  • Dict: A dictionary with the current state of the input data.

function pydantic_output

pydantic_output(output_data: Any) → None

Auto-generates output UI elements for all properties of a (Pydantic-based) model instance.

Args:

  • output_data (Any): The output data.

function pydantic_form

pydantic_form(
    key: str,
    model: Type[~T],
    submit_label: str = 'Submit',
    clear_on_submit: bool = False,
    group_optional_fields: GroupOptionalFieldsStrategy = 'no',
    lowercase_labels: bool = False,
    ignore_empty_values: bool = False
) → Union[~T, NoneType]

Auto-generates a Streamlit form based on the given (Pydantic-based) input class.

Args:

  • key (str): A string that identifies the form. Each form must have its own key.
  • model (Type[BaseModel]): The input model. Either a class or instance based on Pydantic BaseModel or Python dataclass.
  • submit_label (str): A short label explaining to the user what this button is for. Defaults to “Submit”.
  • clear_on_submit (bool): If True, all widgets inside the form will be reset to their default values after the user presses the Submit button. Defaults to False.
  • group_optional_fields (str, optional): If sidebar, optional input elements will be rendered on the sidebar. If expander, optional input elements will be rendered inside an expander element. Defaults to no.
  • lowercase_labels (bool): If True, all input element labels will be lowercased. Defaults to False.
  • ignore_empty_values (bool): If True, empty values for strings and numbers will not be stored in the session state. Defaults to False.

Returns:

  • Optional[BaseModel]: An instance of the given input class, if the submit button is used and the input data passes the Pydantic validation.

class GroupOptionalFieldsStrategy

An enumeration.


This file was automatically generated via lazydocs.