Registry / web-framework / streamlit-javascript

streamlit-javascript

JSON →
library0.1.5pypiunverified

Streamlit-javascript is a third-party Streamlit component (current version 0.1.5) that enables Python applications to execute arbitrary JavaScript code on the client-side browser and retrieve the results back into the Streamlit script. This facilitates advanced frontend interactions and data retrieval not natively supported by Streamlit, such as accessing browser-specific properties or making client-side API calls. The library's release cadence appears to be slow, with the latest PyPI version from May 2022.

web-framework
Install & Compatibility
Where this runs
tested against v0.1.5 · 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.103.910 runs
installs and imports cleanly · install 0.0s · import 1.743s · 447.1MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 15.8s · import 0.980s · 416MB
435MB installed
● package 435MB
Code
Verified usage

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

The primary function `st_javascript` needs to be imported directly, not the entire module.

from streamlit_javascript import st_javascript

This quickstart demonstrates how to use `st_javascript` to execute both asynchronous JavaScript (e.g., an `fetch` API call) and synchronous JavaScript (e.g., retrieving `window.innerWidth`). The `st_javascript` function returns the result of the JavaScript execution, which can be `None` on initial page load or before the JavaScript completes.

import streamlit as st from streamlit_javascript import st_javascript st.subheader("Javascript API Call Example") # Example 1: Making an asynchronous fetch request in JavaScript # The result is returned to Python once the JS promise resolves. return_value = st_javascript(""" await fetch("https://reqres.in/api/products/3") .then(function(response) { return response.json(); }) """) if return_value: st.markdown(f"Return value was: `{return_value}`") st.write("Parsed JSON:", return_value) # Streamlit-javascript attempts to parse JSON strings into Python objects else: st.info("Waiting for JavaScript fetch to complete...") st.subheader("Get Browser Window Width Example") # Example 2: Getting a simple browser property (synchronous) window_width = st_javascript("window.innerWidth") if window_width: st.write(f"Current browser window width: {window_width}px") else: st.info("Waiting for JavaScript to return window width...")
Debug
Known footguns
gotchaJavaScript functions executed via `st_javascript` might sometimes return '0' or an unexpected value if `window.parent.postMessage()` is not used explicitly for custom component communication, or if the JS execution context doesn't properly return a value that `st_javascript` can capture.
gotchaThe return value from `st_javascript` is typically a string representation of the JavaScript result. If you expect a numerical or boolean type, explicit type conversion in Python is necessary.
gotchaSome reports indicate that JavaScript code passed to `st_javascript` might be sensitive to whitespace or line breaks, potentially requiring the code to start on the very first line within the triple-quoted string.
gotchaStreamlit re-runs the entire script on every user interaction. JavaScript code executed via `st_javascript` will also re-run, which can lead to performance issues or unexpected side effects if not managed carefully (e.g., with Streamlit's caching or session state).
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
10 hits · last 30 days
gptbot
4
ahrefsbot
4
script
1
bingbot
1
Resources

No resource links recorded.