Skip to main content

[!WARNING] This is a work in progress. This package currently only supports python code execution. The goal is to support other languages as well.

streamlit-execute

A streamlit component package that allows you to execute code on the client (which keeps the user code execution a safer distance from the server/backend). Currently, only python code execution is supported. Pyodide (Webassembly) is used for python code execution. The goal is to support other languages as well.

Installation instructions

pip install streamlit-execute

Usage instructions

There are 3 functions you will likely need to call to execute python code. If you dont care about Interpreter-like features, you can just call init function and give it the code you want to execute.

import streamlit as st
from streamlit_execute import init

# Execute code
response = init("print('Hello World!')")
st.write(response)

If you want to execute more code in the same interpreter, you can use the run function. This will execute the code you give it in the same interpreter that was created by the init function.

import streamlit as st
import streamlit_execute as se

# Create an interpreter
response = se.init()

# Execute code
response_add = se.run("5 + 5")
st.write(response_add)

The run function creates another component that will pass code to the correct interpreter and receive the corresponding result. It will then pass the result back to Streamlit in the return value of the run function.

However, the above will not work without calling an additional function that sets up communication between the interpreter component and all of the run components. This is done by calling the connect function.

import streamlit as st
import streamlit_execute as se

# Create an interpreter
response = se.init()

# Connect all run calls to the interpreter
se.connect()

# Execute code
response_add = se.run("5 + 5")
st.write(response_add)

Note that run components are intended to be more lightweight than the init component. Using multiple components was a decision that was made because using only one component requires script reruns in order to pass new code to the interpreter. This requires more sophisticated logic to implement and is not as dev-friendly.

Multiple Interpreters

If you want to use multiple interpreters, you can do so by calling the init function multiple times. But this time, they must have different keys. This is necessary because the run function uses the key to determine which interpreter to pass the code to. If you don't provide a key, the default key is used for both the init and run functions.

import streamlit as st
import streamlit_execute as se

# Create two interpreters
response_init1 = se.init(key="interpreter1")
response_init2 = se.init(key="interpreter2")

# Connect all run calls to the interpreters
se.connect()

# Run code in the first interpreter
response_add1 = se.run("5 + 5", target_key="interpreter1")
st.write(response_add1)

# Run code in the second interpreter
response_add2 = se.run("a=2\na", target_key="interpreter2")
st.write(response_add2)

Metadata

Release files for streamlit-execute 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for streamlit-execute 0.1.0
File Size Uploaded Provenance Actions
streamlit-execute-0.1.0.tar.gz 5.9 MB Without provenance Details for streamlit-execute-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for streamlit-execute 0.1.0
File Interpreter ABI Platform Actions
streamlit_execute-0.1.0-py3-none-any.whl Python 3 none any Details for streamlit_execute-0.1.0-py3-none-any.whl

Total release size: 11.8 MB

Release files / streamlit-execute-0.1.0.tar.gz

Download URL streamlit-execute-0.1.0.tar.gz
Size 5.9 MB
Tags Source
SHA-256 checksum
How to use checksums
0ab54981e4a248b23cf1145dcbde93eb2c6535384d400b2cd4bf62c061d89ea0
BLAKE2b-256 checksum
How to use checksums
88181f60998d154a92d0c8b877e42f0d9f521bf80c2ec6037a4e691aede7b259
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.12

Release files / streamlit_execute-0.1.0-py3-none-any.whl

Download URL streamlit_execute-0.1.0-py3-none-any.whl
Size 5.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
a9e764202497e868d319e85e200152d0c3836e50d9d26264ee099b59268e5b79
BLAKE2b-256 checksum
How to use checksums
cdf1d47d501df1ddf012a7bebf5b2f992d1f2f278f417d299ce1c852c187c9dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.12

Security for streamlit-execute 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page