Registry / web-framework / streamlit-js-eval

streamlit-js-eval

JSON →
library1.0.0pypypi✓ verified 91d ago

streamlit-js-eval is a custom Streamlit component that enables developers to execute arbitrary JavaScript expressions directly within a Streamlit application. It facilitates interactions with the browser DOM, local storage, window properties, and more, returning results back to Python. The current version is 1.0.0, and it follows an infrequent release cadence, with stability being a primary focus.

pip install streamlit-js-eval
INSTALL
IMPORT
SIG · STREAMLIT-JS-EVAL
S
streamlit-js-eval
web-frameworkpythonv1.0.0
Install
15.5s avg
Import
1364ms
Disk
433MB
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.0 · 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.751s · 444.8MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 15.5s · import 0.977s · 414MB
433MB installed
● package 433MB
Code
Verified usage

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

streamlit_js_eval
✓ from streamlit_js_eval import streamlit_js_eval

This quickstart demonstrates how to use `streamlit_js_eval` to interact with browser-side JavaScript, including retrieving the current URL, setting and getting local storage values, getting screen dimensions, and performing a page redirect. Each `streamlit_js_eval` call requires a unique `key`.

import streamlit as st from streamlit_js_eval import streamlit_js_eval st.set_page_config(layout="wide") st.title("Streamlit JS Eval Demo") st.header("1. Get Browser URL") current_url = streamlit_js_eval(js_expressions="window.location.href", key="get_url") st.write(f"**Current URL:** `{current_url}`") st.header("2. Set Local Storage Value") if st.button("Set 'myKey' to 'myValue' in Local Storage"): streamlit_js_eval(js_expressions="localStorage.setItem('myKey', 'myValue');", key="set_ls_value", want_result=False) st.success("Value set! Refresh the page to see it in browser dev tools.") st.header("3. Get Local Storage Value") local_storage_val = streamlit_js_eval(js_expressions="localStorage.getItem('myKey');", key="get_ls_value") st.write(f"**Local Storage 'myKey':** `{local_storage_val}`") st.header("4. Get Screen Width") screen_width = streamlit_js_eval(js_expressions="screen.width", key="get_screen_width") st.write(f"**Screen Width:** `{screen_width}px`") st.header("5. Redirect Page (example)") if st.button("Go to Streamlit.io"): streamlit_js_eval(js_expressions="window.location.href='https://streamlit.io';", key="redirect_streamlit", want_result=False)
Debug
Known issues
gotchaJavaScript expressions are evaluated client-side on each Streamlit rerun. Results are cached and only updated if the `js_expressions` or `key` changes, or if `streamlit_js_eval` is explicitly rerun. Be mindful of when and how results are updated in a reactive Streamlit application.
fix
Ensure a unique `key` is used for each distinct evaluation call. If results aren't updating as expected, consider triggering a Streamlit rerun or ensuring the JS expression itself produces a new value. For fire-and-forget actions that don't require a return value, set `want_result=False`.
affects: All versions
gotchaEvaluating arbitrary JavaScript from user input or untrusted sources can lead to Cross-Site Scripting (XSS) vulnerabilities. Treat all `js_expressions` inputs as potentially malicious.
fix
Sanitize or strictly validate any `js_expressions` derived from user input. Limit the scope of executable JavaScript to only what is absolutely necessary and safe.
affects: All versions
gotchaLike all Streamlit components, `streamlit_js_eval` requires a unique `key` parameter for each instance to maintain state across reruns. Failing to provide a unique key can lead to unexpected behavior or `StreamlitAPIException` errors.
fix
Always provide a unique `key` string (e.g., `key="my_unique_eval_1"`) to every `streamlit_js_eval` call in your application.
affects: All versions
Errors
Common errors & fixes
ImportError: cannot import name 'streamlit_js_eval' from 'streamlit_js_eval'
The `streamlit-js-eval` package is either not installed, or there's a typo in the import statement.
fix
Ensure the library is installed by running `pip install streamlit-js-eval`. Verify your import statement is `from streamlit_js_eval import streamlit_js_eval`.
JavaScript expression results in None or doesn't update as expected.
The component might not have executed the JavaScript, or Streamlit did not capture its return value, often due to a missing/duplicate `key`, or `want_result` being `False`.
fix
Ensure each `streamlit_js_eval` call has a unique `key`. If you expect a result, make sure `want_result` is not set to `False`. For fire-and-forget operations, setting `want_result=False` is efficient. If you need re-evaluation on every run, consider using a dynamic `key` or updating `js_expressions` to force a change.
streamlit.errors.StreamlitAPIException: Every Streamlit component must have a unique key. If you are seeing this error, it means that you have streamlit_js_eval defined multiple times with the same key.
Multiple `streamlit_js_eval` calls in the same Streamlit app instance share the same `key` value, which is not allowed by Streamlit's component API.
fix
Assign a unique `key` string to every instance of `streamlit_js_eval` in your application (e.g., `key='eval_id_1'`, `key='eval_id_2'`).
Install Issues
1 verified issue
MarshallComponentException: argument needs a labelAll platforms · Streamlit 1.x →
Upgrade
Version history
1.0.0latest on PyPI · released Jan 9, 2026
Audit
Dependencies
streamlitrequiredThis library is a custom Streamlit component and requires Streamlit to function.
Agent activity
21 hits · last 30 days
node
19
Resources
streamlit-js-eval — pip install streamlit-js-eval · libregistry