Streamlit Theme Component

1.2.3 · active · verified Tue Apr 14

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.

Warnings

Install

Imports

Quickstart

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.")

view raw JSON →