Registry / web-framework / st-theme

st-theme

JSON →
library1.2.3pypypi✓ verified 85d ago

st-theme is a Streamlit component that enables Python applications to retrieve the active theme settings (e.g., colors, font) of the Streamlit app. It is currently at version 1.2.3 and maintains an active development cadence with several minor releases per year, ensuring compatibility and bug fixes.

pip install st-theme
INSTALL
IMPORT
SIG · ST-THEME
S
st-theme
web-frameworkpythonv1.2.3
Install
15.6s avg
Import
1336ms
Disk
433MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 1.728s · 445.1MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 15.6s · import 0.945s · 414MB
433MB installed
● package 433MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

st_theme
from streamlit_theme import st_theme

This quickstart demonstrates how to import and use the `st_theme` component to display the active theme settings of your Streamlit application. It also includes a robust way to handle the scenario where the theme might not be immediately available upon initial page load, providing a fallback.

import streamlit as st from streamlit_theme import st_theme st.set_page_config(layout="centered", page_title="Theme Demo") st.title("Current Streamlit Theme") st.markdown("--- ") theme = st_theme() if theme: st.success("Theme successfully fetched!") st.write("Here are the active theme settings:") st.json(theme) st.info(f"Primary Color: {theme.get('primaryColor', 'N/A')}") st.info(f"Background Color: {theme.get('backgroundColor', 'N/A')}") else: st.warning("Theme could not be fetched immediately. This is a known browser-dependent issue upon initial load. Try changing the theme manually (light/dark mode) or refresh the page. A default theme is used as a fallback for display purposes.") # Provide a default or handle the None case gracefully default_theme = { "base": "light", "primaryColor": "#F63366", "backgroundColor": "#FFFFFF", "secondaryBackgroundColor": "#F0F2F6", "textColor": "#262730", "font": "sans serif" } st.write("Displaying a fallback default theme:") st.json(default_theme) st.info("Using a default light theme as a fallback for display.")
Debug
Known issues
gotchaThe `st-theme` console script, introduced in version 1.2.3, currently returns an error when used with Streamlit version 1.34.0 due to an upstream bug in Streamlit.
fix
This is a known issue (https://github.com/streamlit/streamlit/issues/8606). Avoid using the console script with Streamlit 1.34.0. The core component functionality within a Streamlit app is unaffected.
affects: st-theme >=1.2.3 with Streamlit 1.34.0
gotchaUpon initial page load, `st_theme()` might return `None` due to a browser-dependent bug where the theme is not immediately available. It updates correctly when the user changes the theme.
fix
It is recommended to set a default theme configuration for your app and use its value if `st_theme()` returns `None` during initial rendering. Implement a check like `if theme: ... else: use_default_theme()`.
affects: All versions
gotchaThe `st_theme` function includes a `adjust` parameter (default `True`) that applies a CSS adjustment to remove extra space from the component. While generally safe, this CSS adjustment might, in rare cases, interfere with other elements of your Streamlit app.
fix
If you encounter unexpected CSS conflicts, pass `adjust=False` to the `st_theme()` function (e.g., `theme = st_theme(adjust=False)`). You can then apply your own custom CSS adjustments using `st.html` (or `st.markdown` in older Streamlit versions) if necessary.
affects: All versions
gotchaBe aware of other similarly named libraries like `streamlit-themes` (note the hyphen). The `st-theme` library (this entry) is for *retrieving* the active theme, while `streamlit-themes` focuses on *setting* themes and has its own caveats, including accessing internal Streamlit configurations which may break in future updates.
fix
Ensure you import from `streamlit_theme` and understand its purpose of returning the *current* active theme, not modifying it. If you intend to *set* themes, `streamlit-themes` is a different library with different usage patterns and risks.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'st_theme'
The `st-theme` package is either not installed in your environment or the import statement uses an incorrect module name.
fix
Install the package using `pip install st-theme` and ensure your import statement is `import st_theme` or `from st_theme import get_theme`.
AttributeError: module 'st_theme' has no attribute 'get_current_theme'
You are attempting to call a function named `get_current_theme` which does not exist in the `st_theme` module, or it has been misspelled.
fix
Use the correct function name `st_theme.get_theme()` to retrieve the active Streamlit theme settings.
st-theme get_theme returns None
The `st_theme.get_theme()` function returns `None` when the Streamlit application is not running in a live Streamlit environment (e.g., in a local script without `streamlit run`) or if it fails to retrieve theme information.
fix
Ensure your Streamlit app is running via `streamlit run your_app.py`. For robustness, handle `None` by providing default theme values, e.g., `theme = st_theme.get_theme() or {}`.
KeyError: 'primary_color'
You are trying to access a theme property using an incorrect key name, often due to a mismatch in casing (e.g., `primary_color` instead of `primaryColor`) or trying to access a non-existent key.
fix
Inspect the keys available in the returned theme dictionary by printing it (e.g., `print(theme)`) and use the correct casing for properties like `theme['primaryColor']`.
Upgrade
Version history
1.2.3latest on PyPI · released May 3, 2024
Audit
Dependencies
streamlitrequiredRequired for running Streamlit applications and using Streamlit components. Requires Streamlit >=1.20.
Agent activity
8 hits · last 30 days
node
7
Resources
st-theme — pip install st-theme · libregistry