This template is made for Python 3.11 version.
👉 You can delete this file before committing your project to GitHub.
How to use this template project see the following steps:
- Clone the template project.
- Write your code in the
streamlit_app.py
file. - If necessary: Add additional python dependencies to the
requirements.txt
file. - If necessary: Add binary dependencies to the
packages.txt
file. Keep the line-endings in Linux (LF only) format. Uncomment the binary installation lines in the Dockerfile. - Build the Docker image locally (commands see below or in the Dockerfile).
- Run the Docker container locally (commands see below or in the Dockerfile) and debug your streamlit app locally until you are ready to deploy to Streamlit Cloud.
- Deploy the project to Streamlit Cloud and test it.
- Adjust the
Open in Streamlit
badge in this README.md file, that it points to the deployed project. - Adjust the README.md file and describe your streamlit project.
- Delete this "Usage" file before committing your project to GitHub.
If you don't want to use Docker for local development, you can also use a Python virtual environment. How to setup a Python virtual environment for local development:
pip install --upgrade virtualenv
python -m venv .venv
.venv\Scripts\activate
source .venv/bin/activate
python -m pip install --upgrade pip
pip install --upgrade -r requirements.txt
streamlit run streamlit-app.py
deactivate
This template contains a Dockerfile for local debugging and testing of the project, before deploying the project to Streamlit Cloud. This shall ease the process of developing and deploying projects to Streamlit Cloud, without endless back and forth trial-and-error between local development environment, GitHub and Streamlit Cloud.
The Dockerfile is based on python:3.11-slim
image and shall mimic the Streamlit Cloud runtime as closely as possible.
Hint: If you run the Dockerfile locally on a Windows host system, you have to uncomment the [server]
settings in the .streamlit/config.toml
file. Comment these lines again before deploying the project to Streamlit Cloud.
To build the docker image locally, run the following command:
docker build --progress=plain --tag streamlit:latest .
Then to run the docker container locally, run the following command:
docker run -ti -p 8501:8501 --rm streamlit:latest
If you want to run the docker container locally and make code changes on the fly, run the following command:
docker run -ti -p 8501:8501 -v ${pwd}:/app --rm streamlit:latest
👉 For more details, look into the Dockerfile file itself.
The .devcontainer.json file streamlines development environments by providing a consistent configuration for both Visual Studio Code and GitHub Codespaces. This file defines the tools, runtimes, extensions, and settings required for your project. Here's how it works:
- VS Code: The "Remote-Containers" extension in VS Code reads your
.devcontainer.json
to build or access a development container customized for your project. This ensures everyone works in an identical environment. - GitHub Codespaces: Codespaces uses
.devcontainer.json
to automatically provision cloud-based development environments. With one click, you have a ready-to-code workspace, saving time and setup hassle.
For lazy or advanced users, there is also a Makefile included in this template project.
Details about how to use the Makefile with the make
command see Makefile.md.
To deploy the project to Streamlit Cloud, you have to create a new project on Streamlit Cloud and connect it to your GitHub repository. How to deploy a project to Streamlit Cloud see in the official documentation here.
- I don't recommend to use conda and an
environment.yml
file for streamlit projects. Better use a plain and simplerequirements.txt
file. - If you write your
requirements.txt
file, do it manually! Don't usepip freeze > requirements.txt
to generate the file! This will generate a lot of unnecessary or even uninstallable dependencies, which will slow down or even crash the deployment process on Streamlit Cloud.
See also the official documentation from Streamlit about docker deployments:
https://docs.streamlit.io/knowledge-base/tutorials/deploy/docker
Last changed: 2023-11-11