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.
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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 1.743s · 447.1MB
glibcpy 3.10–3.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...")
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.
Resources
No resource links recorded.