Streamlit Shortcuts
Add keyboard shortcuts to your Streamlit buttons! 🚀
🎯 Mirrors the native st.button pattern
# Before using native st.button:
if st.button("Save", type="primary", use_container_width=True):
save()
# After (just change function name & add shortcut):
if shortcut_button("Save", "ctrl+s", type="primary", use_container_width=True):
save()
# Multiple shortcuts for one button
if shortcut_button("Previous", ["arrowleft", "h"]):
go_previous()
🎨 Add shortcuts to ANY Streamlit widget
name = st.text_input("Name", key="name_input")
# Add shortcuts to any widget with a key
add_shortcuts(
name_input="ctrl+n", # Focus name field
)
Check out the live demo or view the example code
📦 Installation
pip install streamlit-shortcuts
📖 API Reference
shortcut_button(label, shortcut, **kwargs)
Drop-in replacement for st.button with keyboard shortcut support.
Parameters:
label(str): Button textshortcut(str | list[str]): Single shortcut or list of shortcuts (e.g., "ctrl+s", ["ctrl+s", "cmd+s"])key(str, optional): Unique key for the buttonhint(bool, optional): Show shortcut hint in button label (default: True)**kwargs: All other st.button parameters (help, on_click, args, type, icon, disabled, use_container_width)
Returns: bool - True if clicked
add_shortcuts(**shortcuts)
Add keyboard shortcuts to any Streamlit widgets.
Parameters:
**shortcuts: Keyword arguments where key is the widget's key and value is the shortcut (str | list[str])
Example:
add_shortcuts(
save_btn="ctrl+s",
search_input="ctrl+f",
submit_form="ctrl+enter"
)
# Multiple shortcuts per widget
add_shortcuts(
prev_btn=["arrowleft", "a"],
next_btn=["arrowright", "d"]
)
clear_shortcuts() (New in v1.1)
Remove all keyboard shortcuts and event listeners. Useful for:
- Multi-page apps when switching pages
- Conditionally disabling all shortcuts
- Cleaning up shortcuts in dynamic UIs
Example:
# Disable shortcuts conditionally
if not shortcuts_enabled:
clear_shortcuts()
# Clean up when switching pages
if st.sidebar.button("Go to Settings"):
clear_shortcuts()
st.switch_page("settings")
⌨️ Keyboard Shortcuts
- Modifiers:
ctrl,alt,shift,meta(cmd on Mac) - Common keys:
enter,escape,space,tab,delete - Letters:
a-z - Numbers:
0-9 - Function keys:
f1-f12 - Arrow keys:
arrowleft,arrowright,arrowup,arrowdown
Examples:
ctrl+s- Ctrl + Sctrl+shift+d- Ctrl + Shift + Dalt+enter- Alt + Enterf1- F1 key
💻 Platform Notes
- On macOS,
ctrlworks as expected (not cmd) - For OS-specific shortcuts, use
meta(Windows key on PC, Cmd on Mac) - Some shortcuts may conflict with browser/OS shortcuts
⚠️ Known Issues
Column Alignment
When using shortcut_button inside columns with vertical_alignment, the button may not align properly. This happens because the shortcut injection creates an invisible element that affects layout.
Workaround: Use st.button with add_shortcuts separately:
# ❌ Broken alignment
col1, col2 = st.columns([1, 1], vertical_alignment="bottom")
with col1:
shortcut_button("Save", "ctrl+s")
with col2:
st.selectbox("Options", ["A", "B", "C"])
# ✅ Correct alignment
col1, col2 = st.columns([1, 1], vertical_alignment="bottom")
with col1:
st.button("Save", key="save_btn")
with col2:
st.selectbox("Options", ["A", "B", "C"])
# Add shortcuts after columns
add_shortcuts(save_btn="ctrl+s")
🚨 v1.0 Breaking Changes - complete rewrite
- ⭐ No more API hijacking - v0.x monkey-patched Streamlit's API. Now we respect it:
# v0.x - Hijacked the API, confusing and unpythonic button("Save", "ctrl+s", lambda: save()) # What is this? Not st.button! # v1.0 - Respects Streamlit patterns, works like st.button if shortcut_button("Save", "ctrl+s"): # Familiar pattern! save() # Or use native st.button unchanged if st.button("Save", key="save_btn"): save() add_shortcuts(save_btn="ctrl+s")
- 📉 From 277 lines → 91 lines total (across 5 Python files → 1 file)
- 🗑️ Removed 15 files of configuration bloat
- 📁 No more src/ directory - just one flat file
- ❌ Deleted all tests - meaningless tests that tested nothing, replaced with assertions that actually fail
- 🔥 Modern Python tooling - replaced setup.py/MANIFEST/VERSION with pyproject.toml + uv
- 🧹 Ruff instead of 5 linters - removed flake8, black, isort, mypy, pre-commit hooks
- ⚡ 3 workflows → 1 workflow - simple CI/CD
If upgrading from v0.x:
# Old v0.x API
button("Click me", "ctrl+k", lambda: st.write("Hi"))
# New v1.0 API
if shortcut_button("Click me", "ctrl+k"):
st.write("Hi")
# Or use st.button + add_shortcuts
if st.button("Click me", key="btn"):
st.write("Hi")
add_shortcuts(btn="ctrl+k")
🙏 Credits
Built by the Streamlit community! 🎈
Special thanks to:
- @brunomsantiago and @TomJohnH for the initial concept
- @toolittlecakes for Meta key support
- @quantum-ernest for keyboard hints
- @sammlapp for making shortcuts work with any widget
- @jcbize for improved error handling
- @csipapicsa for identifying a XSS vulnerability
Inspired by Streamlit discussion #1291
Metadata
Release files for streamlit-shortcuts 1.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| streamlit_shortcuts-1.2.2.tar.gz | 112.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| streamlit_shortcuts-1.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 119.7 kB
Release files / streamlit_shortcuts-1.2.2.tar.gz
| Download URL | streamlit_shortcuts-1.2.2.tar.gz |
|---|---|
| Size | 112.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f195f3c1577f26081c265633a02f5fa9784f2d7b1dd94c2ba4b3559cef68bd1
|
|
BLAKE2b-256 checksum How to use checksums |
7332e1c7440408fa9ec39b4970276aa549744ed358ffec561c26374ac7024085
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logRelease files / streamlit_shortcuts-1.2.2-py3-none-any.whl
| Download URL | streamlit_shortcuts-1.2.2-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7b8668432bc39478b2e4ca68d21acfd7c853966951251c21f177eb2bece3c3b4
|
|
BLAKE2b-256 checksum How to use checksums |
ff0fda939071eb3a653f362040a85cfd0d1d2b99e37f1768009d08c27a735d2e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency log