🚧 Work in Progress 🚧
streamlit-terminal is a project designed to embed a terminal within a Streamlit web application. This allows users to execute shell commands directly within a web interface, providing an easy way to interact with a system’s command-line tools from a browser.
- ✅ Interactive Terminal: Embed an interactive terminal in a Streamlit app to execute shell commands.
- ✅ Custom Command Execution: Supports running custom commands by initializing the terminal with a command.
- ✅ Real-Time Output: Displays real-time command outputs (
stdout,stderr), and tracks command execution history. - ✅ Command History: Keeps track of previously run commands and their outputs for easy access and debugging.
- ✅ Process Management: Users can start and terminate processes directly from the terminal.
- 🚧 Shell Support: Currently, each command runs in a separate process. A future update will allow the creation of a dedicated shell process for each terminal session, enabling commands to run within the same environment (e.g., maintaining session states like environment variables and current directories).
- 🚧 Preferred Shell Selection: Users will be able to select their preferred shell from options such as
cmd,pwsh,powershell,msys(Windows),bash(Linux), and others. - 🚧 Support for
stdin: While the terminal currently supportsstdoutandstderr, future updates will add support forstdinfor full command interactivity. - 🚧 Attach to Running Processes: Users will be able to attach to existing running processes, allowing them to monitor and interact with those processes through the embedded terminal.
-
Clone the repository: Download the
streamlit-terminalrepository to your local machine.git clone https://github.com/akipg/streamlit-terminal.git
-
Navigate to the project directory: Change into the project’s main directory.
cd streamlit-terminal -
Install the required dependencies: Install Streamlit to run the application.
pip install streamlit
-
Modify the
__init__.pyfile: Set_RELEASE = Falseinstreamlit_terminal/__init__.pyfor development mode._RELEASE = False
-
Run the application: Start the Streamlit app.
streamlit run app.py
To set up the development environment for the frontend:
-
Navigate to the frontend directory: Move into the frontend Vue.js project directory.
cd streamlit_terminal/frontend-vue -
Install dependencies: Install all required Node.js dependencies using
pnpm.pnpm i
-
Start the development server: Run the frontend development server with hot-reload enabled.
pnpm run dev
You can embed a basic terminal in the app as follows:
from streamlit_terminal import st_terminal
st_terminal(key="terminal1")In this example, the terminal will load with the command echo 'Hello, World!' pre-filled. The user can click the Run button to execute it.
from streamlit_terminal import st_terminal
st_terminal(key="terminal2", command="echo 'Hello, World!'")You can also set up multiple terminals, each with different commands and configurations:
import streamlit as st
from streamlit_terminal import st_terminal
# Set wide mode
st.set_page_config(layout="wide")
st.markdown("# Streamlit Terminal")
# Example 1: Basic Usage
st.markdown("## Example 1: Basic Usage")
st_terminal(key="terminal1")
# Example 2: Custom Command
st.markdown("## Example 2: Custom Command")
st_terminal(key="terminal2", command="echo 'Hello World'")
# Example 3: Custom Command with adjustable height
st.markdown("## Example 3: Custom Command with height")
st_terminal(key="terminal3", command="python -u test/clock.py", height=600)