======================== CODE SNIPPETS ======================== TITLE: Test Streamlit Installation with Hello App DESCRIPTION: These commands launch Streamlit's built-in 'Hello' example application to verify a successful installation. A fallback command is provided if the direct `streamlit` command is not immediately available. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_5 LANGUAGE: bash CODE: ``` streamlit hello ``` LANGUAGE: bash CODE: ``` python -m streamlit hello ``` ---------------------------------------- TITLE: Run Streamlit Hello App with Default Settings DESCRIPTION: This command verifies Streamlit installation by running an included example application. It starts the 'Hello' app and opens it in the default web browser. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_734 LANGUAGE: bash CODE: ``` streamlit hello ``` ---------------------------------------- TITLE: Streamlit CLI: Configuration Options Examples DESCRIPTION: Examples demonstrating how to pass configuration options to Streamlit CLI commands, such as `streamlit hello`, to customize app behavior or appearance. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_733 LANGUAGE: Bash CODE: ``` --theme.primaryColor=blue ``` LANGUAGE: Bash CODE: ``` --theme.primaryColor="blue" ``` LANGUAGE: Bash CODE: ``` --theme.primaryColor=#0000FF ``` ---------------------------------------- TITLE: Run Streamlit Component Example Application DESCRIPTION: Commands to activate the Python environment, install the component template as an editable package, and run the Streamlit example application for both React and TypeScript-only templates. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_168 LANGUAGE: bash CODE: ``` # React template cd template . venv/bin/activate # or similar to activate the venv/conda environment where Streamlit is installed pip install -e . # install template as editable package streamlit run my_component/example.py # run the example # or # TypeScript-only template cd template-reactless . venv/bin/activate # or similar to activate the venv/conda environment where Streamlit is installed pip install -e . # install template as editable package streamlit run my_component/example.py # run the example ``` ---------------------------------------- TITLE: Install pytest for Streamlit Testing DESCRIPTION: Installs the pytest framework, a common Python testing tool, into your Streamlit development environment. This is a prerequisite for running the Streamlit app testing examples. SOURCE: https://github.com/streamlit/docs/blob/main/content/develop/concepts/app-testing/get-started.md#_snippet_0 LANGUAGE: bash CODE: ``` pip install pytest ``` ---------------------------------------- TITLE: Streamlit: Installation and Basic Usage DESCRIPTION: This snippet provides commands for installing Streamlit, running a Streamlit application from the command line, and the standard Python import convention for Streamlit. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_866 LANGUAGE: bash CODE: ``` pip install streamlit streamlit run first_app.py ``` LANGUAGE: python CODE: ``` # Import convention >>> import streamlit as st ``` ---------------------------------------- TITLE: Dockerfile for Streamlit Application DESCRIPTION: This Dockerfile defines the steps to build a Docker image for a Streamlit application. It starts from a Python 3.9 slim image, sets the working directory, installs necessary build tools, clones a Streamlit example repository, installs Python dependencies, exposes port 8501, includes a health check, and sets the entrypoint to run the Streamlit application. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_1077 LANGUAGE: docker CODE: ``` # app/Dockerfile FROM python:3.9-slim WORKDIR /app RUN apt-get update apt-get install -y \ build-essential \ curl \ software-properties-common \ git \ rm -rf /var/lib/apt/lists/* RUN git clone https://github.com/streamlit/streamlit-example.git . RUN pip3 install -r requirements.txt EXPOSE 8501 HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health ENTRYPOINT ["streamlit", "run", "streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"] ``` ---------------------------------------- TITLE: GitHub Actions Test Environment Setup DESCRIPTION: YAML snippet detailing the setup steps for a GitHub Actions job, including checking out the repository code and installing a specific Python version (3.11) on an Ubuntu environment. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_238 LANGUAGE: yaml CODE: ``` jobs: streamlit: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: "3.11" ``` ---------------------------------------- TITLE: Install and Validate Streamlit via Command Line DESCRIPTION: This snippet provides the essential command-line steps for installing Streamlit using pip and then validating the installation by running the built-in 'Hello' application. It's part of the recommended setup for local development and assumes a Python environment is already configured. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_0 LANGUAGE: Bash CODE: ``` pip install streamlit ``` LANGUAGE: Bash CODE: ``` streamlit hello ``` ---------------------------------------- TITLE: Run Streamlit Hello App DESCRIPTION: Executes the Streamlit "Hello" example application to validate the installation. This command starts a local web server and opens the app in your browser. SOURCE: https://github.com/streamlit/docs/blob/main/content/get-started/installation/anaconda-distribution.md#_snippet_1 LANGUAGE: bash CODE: ``` streamlit hello ``` ---------------------------------------- TITLE: Streamlit CLI: Run Hello App DESCRIPTION: The `streamlit hello` command runs an example Streamlit application that is included with the Streamlit library, demonstrating basic functionalities. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_732 LANGUAGE: Bash CODE: ``` streamlit hello ``` ---------------------------------------- TITLE: Install Streamlit Nightly Release DESCRIPTION: Instructions on how to switch from the official Streamlit package to the nightly release. This involves uninstalling the stable `streamlit` package and then installing the `streamlit-nightly` package with an upgrade. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_1059 LANGUAGE: bash CODE: ``` pip uninstall streamlit pip install streamlit-nightly --upgrade ``` ---------------------------------------- TITLE: Define Dockerfile for Streamlit Application DESCRIPTION: A Dockerfile that defines the steps to build a Docker image for the Streamlit application. It sets up a Python environment, installs necessary dependencies, clones the Streamlit example app, and configures the entrypoint. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_1097 LANGUAGE: docker CODE: ``` FROM python:3.9-slim RUN groupadd --gid 1000 appuser \ && useradd --uid 1000 --gid 1000 -ms /bin/bash appuser RUN pip3 install --no-cache-dir --upgrade \ pip \ virtualenv RUN apt-get update && apt-get install -y \ build-essential \ software-properties-common \ git USER appuser WORKDIR /home/appuser RUN git clone https://github.com/streamlit/streamlit-example.git app ENV VIRTUAL_ENV=/home/appuser/venv RUN virtualenv ${VIRTUAL_ENV} RUN . ${VIRTUAL_ENV}/bin/activate && pip install -r app/requirements.txt EXPOSE 8501 COPY run.sh /home/appuser ENTRYPOINT ["./run.sh"] ``` ---------------------------------------- TITLE: Example Python Dependencies (requirements.txt) DESCRIPTION: Shows typical Python dependencies listed in a `requirements.txt` file. These packages are installed by pip to ensure the Streamlit application has all necessary libraries to run correctly. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_1083 LANGUAGE: text CODE: ``` altair pandas streamlit ``` ---------------------------------------- TITLE: Run Streamlit App from Working Directory DESCRIPTION: This example shows the basic command to start a Streamlit application when its entrypoint file is located in the current working directory. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_741 LANGUAGE: bash CODE: ``` streamlit run your_app.py ``` ---------------------------------------- TITLE: Example config.toml file for Streamlit settings DESCRIPTION: Provides an example of a `config.toml` file, demonstrating how to define client and theme settings. This file uses TOML syntax for key-value pairs to customize Streamlit's appearance and behavior. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_687 LANGUAGE: toml CODE: ``` [client] showErrorDetails = "none" [theme] primaryColor = "#F63366" backgroundColor = "black" ``` ---------------------------------------- TITLE: Streamlit App Testing Example DESCRIPTION: A Python test function demonstrating how to initialize, run, and interact with a Streamlit app using AppTest. It simulates user input and asserts the resulting output. SOURCE: https://github.com/streamlit/docs/blob/main/content/develop/concepts/app-testing/get-started.md#_snippet_10 LANGUAGE: python CODE: ``` """test_app.py""" from streamlit.testing.v1 import AppTest def test_increment_and_add(): """A user increments the number input, then clicks Add""" at = AppTest.from_file("app.py").run() at.number_input[0].increment().run() at.button[0].click().run() assert at.markdown[0].value == "Beans counted: 1" ``` ---------------------------------------- TITLE: Verify Docker Engine Installation DESCRIPTION: Command to run the `hello-world` Docker image to confirm Docker Engine is correctly installed on your server. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_1095 LANGUAGE: bash CODE: ``` sudo docker run hello-world ``` ---------------------------------------- TITLE: Example Project Directory Structure for Pytest DESCRIPTION: Illustrates the recommended directory structure for a Streamlit application with a dedicated `tests/` directory for `pytest` test files. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_211 LANGUAGE: none CODE: ``` myproject/ ├── app.py └── tests/ └── test_app.py ``` ---------------------------------------- TITLE: Streamlit: Install Pre-release Features DESCRIPTION: This snippet shows how to uninstall the stable Streamlit version and install the `streamlit-nightly` package to access pre-release and experimental features. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_867 LANGUAGE: bash CODE: ``` pip uninstall streamlit pip install streamlit-nightly --upgrade ``` ---------------------------------------- TITLE: Example Project Structure for Streamlit Login Page Testing DESCRIPTION: This snippet outlines the recommended directory structure for a Streamlit application that includes a login page and its corresponding test files. It demonstrates a clear separation between the main application code and its tests. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_242 LANGUAGE: none CODE: ``` myproject/ ├── app.py └── tests/ └── test_app.py ``` ---------------------------------------- TITLE: Creating and Populating a MySQL Database Table DESCRIPTION: This SQL script creates a new database named 'pets', selects it, defines a table 'mytable' with 'name' and 'pet' columns, and inserts three example rows. This setup is necessary before connecting a Streamlit application to the MySQL database. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_811 LANGUAGE: SQL CODE: ``` CREATE DATABASE pets; USE pets; CREATE TABLE mytable ( name varchar(80), pet varchar(80) ); INSERT INTO mytable VALUES ('Mary', 'dog'), ('John', 'cat'), ('Robert', 'bird'); ``` ---------------------------------------- TITLE: Create TiDB database and table DESCRIPTION: This SQL snippet creates a new database named 'pets' and a table 'mytable' within it, populating it with example data. It demonstrates the initial setup for a TiDB cluster. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_838 LANGUAGE: sql CODE: ``` CREATE DATABASE pets; USE pets; CREATE TABLE mytable ( name varchar(80), pet varchar(80) ); INSERT INTO mytable VALUES ('Mary', 'dog'), ('John', 'cat'), ('Robert', 'bird'); ``` ---------------------------------------- TITLE: Create PostgreSQL Table with Example Data DESCRIPTION: SQL commands to create a sample table named `mytable` and insert three rows of example data. This table is used for demonstration purposes in the Streamlit application. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_822 LANGUAGE: sql CODE: ``` CREATE TABLE mytable ( name varchar(80), pet varchar(80) ); INSERT INTO mytable VALUES ('Mary', 'dog'), ('John', 'cat'), ('Robert', 'bird'); ``` ---------------------------------------- TITLE: Verify Docker Engine Installation DESCRIPTION: This command runs the `hello-world` Docker image to confirm that Docker Engine is correctly installed and operational on your server. It's a standard first step to ensure your Docker environment is set up. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_1076 LANGUAGE: bash CODE: ``` sudo docker run hello-world ``` ---------------------------------------- TITLE: Streamlit Version Prerequisite DESCRIPTION: Specifies the minimum required Streamlit version for the tutorials and examples provided in this documentation. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_849 LANGUAGE: text CODE: ``` streamlit>=1.37.0 ``` ---------------------------------------- TITLE: Install Python Package from Test PyPI DESCRIPTION: This command shows how to install a Python package that has been uploaded to Test PyPI. It specifies the Test PyPI index URL and uses the `--no-deps` flag to avoid installing dependencies, allowing for a focused test of the newly uploaded package. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_186 LANGUAGE: bash CODE: ``` python -m pip install --index-url https://test.pypi.org/simple/ --no-deps example-pkg-YOUR-USERNAME-HERE ``` ---------------------------------------- TITLE: Install Streamlit via pip DESCRIPTION: This command installs the Streamlit library into your activated Python virtual environment using the `pip` package manager, making it available for your projects. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_4 LANGUAGE: bash CODE: ``` pip install streamlit ``` ---------------------------------------- TITLE: Create a Streamlit SQL Connection DESCRIPTION: Demonstrates how to create a connection to a SQL database using `st.connection` and query data. This example connects to a 'pets_db' and fetches pet owners. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_650 LANGUAGE: Python CODE: ``` conn = st.connection('pets_db', type='sql') pet_owners = conn.query('select * from pet_owners') st.dataframe(pet_owners) ``` ---------------------------------------- TITLE: Install Git and Build Essentials in Docker DESCRIPTION: Updates apt-get and installs necessary packages like `build-essential`, `curl`, `software-properties-common`, and `git`. These are often required for compiling software or cloning repositories within the Docker container. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_1080 LANGUAGE: docker CODE: ``` RUN apt-get update apt-get install -y \ build-essential \ curl \ software-properties-common \ git \ rm -rf /var/lib/apt/lists/* ``` ---------------------------------------- TITLE: Running Streamlit Hello for Installation Verification DESCRIPTION: Illustrates how to run the `streamlit hello` command to confirm a successful Streamlit installation. Executing this command launches the example application in your default web browser, providing visual confirmation. SOURCE: https://github.com/streamlit/docs/blob/main/content/develop/api-reference/command-line/hello.md#_snippet_1 LANGUAGE: bash CODE: ``` streamlit hello ``` ---------------------------------------- TITLE: Streamlit CLI Run Command API Reference DESCRIPTION: Provides the comprehensive API documentation for the `streamlit run` command, which starts a Streamlit app. It covers syntax, the `` argument, configuration options, and how script arguments are handled. SOURCE: https://github.com/streamlit/docs/blob/main/public/llms-full.txt#_snippet_740 LANGUAGE: APIDOC CODE: ``` streamlit run [-- config options] [script args] Arguments: : The path to your entrypoint file for your Streamlit app. In a multipage app with `st.navigation`, your entrypoint file acts as a router between your pages. Otherwise, your entrypoint file is your app's homepage. Options: Configuration options are passed in the form of `--
.