Skip to main content

Streamlit keyboard shortcuts for your buttons.

Project description

Streamlit Shortcuts

Streamlit Shortcuts allows you to easily add keyboard shortcuts to your Streamlit buttons.

Installation

pip install streamlit-shortcuts

Example

import streamlit as st
import streamlit_shortcuts

def delete_callback():
    st.write("DELETED!")

streamlit_shortcuts.button("delete", on_click=delete_callback, shortcut="Ctrl+Shift+X")

⭐ NEW in v0.1.5: Support for args and kwargs

import streamlit as st
import streamlit_shortcuts

def delete_callback(item_id, user="anonymous"):
    st.write(f"Item {item_id} DELETED by {user}!")

streamlit_shortcuts.button(
    "Delete",
    shortcut="Ctrl+Shift+X",
    on_click=delete_callback,
    args=(42,),
    kwargs={"user": "admin"},
    type="primary"
)

This creates a primary Streamlit button labeled "Delete" with the shortcut "Ctrl+Shift+X". When clicked (or activated via shortcut), it calls delete_callback(42, user="admin").

🥱 Old

import streamlit as st
from streamlit_shortcuts import add_keyboard_shortcuts

def delete_callback():
    st.write("DELETED!")

st.button("delete", on_click=delete_callback)

add_keyboard_shortcuts({
    'Ctrl+Shift+X': 'delete',
})

The 'Ctrl+Shift+X' combination will trigger "Another Button".

Keys

  • Modifiers: 'Ctrl', 'Shift', 'Alt', 'Meta' ('Cmd' on Mac or 'Win' on Windows, thanks to @toolittlecakes)
  • Common Keys: 'Enter', 'Escape', 'Space'
  • Arrow Keys: 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'

Examples of Key Combinations:

  • 'Ctrl+Enter'
  • 'Shift+ArrowUp'
  • 'Alt+Space'

For a complete list of key values, refer to: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values

Versioning

We use semantic versioning. The current version is stored in the VERSION file in the root of the repository.

Contributing

Contributions are welcome! If you have suggestions for improvements or bug fixes, please follow these steps:

  1. Fork the repository
  2. Create a new branch for your feature or bugfix
  3. Make your changes
  4. Add or update tests as necessary
  5. Update the VERSION file if your changes warrant a version bump
  6. Submit a pull request

Please make sure to update tests as appropriate and adhere to the existing coding style.

Releasing New Versions

To release a new version:

  1. Update the VERSION file with the new version number
  2. Commit the change: git commit -am "Bump version to X.Y.Z"
  3. Create a new tag: git tag vX.Y.Z
  4. Push the changes and the tag: git push && git push --tags

The GitHub Actions workflow will automatically create a new release and publish to PyPI.

Contributors

  • @toolittlecakes - Added 'Meta' modifier
  • @quantum-ernest - Improved usage ergonomics
  • @taylor-ennen - Fixed usage flow of code

Credits

Solution inspired by:

Special thanks to @brunomsantiago and @TomJohnH for their initial work on this concept.

Wrapped and extended for easier usage by the Streamlit Shortcuts team.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_shortcuts-0.1.5.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

streamlit_shortcuts-0.1.5-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_shortcuts-0.1.5.tar.gz.

File metadata

  • Download URL: streamlit_shortcuts-0.1.5.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for streamlit_shortcuts-0.1.5.tar.gz
Algorithm Hash digest
SHA256 8a69983e9e3f1868756eba32cc570c59f1a619c2bc9956832c3eaea96e7af27a
MD5 1a2a6b1ceb2d71019908a1297141562d
BLAKE2b-256 adf348798abaa6e8567a881766bdb8f3608b4139aa3fb74b77f39f453a0468ba

See more details on using hashes here.

File details

Details for the file streamlit_shortcuts-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_shortcuts-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3b4f97a75eab4b680a9aa9441f3271bfb7367c158c71efa8b6a3c22987a451c7
MD5 9e545b90d07c88f7c571140555aec013
BLAKE2b-256 3bb577bafd02dfd249614140950b0d278241173942790516e452e513aa9e6b55

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page