{"id":6251,"library":"st-theme","title":"Streamlit Theme Component","description":"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.","status":"active","version":"1.2.3","language":"en","source_language":"en","source_url":"https://github.com/gabrieltempass/streamlit-theme","tags":["streamlit","theme","component","ui","frontend"],"install":[{"cmd":"pip install st-theme","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for running Streamlit applications and using Streamlit components. Requires Streamlit >=1.20.","package":"streamlit","optional":false}],"imports":[{"symbol":"st_theme","correct":"from streamlit_theme import st_theme"}],"quickstart":{"code":"import streamlit as st\nfrom streamlit_theme import st_theme\n\nst.set_page_config(layout=\"centered\", page_title=\"Theme Demo\")\n\nst.title(\"Current Streamlit Theme\")\nst.markdown(\"--- \")\n\ntheme = st_theme()\n\nif theme:\n    st.success(\"Theme successfully fetched!\")\n    st.write(\"Here are the active theme settings:\")\n    st.json(theme)\n    st.info(f\"Primary Color: {theme.get('primaryColor', 'N/A')}\")\n    st.info(f\"Background Color: {theme.get('backgroundColor', 'N/A')}\")\nelse:\n    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.\")\n    # Provide a default or handle the None case gracefully\n    default_theme = {\n        \"base\": \"light\",\n        \"primaryColor\": \"#F63366\",\n        \"backgroundColor\": \"#FFFFFF\",\n        \"secondaryBackgroundColor\": \"#F0F2F6\",\n        \"textColor\": \"#262730\",\n        \"font\": \"sans serif\"\n    }\n    st.write(\"Displaying a fallback default theme:\")\n    st.json(default_theme)\n    st.info(\"Using a default light theme as a fallback for display.\")","lang":"python","description":"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."},"warnings":[{"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.","message":"The `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.","severity":"gotcha","affected_versions":"st-theme >=1.2.3 with Streamlit 1.34.0"},{"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()`.","message":"Upon 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Be 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}