streamlitextras package
Subpackages
- streamlitextras.authenticator package
- streamlitextras.cookiemanager package
- streamlitextras.logger package
- streamlitextras.router package
- streamlitextras.threader package
Submodules
streamlitextras.helpers module
- class CustomHTML[source]
Bases:
objectClass containing custom HTML/CSS to be injected into the streamlit app
- property st_info_classes: list
Classes used by st.info(), used for creating a custom info box with self.custom_el()
- static centered_image(image_path: str) None[source]
Creates 3 streamlit columns with a centered image
- Parameters
image_path (str) – The URL or local path of an image
This is currently unused.
- static anchor_el(anchor_id: str)[source]
Creates a div to be used as a # anchor
- Parameters
anchor_id (str) – the string to set the id property to on the div element
- static bytes_to_data_uri(byteslike_object: _io.BytesIO | streamlit.runtime.uploaded_file_manager.UploadedFile | bytes, mime_type: Optional[str] = None) str[source]
Creates a data URI from a bytesIO object
- Parameters
byteslike_object (Union[BytesIO, UploadedFile]) – BytesIO or bytes or any class that inherits them
mime_type (str) – The mimetype to set on the data URI
- Returns
The data URI as a string
- classmethod download_link(byteslike_object: _io.BytesIO | streamlit.runtime.uploaded_file_manager.UploadedFile | bytes, filename: str, link_text: str = '', mime_type: Optional[str] = None) str[source]
Creates a data URI from a bytesIO object
- Parameters
byteslike_object (Union[BytesIO, UploadedFile]) – BytesIO or bytes or any class that inherits them
filename (str) – The filename presented for the download file
link_text (str) – The text to put inside the link element, defaults to empty string
mime_type (Optional[str]) – The mimetype to set on the data URI. Defaults to “application/octet-stream”
- static custom_el(text: str, tag: str = 'div', align: str = '', color: str = '', anchor: str = '', classes: list = [], extra_style: str = '', props: dict = {}) str[source]
Creates HTML string for a custom element based on the function parameters. There is no validation so ensure calls to this function are correct.
- Parameters
text (str) – the innerText/innerHTML of the element
tag (str) – the HTML tag of the element
align (str) – the CSS text-align property to apply to the element style
color (str) – the css color property to apply to the element style
anchor (str) – if provided, will put an empty div element with this value as an id next to the main element. used for creating anchors.
classes (list) – list of css classes to apply to the class property of the element
extra_style (str) – string of properly formatted CSS rules to be applied to the element style tag
props (dict) – dictionary of properties and values to apply to the element in format {“property”: “value”}
- static display_speaker(speaker_id: str) str[source]
Creates HTML text for a simple paragraph element with the innerText as speaker_id
- Parameters
speaker_id (str) – The text to be inserted in the element innerText/innerHTML
- static display_text(text: str) str[source]
Creates HTML text for a styled paragraph element with the innerText as text
- Parameters
text (str) – The text to be inserted into the paragraph innerText/innerHTML
- static display_table(table_data: list[list], style: str = '') str[source]
Creates HTML table based on table_data which is a 2D list Each list item is a set of columns. The first item is the header.
- static display_audio(audio_file_url: str, timestamp: str | int = '', id: str = 'audio', classes: list = []) str[source]
Creates a HTML audio element with a specified id and special class, this enables more advanced handling of the elements than st.audio()
- Parameters
audio_file_url (str) – The url to the audio file for the element
int] (str Union[str,) – The timestamp in the format HH:MM:SS to apply to the URL fragment, alternatively can be the number of seconds
id (str) – The id property of the audio element
classes (list) – list of css classes to apply to the class property of the element
- lottie_url = 'https://lottie.host/250d8ce6-e7eb-43a7-ab4f-1d78edc49b9d/2TLv74crQZ.json'
- classmethod load_lottieurl(lottie_url: Optional[str] = None) dict | None[source]
Loads and returns JSON from the lottie library This is used for animations
- property lottie_data
streamlitextras.storageservice module
streamlitextras.utils module
- repr_(cls, ignore_keys: Optional[list[str]] = None, only_keys: Optional[list[str]] = None) str[source]
Returns a string detailing a class attributes from cls.__dict__ Makes nice printing for __repr__ implementations
- Parameters
ignore_keys – If provided, these keys will be not be included in the attribute string
only_keys – If provided, these keys will be the only ones included in the attribute string
- save_file(st_file_object: UploadedFile, to_path: str) str[source]
Saves a streamlit UploadedFile BytesIO object to the given relative path
- Parameters
st_file_object (UploadedFile) – The UploadedFile bytes object to save to disk - contains filename and metadata
to_path (str) – The relative path to a folder to save the file to
- Returns str
Will return the relative path which can be used as a URL
streamlitextras.webutils module
- stxs_javascript(source: str) None[source]
Runs javascript on the top level context of the page.
Does this by embedding an iframe that attaches a script tag to its parent.
- Parameters
source (str) – The script source to embed in the <script></script> element
- get_user_timezone(default_tz: Optional[str] = None) Optional[str][source]
Uses javascript to get the tz database name for the browser/users timezone
- Parameters
default_tz (Optional[str]) – value to return if the operation fails. Defaults to UTC
- Returns Optional[str]
The tz database name for the timezone, or None if the operation fails and default_tz isn’t set, or isn’t supported by the browser (unlikely)
- scroll_page(x: int = 0, y: int = 0)[source]
Runs javascript to scroll the streamlit main section Defaults to scrolling to the top if no arguments are passed
- bytes_to_data_uri(byteslike_object: Union[BytesIO, UploadedFile, bytes], mime_type: Optional[str] = None) str[source]
Creates a data URI from a bytesIO object
- Parameters
byteslike_object (Union[BytesIO, UploadedFile]) – BytesIO or bytes or any class that inherits them
mime_type (str) – The mimetype to set on the data URI
- Returns
The data URI as a string
- trigger_download(download_uri: str, filename: str)[source]
Uses javascript and a data URI on a link element to trigger a download for the user