Skip to main content

LLM-aware UI focus context for Streamlit — askable Python binding

Project description

askable-streamlit

Streamlit binding for askable — give your Streamlit app LLM awareness.

Install

pip install askable-streamlit

Quick start

import streamlit as st
from askable.streamlit import askable_context

st.title("AI Dashboard")

# Render data with data-askable annotations
st.markdown(
    """
    <div data-askable='{"metric":"revenue","period":"Q3","value":"$2.3M"}'>
        <h3>Q3 Revenue: $2.3M</h3>
        <p>Down 12% month-over-month</p>
    </div>
    """,
    unsafe_allow_html=True,
)

# Get the current focus context
focus = askable_context()

if focus:
    st.caption(f"Context: {focus['text'][:80]}...")

    if st.button("Ask AI about this"):
        prompt_context = (
            f"User is focused on: {focus['text']} "
            f"(metadata: {focus['meta']})"
        )
        # Pass prompt_context as your LLM system message
        response = call_your_llm(
            system=f"UI context: {prompt_context}",
            user="What should I know about this?",
        )
        st.write(response)

How it works

askable_context() renders a hidden zero-height iframe component that:

  1. Injects @askable/core into the parent Streamlit page via same-origin iframe access
  2. Observes all [data-askable] elements on document.body
  3. When the user clicks, focuses, or hovers an annotated element, sends the focus data back to Python as the component value

The returned dict has the same shape as AskableFocus from the JS core:

{
    "meta": {"metric": "revenue", "period": "Q3"},  # parsed from data-askable
    "text": "Q3 Revenue: $2.3M",                     # element text (≤200 chars)
    "timestamp": 1711234567890,                       # unix ms
}

Requirements

  • Python ≥ 3.9
  • Streamlit ≥ 1.28.0
  • Works with all standard Streamlit deployment targets (local, Streamlit Cloud, etc.)

Note: The component injects JS into the parent page via same-origin iframe access. This works in all standard Streamlit deployments because custom component frontends are served from the same origin as the app.

License

MIT

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

askable_streamlit-0.1.2.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

askable_streamlit-0.1.2-py3-none-any.whl (2.4 kB view details)

Uploaded Python 3

File details

Details for the file askable_streamlit-0.1.2.tar.gz.

File metadata

  • Download URL: askable_streamlit-0.1.2.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for askable_streamlit-0.1.2.tar.gz
Algorithm Hash digest
SHA256 475159b0613f0854189da592c5c4285756bd5e5ff3afdf67f8fd255440ad4d13
MD5 e673e268a252e6d861866982435e28d5
BLAKE2b-256 f786b73380495fa9725a995ea2e8abf8711a8e0d44475bb62d3399b5a8c46668

See more details on using hashes here.

Provenance

The following attestation bundles were made for askable_streamlit-0.1.2.tar.gz:

Publisher: publish-python.yml on askable-ui/askable

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file askable_streamlit-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for askable_streamlit-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ac0f7fd33a92382f95b8757006399af62681b9d1eb8636ef4b68dcc7e48ddf29
MD5 7b5cf8e1d01f6e86e954468e4c6e3cfb
BLAKE2b-256 86b373f4f24348b46b21549182341f7d00737d3e42064e32b0918cc4578cc294

See more details on using hashes here.

Provenance

The following attestation bundles were made for askable_streamlit-0.1.2-py3-none-any.whl:

Publisher: publish-python.yml on askable-ui/askable

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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