Back to Streamlit

Streamlit API reference

lib/streamlit/.agents/skills/developing-with-streamlit/references/api-reference.md

1.59.021.2 KB
Original Source

Streamlit API reference

Use this as a quick orientation for the public top-level st API. The table below covers the public st.<command>(...) commands, common top-level objects, st.column_config helpers, and public namespaces exposed by the local Streamlit namespace when this reference was written.

Treat summaries as starting points, not complete usage docs. Before using unfamiliar parameters, deprecated options, return values, or command-specific edge cases, inspect the local docstring and signature.

Inspecting local docs from the CLI

Use streamlit docs <COMMAND> to print the signature and docstring for a public Streamlit command from the relevant Streamlit installation:

bash
streamlit docs st.button

It also supports public nested namespace members:

bash
streamlit docs st.column_config.NumberColumn
streamlit docs st.cache_data.clear

For container usage, look up the same top-level command because container methods share the same public element docs:

bash
streamlit docs st.button
# Applies to st.button(...), st.sidebar.button(...), and buttons in other containers.

Run this command with the Streamlit installation relevant to the code being edited. For example, use the active virtual environment, the project's package runner, or the repo's development environment so the docs match that Streamlit version. If COMMAND is omitted, streamlit docs opens the documentation website in a browser instead of printing command docs.

Public st API

APISummary
Top-level commands
st.AppASGI-compatible Streamlit application. Use it for advanced server configuration, including custom routes, startup and shutdown lifecycle hooks, custom middleware, custom exception handlers, FastAPI integration, and programmatic secrets.
st.PageConfigure a page for st.navigation in a multipage app. It creates a page object from a Python file or callable with optional title, icon, URL path, default status, and visibility.
st.altair_chartDisplay a chart using the Vega-Altair library. Use it when native charts are not expressive enough and you need Altair's encodings, layers, tooltips, or interactions.
st.area_chartDisplay an area chart. Use it for common area-chart cases with Streamlit-managed rendering.
st.audioDisplay an audio player. Accepts common audio data sources such as files, URLs, bytes, and arrays.
st.audio_inputDisplay a widget that returns an audio recording from the user's microphone. Use it when an app needs recorded audio as input.
st.badgeDisplay a colored badge with an icon and label. Useful for compact status, category, or metadata indicators.
st.balloonsDraw celebratory balloons. Use sparingly for success moments or lightweight feedback.
st.bar_chartDisplay a bar chart. Use it for straightforward categorical or binned comparisons.
st.buttonDisplay a button widget. It returns True on the script rerun triggered by a click.
st.cacheLegacy caching decorator (deprecated). Do not use in new code; prefer st.cache_data for serializable data and st.cache_resource for shared resources.
st.cache_dataCache the return value of a function. Use it for expensive computations or data-loading steps that return serializable data; each caller receives a copy of the cached value.
st.cache_resourceCache a shared resource returned by a function. Use it for global objects such as database connections, ML models, or clients that should be reused across reruns and sessions.
st.camera_inputDisplay a widget that returns pictures from the user's webcam. It returns an UploadedFile with the captured image when the user takes a picture, and None before then.
st.captionDisplay text in small font. Use it for secondary text, notes, or metadata beneath primary content.
st.chat_inputDisplay a chat input widget. It is designed for conversational apps and returns the submitted message or uploaded files depending on configuration.
st.chat_messageInsert a chat message container. Use it to render messages from users, assistants, or named speakers.
st.checkboxDisplay a checkbox widget. It returns a boolean value.
st.codeDisplay a code block with optional syntax highlighting. Use it for source code, commands, logs, and other preformatted text.
st.color_pickerDisplay a color picker widget. It returns the selected color as a hex string.
st.columnsInsert containers laid out as side-by-side columns. Use it for horizontal layouts and place elements into returned column containers.
st.connectionCreate or retrieve a connection to a data store or API. Use connection classes and secrets to centralize external service access.
st.containerInsert a multi-element container. Use it to group elements, control layout, or append content to a specific location.
st.data_editorDisplay a data editor widget. Use it when users need to edit rows or cells and the app needs the edited data back in Python.
st.dataframeDisplay a dataframe as an interactive table. Supports column configuration, selection, sizing, sorting, and efficient data exploration.
st.date_inputDisplay a date input widget. It can return a single date or a date range depending on the initial value.
st.datetime_inputDisplay a date and time input widget. Use it when users need to choose precise timestamps rather than dates alone.
st.dialogFunction decorator to create a modal dialog. Use it to isolate short workflows while preserving Streamlit's rerun model.
st.dividerDisplay a horizontal rule. Use it to separate sections without adding a heavy layout container.
st.download_buttonDisplay a download button widget. Use it for generated files, reports, transformed data, or other app outputs.
st.echoUse in a with block to draw some code on the app, then execute it. Useful for tutorials, examples, and educational apps.
st.emptyInsert a single-element container. Use it as a placeholder when you need to replace, update, or clear one element later.
st.errorDisplay error message. Use it for failures or blocking conditions that require user attention.
st.exceptionDisplay an exception. Use it to surface caught exceptions and traceback information during debugging or diagnostics.
st.expanderInsert a multi-element container that can be expanded/collapsed. Use it for optional details that should not dominate the main page.
st.feedbackDisplay a feedback widget. It supports compact user reactions such as thumbs, faces, or stars depending on configuration.
st.file_uploaderDisplay a file uploader widget. It returns uploaded file objects and can support multiple files and type filtering.
st.formCreate a form that batches elements together with a "Submit" button. Use it when several inputs should update the app together instead of on every widget change.
st.form_submit_buttonDisplay a form submit button. It must be used inside st.form and triggers the form's batched submission.
st.fragmentDecorator to turn a function into a fragment which can rerun independently of the full app. Use it to reduce rerun cost for isolated interactive sections or run independent, slow sections in parallel during full app reruns.
st.get_optionReturn the current value of a given Streamlit configuration option. Use it for runtime-aware behavior that depends on configured settings.
st.graphviz_chartDisplay a graph using the dagre-d3 library. Use it for directed graphs, diagrams, and node-edge visualizations.
st.headerDisplay text in header formatting. Use it for major sections below the page title.
st.helpDisplay help and other information for a given object. It renders docstrings, signatures, and related information inside the app.
st.htmlInsert HTML into your app. JavaScript is ignored by default (opt in with unsafe_allow_javascript=True); for interactive components that exchange data with Python, use st.components.v2.component() instead.
st.iframeEmbed content in an iframe. Use it to show an external page or embedded resource in a bounded frame.
st.imageDisplay an image or list of images. Accepts paths, URLs, bytes, arrays, and image-like objects.
st.infoDisplay an informational message. Use it for neutral guidance, context, or non-blocking status.
st.jsonDisplay an object or string as a pretty-printed, interactive JSON string. Use it for structured debug output or data inspection.
st.latexDisplay mathematical expressions formatted as LaTeX. Use it for equations and scientific notation.
st.line_chartDisplay a line chart. Use it for trends, time series, and ordered numeric values.
st.link_buttonDisplay a link button element. Use it when the action is navigation to another URL.
st.loginInitiate the login flow for the given provider. Use it with configured auth settings and inspect the local docs for provider-specific behavior.
st.logoRenders a logo in the upper-left corner of your app and its sidebar. Use it for app branding and optional navigation link behavior.
st.logoutLogout the current user. Use it with Streamlit's authentication support.
st.mapDisplay a map with a scatterplot overlaid onto it. Use it for latitude/longitude data when a simple geographic visualization is enough.
st.markdownDisplay string formatted as Markdown. It supports Streamlit-specific extensions such as colored text, badges, icons, and limited HTML when enabled.
st.menu_buttonDisplay a dropdown menu button widget. Use it when a compact button should expose a small set of actions or options.
st.mermaid_chartDisplay a Mermaid diagram. Use it for text-based diagram definitions such as flowcharts, sequence diagrams, class diagrams, and state diagrams.
st.metricDisplay a metric in big bold font, with an optional indicator of how the metric changed. Use it for KPIs, headline numbers, optional inline sparklines (chart_data), and dashboard summaries.
st.multiselectDisplay a multiselect widget. Use it when users can choose multiple items from a list, optionally including new options they enter.
st.navigationConfigure the available pages in a multipage app and where the navigation menu appears (sidebar, top, or hidden). It returns the currently selected page object, which the app should run.
st.number_inputDisplay a numeric input widget. It supports integer and floating-point values, bounds, steps, and formatting.
st.page_linkDisplay a link to another page in a multipage app or to an external page. Use it for explicit navigation elements.
st.paginationDisplay a pagination widget for navigating through pages of content. Use it when a dataset or workflow is split across numbered pages.
st.pdfDisplay a PDF viewer. Use it to render PDF files or bytes directly in the app.
st.pillsDisplay a pills widget. Use it for compact single- or multi-select choices with pill-shaped options.
st.plotly_chartDisplay an interactive Plotly chart. Use it when Plotly is already available or chart interactions/customization require Plotly.
st.popoverInsert a popover container. Use it for compact controls or details that should appear on demand without occupying page space.
st.progressDisplay a progress bar. Use it to communicate completion state for running tasks or staged workflows.
st.pydeck_chartDraw a chart using the PyDeck library. Use it for deck.gl-powered maps and geospatial visualizations.
st.pyplotDisplay a matplotlib.pyplot figure. Use it for existing Matplotlib visualizations or libraries that produce Matplotlib figures.
st.radioDisplay a radio button widget. Use it when users should choose exactly one option from a small visible set.
st.rerunRerun the app or current fragment immediately. Use it to force a rerun after state changes or navigation-like actions.
st.scatter_chartDisplay a scatterplot chart. Use it for relationships between numeric variables, optionally with size and color encodings.
st.segmented_controlDisplay a segmented control widget. Use it for compact mutually exclusive choices, especially mode or view switching.
st.select_sliderDisplay a slider widget to select items from a list. Use it when options are ordered but not necessarily numeric.
st.selectboxDisplay a select widget. Use it for selecting one item from a medium or large set.
st.set_optionSet a configuration option. Use sparingly because not all options are safe or meaningful to change after startup.
st.set_page_configConfigure the default settings of the page. Prefer calling it near the top of the script; repeated calls are additive and override only the parameters you specify.
st.skeletonDisplay a skeleton loading placeholder. Use it standalone (like st.empty) to reserve space and replace it with content later, or as a context manager (like st.spinner) to show a temporary placeholder while a block runs.
st.sliderDisplay a slider widget. Use it for numeric ranges, dates, times, or other ordered values.
st.snowDraw celebratory snowfall. Use sparingly for lightweight success or celebration effects.
st.spaceAdd vertical or horizontal space. Use it for small layout adjustments instead of empty Markdown strings.
st.spinnerDisplay a loading spinner while executing a block of code. Use it as a context manager around work that may take noticeable time.
st.statusInsert a status container to display output from long-running tasks. Use it to show progress, intermediate output, and final state for multi-step operations.
st.stopStops execution immediately. Use it to halt rendering after validation failures, missing inputs, or intentional early exits.
st.subheaderDisplay text in subheader formatting. Use it for subsections under headers.
st.successDisplay a success message. Use it for completed actions or positive status.
st.switch_pageProgrammatically switch the current page in a multipage app. Use it for navigation triggered by app logic.
st.tableDisplay data in a static table. Use it for small, styled tables such as key-value summaries, confusion matrices, or leaderboards, including cells with supported Markdown, when users do not need interactive exploration.
st.tabsInsert containers separated into tabs. Use tabs to switch between related views while rendering all tab content in the same run.
st.textWrite text without Markdown or HTML parsing. Use it for unformatted output.
st.text_areaDisplay a multi-line text input widget. Use it for comments, prompts, notes, and longer free-form input.
st.text_inputDisplay a single-line text input widget. Use it for short free-form input such as names, filters, IDs, or search text.
st.time_inputDisplay a time input widget. Use it when users need to choose a time of day.
st.titleDisplay text in title formatting. Use it for the main page title.
st.toastDisplay a short message, known as a notification "toast". It appears in the app's top-right corner and disappears after four seconds.
st.toggleDisplay a toggle widget. Use it for boolean settings that behave like on/off switches.
st.vega_lite_chartDisplay a chart using the Vega-Lite library. Use it for direct Vega-Lite specifications or when you already have Vega-Lite JSON.
st.videoDisplay a video player. Accepts common video data sources such as files, URLs, bytes, and arrays.
st.warningDisplay warning message. Use it for cautionary or recoverable conditions that need attention.
st.writeDisplays arguments in the app. Use it for quick output, mixed content, and exploratory apps.
st.write_streamStream a generator, iterable, or stream-like sequence to the app. Use it for token streams, incremental text, or progressively produced output.
Top-level objects
st.bottomBottom-pinned container for the main app area. Use it as a container object, not as a function.
st.contextRead-only access to user session context. Exposes headers, cookies, theme (theme.type), timezone, timezone_offset, locale, url, ip_address, and is_embedded.
st.query_paramsMutable mapping for the browser URL query parameters. Use it to read or update URL state.
st.secretsDict-like access to secrets loaded from secrets.toml. Use it for credentials and configuration that should not be hard-coded.
st.session_statePer-session mutable mapping for app state. Use it to persist values across reruns and share state between widgets and app logic.
st.sidebarSidebar container that exposes most element methods as st.sidebar.<command>() and supports with st.sidebar: blocks.
st.userRead-only dict-like object for current user information. Values depend on the hosting and authentication configuration.
st.column_config helpers
st.column_config.AreaChartColumnConfigure an area chart column in st.dataframe or st.data_editor. Use it for compact per-row trends where filled areas are clearer than plain numbers.
st.column_config.AudioColumnConfigure an audio column in st.dataframe or st.data_editor. Use it for audio URLs, paths, or media values that users should be able to play inline.
st.column_config.BarChartColumnConfigure a bar chart column in st.dataframe or st.data_editor. Use it for compact per-row comparisons or small sequences of numeric values.
st.column_config.ButtonColumnConfigure a button column in st.dataframe or st.data_editor. Use it when each row needs an action trigger.
st.column_config.CheckboxColumnConfigure a checkbox column in st.dataframe or st.data_editor. Use it for boolean values, especially editable true/false fields.
st.column_config.ColumnConfigure a generic column in st.dataframe or st.data_editor. Use it for label, width, help text, visibility, disabled state, pinned state, and other shared column metadata.
st.column_config.DateColumnConfigure a date column in st.dataframe or st.data_editor. Use it for date-only display or editing with optional formatting and bounds.
st.column_config.DatetimeColumnConfigure a datetime column in st.dataframe or st.data_editor. Use it for timestamp display or editing with optional formatting, timezone-aware values, and bounds.
st.column_config.ImageColumnConfigure an image column in st.dataframe or st.data_editor. Use it for image URLs, paths, or image-like values that should display visually instead of as text.
st.column_config.JsonColumnConfigure a JSON column in st.dataframe or st.data_editor. Use it for dictionaries, lists, or JSON strings that need structured display.
st.column_config.LineChartColumnConfigure a line chart column in st.dataframe or st.data_editor. Use it for compact per-row trends without the filled area of an area chart.
st.column_config.LinkColumnConfigure a link column in st.dataframe or st.data_editor. Use it for URLs, optionally with validation and display text behavior.
st.column_config.ListColumnConfigure a list column in st.dataframe or st.data_editor. Use it for arrays or repeated values that should render as structured list content.
st.column_config.MarkdownColumnConfigure a markdown column in st.dataframe or st.data_editor. Cells show plain text, and clicking a cell opens an overlay that renders the Markdown.
st.column_config.MultiselectColumnConfigure a multiselect column in st.dataframe or st.data_editor. Use it when each row can contain multiple choices from a known set.
st.column_config.NumberColumnConfigure a number column in st.dataframe or st.data_editor. Use it for integers, floats, currencies, percentages, min/max bounds, step sizes, and numeric formatting.
st.column_config.ProgressColumnConfigure a progress column in st.dataframe or st.data_editor. Use it for percentages, completion values, scores, or bounded progress-like quantities.
st.column_config.SelectboxColumnConfigure a selectbox column in st.dataframe or st.data_editor. Use it when each row should choose exactly one option from a known set.
st.column_config.TextColumnConfigure a text column in st.dataframe or st.data_editor. Use it for strings with optional validation, length bounds, and text-specific display or editing behavior.
st.column_config.TimeColumnConfigure a time column in st.dataframe or st.data_editor. Use it for time-of-day display or editing with optional formatting and bounds.
st.column_config.VideoColumnConfigure a video column in st.dataframe or st.data_editor. Use it for video URLs, paths, or media values that users should be able to play inline.
Public namespaces
st.column_configNamespace of column configuration helpers for st.dataframe and st.data_editor. See the st.column_config helper rows above and inspect helpers such as st.column_config.NumberColumn for exact parameters.
st.componentsNamespace for custom components. Prefer st.components.v2.component() for new HTML/JS components; st.components.v1 is deprecated for new work.