{"id":7769,"library":"streamlit-toggle-switch","title":"Streamlit Toggle Switch","description":"streamlit-toggle-switch is a Streamlit custom component that provides a customizable toggle switch widget, offering options for color and placement. The current version is 1.0.2. The library has not seen updates since late 2022, and its functionality has largely been superseded by a native Streamlit widget.","status":"deprecated","version":"1.0.2","language":"en","source_language":"en","source_url":"https://github.com/sqlinsights/streamlit-toggle-switch","tags":["streamlit","toggle","switch","custom component","deprecated"],"install":[{"cmd":"pip install streamlit-toggle-switch","lang":"bash","label":"Install via pip"}],"dependencies":[],"imports":[{"note":"The installed package `streamlit-toggle-switch` is imported as `streamlit_toggle`.","wrong":"from streamlit_toggle_switch import st_toggle_switch","symbol":"st_toggle_switch","correct":"from streamlit_toggle import st_toggle_switch"},{"note":"Native Streamlit widget, preferred over this custom component.","symbol":"st.toggle","correct":"import streamlit as st\non = st.toggle('Activate feature')"}],"quickstart":{"code":"import streamlit as st\nfrom streamlit_toggle import st_toggle_switch\n\nst.title('Custom Toggle Switch Demo')\n\n# Example using the custom component\nis_enabled = st_toggle_switch(\n    label='Enable Feature X',\n    key='feature_x_toggle',\n    default_value=False,\n    label_after=True,\n    inactive_color='#D3D3D3',  # Optional\n    active_color='#11567f',   # Optional\n    track_color='#29B5E8'     # Optional\n)\n\nif is_enabled:\n    st.write('Feature X is enabled!')\nelse:\n    st.write('Feature X is disabled.')\n\nst.subheader('Native Streamlit Toggle (Recommended)')\n\nnative_toggle_on = st.toggle('Activate native feature')\nif native_toggle_on:\n    st.write('Native feature activated!')\n","lang":"python","description":"This quickstart demonstrates how to use the `streamlit-toggle-switch` component and also includes the recommended native `st.toggle` widget for comparison."},"warnings":[{"fix":"Migrate to `st.toggle`. For custom styling, consider `st.toggle` with custom CSS or alternatives like `streamlit-option-menu` if more complex navigation is needed.","message":"This custom component is officially deprecated by its author in favor of Streamlit's native `st.toggle` widget, which offers similar functionality and is better integrated into the Streamlit ecosystem.","severity":"breaking","affected_versions":"All versions"},{"fix":"Always use `import streamlit_toggle as tog` (or similar alias) after `pip install streamlit-toggle-switch`.","message":"The package name for installation is `streamlit-toggle-switch`, but the Python module to import is `streamlit_toggle`. This can lead to `ModuleNotFoundError` or `AttributeError` if the wrong module name is used in `import` statements.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For complex interactions, use the native `st.toggle` with its `on_change` parameter and `st.session_state` for reliable state management. If using the custom component, explicitly manage state in `st.session_state` based on the returned value.","message":"The `streamlit-toggle-switch` component, like many custom components, may not offer direct `on_change` callbacks for immediate state updates as robustly as native Streamlit widgets. This can lead to 'two-click' issues or require manual session state management.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure you have installed `streamlit-toggle-switch` correctly. The correct import path is `from streamlit_toggle import st_toggle_switch`. Some users reported success with Python 3.8.5 or 3.8.10 when encountering similar issues.","cause":"This error often occurs due to an incorrect import statement, typically trying to import `st_toggle_switch` directly from a module name that doesn't expose it, or using an incompatible Python version.","error":"AttributeError: module 'streamlit_toggle' has no attribute 'st_toggle_switch'"},{"fix":"Verify installation with `pip show streamlit-toggle-switch`. Ensure your Python environment is correctly activated. If you previously installed `streamlit-toggle` (a different package), uninstall it and install `streamlit-toggle-switch`.","cause":"Despite installing `streamlit-toggle-switch`, the import for `streamlit_toggle` fails because the underlying package might not be correctly installed or recognized, or a different package name was used during installation.","error":"ModuleNotFoundError: No module named 'streamlit_toggle'"}]}