Enumerations¶
Component type definitions and registry for the streamlit_rich_message_history package.
This module defines the core component types and provides a registry system for extending the package with custom component types, detectors, and renderers.
- class streamlit_rich_message_history.enums.ComponentRegistry[source]¶
Bases:
object
Registry to manage custom component types, detectors, and renderers.
This class provides static methods for registering and retrieving: - Custom component types (extending ComponentType) - Type detection functions that identify content types - Rendering functions that display specific content types
The registry is a central point for extending the package with custom components.
- classmethod get_all_types()[source]¶
Get all component types (built-in and custom).
- Returns:
List containing all ComponentType values
- Return type:
list
- classmethod get_custom_type(name)[source]¶
Get a custom component type by name.
- Parameters:
name (
str
) – String identifier of the component type- Returns:
The component type if found, None otherwise
- Return type:
- classmethod get_detector(comp_type)[source]¶
Get the detector function for a component type.
- Parameters:
comp_type (
ComponentType
) – The component type to get the detector for- Returns:
The detector function if registered, None otherwise
- Return type:
Callable
- classmethod get_renderer(comp_type)[source]¶
Get the renderer function for a component type.
- Parameters:
comp_type (
ComponentType
) – The component type to get the renderer for- Returns:
The renderer function if registered, None otherwise
- Return type:
Callable
- classmethod register_component_type(name)[source]¶
Register a new component type with the given name. If a component type with this name already exists, returns the existing type with a warning instead of raising an exception.
- Parameters:
name (
str
) – String identifier for the new component type- Returns:
The newly created component type or existing component type
- Return type:
Examples
>>> IMAGE_TYPE = ComponentRegistry.register_component_type("image") >>> # IMAGE_TYPE can now be used like a standard ComponentType >>> # Registering the same type again will return the existing type >>> SAME_IMAGE_TYPE = ComponentRegistry.register_component_type("image") >>> # A warning will be printed and SAME_IMAGE_TYPE == IMAGE_TYPE
- classmethod register_detector(comp_type, detector)[source]¶
Register a detector function for a component type.
The detector function determines if content should be treated as this component type.
- Parameters:
comp_type (
ComponentType
) – The component type to register a detector fordetector (
Callable
[[Any
,Dict
[str
,Any
]],bool
]) – Function that takes content and kwargs and returns True if the content should be handled as this component type
- Return type:
None
Examples
>>> def image_detector(content, kwargs): return isinstance(content, PIL.Image.Image) >>> ComponentRegistry.register_detector(IMAGE_TYPE, image_detector)
- classmethod register_renderer(comp_type, renderer)[source]¶
Register a renderer function for a component type.
The renderer function handles displaying the content in a Streamlit app.
- Parameters:
comp_type (
ComponentType
) – The component type to register a renderer forrenderer (
Callable
[[Any
,Dict
[str
,Any
]],None
]) – Function that takes content and kwargs and renders it in Streamlit
- Return type:
None
Examples
>>> def image_renderer(content, kwargs): st.image(content, **{k: v for k, v in kwargs.items() if k in ['caption', 'width', 'use_column_width']}) >>> ComponentRegistry.register_renderer(IMAGE_TYPE, image_renderer)
- class streamlit_rich_message_history.enums.ComponentType(value)[source]¶
Bases:
Enum
Enum defining the possible message component types.
These types correspond to different ways content can be displayed in messages, such as text, dataframes, charts, etc.
- TEXT¶
Plain text content
- DATAFRAME¶
Pandas DataFrame display
- SERIES¶
Pandas Series display
- MATPLOTLIB_FIGURE¶
Matplotlib plot
- PLOTLY_FIGURE¶
Plotly chart
- NUMBER¶
Numeric value
- ERROR¶
Error message
- CODE¶
Code snippet with syntax highlighting
- METRIC¶
Metric with optional delta
- TABLE¶
Static table display
- JSON¶
JSON data viewer
- HTML¶
HTML content
- LIST¶
List of items
- TUPLE¶
Tuple of items
- DICT¶
Dictionary of items
- CODE = 'code'¶
- DATAFRAME = 'dataframe'¶
- DICT = 'dict'¶
- ERROR = 'error'¶
- HTML = 'html'¶
- JSON = 'json'¶
- LIST = 'list'¶
- MATPLOTLIB_FIGURE = 'matplotlib_figure'¶
- METRIC = 'metric'¶
- NUMBER = 'number'¶
- PLOTLY_FIGURE = 'plotly_figure'¶
- SERIES = 'series'¶
- TABLE = 'table'¶
- TEXT = 'text'¶
- TUPLE = 'tuple'¶