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-themeVerified import paths — ran on the pinned version, not inferred.
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.
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.
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()`.
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.
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.
Install the package using `pip install st-theme` and ensure your import statement is `import st_theme` or `from st_theme import get_theme`.
Use the correct function name `st_theme.get_theme()` to retrieve the active Streamlit theme settings.
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 {}`.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']`.