Registry / web-framework / streamlit-toggle-switch

streamlit-toggle-switch

JSON →
library1.0.2pypypi✓ verified 91d ago

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.

pip install streamlit-toggle-switch
INSTALL
IMPORT
SIG · STREAMLIT-TOGGLE-S
S
streamlit-toggle-switch
web-frameworkpythonv1.0.2
Install
15.6s avg
Import
1368ms
Disk
436MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.0.2 · 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.10–3.920 runs
installs and imports cleanly · install 0.0s · import 1.747s · 447.6MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 15.6s · import 0.990s · 417MB
436MB installed
● package 436MB
Code
Verified usage

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

st_toggle_switch
✓ from streamlit_toggle import st_toggle_switch
✗ from streamlit_toggle_switch import st_toggle_switch
The installed package `streamlit-toggle-switch` is imported as `streamlit_toggle`.
st.toggle
✓ import streamlit as st on = st.toggle('Activate feature')
Native Streamlit widget, preferred over this custom component.

This quickstart demonstrates how to use the `streamlit-toggle-switch` component and also includes the recommended native `st.toggle` widget for comparison.

import streamlit as st from streamlit_toggle import st_toggle_switch st.title('Custom Toggle Switch Demo') # Example using the custom component is_enabled = st_toggle_switch( label='Enable Feature X', key='feature_x_toggle', default_value=False, label_after=True, inactive_color='#D3D3D3', # Optional active_color='#11567f', # Optional track_color='#29B5E8' # Optional ) if is_enabled: st.write('Feature X is enabled!') else: st.write('Feature X is disabled.') st.subheader('Native Streamlit Toggle (Recommended)') native_toggle_on = st.toggle('Activate native feature') if native_toggle_on: st.write('Native feature activated!')
Debug
Known issues
breakingThis 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.
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.
affects: All versions
gotchaThe 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.
fix
Always use `import streamlit_toggle as tog` (or similar alias) after `pip install streamlit-toggle-switch`.
affects: All versions
gotchaThe `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.
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.
affects: All versions
Errors
Common errors & fixes
AttributeError: module 'streamlit_toggle' has no attribute 'st_toggle_switch'
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.
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.
ModuleNotFoundError: No module named 'streamlit_toggle'
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.
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`.
Upgrade
Version history
1.0.2latest on PyPI · released Oct 25, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
16
Resources
streamlit-toggle-switch — pip install streamlit-toggle-switch · libregistry