In this guide, I’ll show you how to:
✅ Run your Streamlit app locally
✅ Deploy it online for free (or self-host if you prefer)
Let’s dive in!
🧠 What is Streamlit?
Streamlit is a Python framework that turns your scripts into shareable web apps in minutes. With just a few lines of code, you can create sliders, charts, inputs, and more—all in real time. Perfect for machine learning demos, dashboards, and data apps.
🛠️ Step 1: Install Streamlit
First, let’s get Streamlit installed. If you don’t already have it:
pip install streamlit
✅ Tip: It’s recommended to use a virtual environment.
📂 Step 2: Create Your First Streamlit App
Let’s create a simple app. Create a Python file, for example: app.py
That’s it. You’ve got a working web app with just a few lines.
import streamlit as st
st.title("Hello, Streamlit 👋")
st.write("This is your first Streamlit app. It updates in real-time!")
name = st.text_input("Enter your name:")
if name:
st.success(f"Nice to meet you, {name}!")
▶️ Step 3: Run the App Locally
To launch your app locally, just run:
streamlit run app.py
You’ll see output like this:
Local URL: http://localhost:8501
Network URL: http://192.168.0.xxx:8501
Open the local URL in your browser and boom! You’ve got a working app 🎉
🌐 Step 4: Hosting Your Streamlit App
Now that your app works locally, let’s get it online.
✅ Option 1: Deploy for Free on Streamlit Community Cloud
- Push your app to a GitHub repository (must include
app.py
andrequirements.txt
). - Go to streamlit.io/cloud and sign in with GitHub.
- Click “New app” and select your repository.
- Fill in the path to your main file (e.g.,
app.py
) and click Deploy.
That’s it! Streamlit will install your dependencies and host your app live.
Example requirements.txt
:
streamlit
pandas
matplotlib
📍Your app will be live at https://your-app-name.streamlit.app
.
⚙️ Option 2: Self-Hosting on Your Own Server
Prefer full control? You can deploy Streamlit on any server (e.g., a VPS):
- SSH into your server.
- Install Python, pip, and virtualenv.
- Upload your app files.
- Install dependencies and run:
streamlit run app.py --server.port 8501 --server.enableCORS false
To keep it running 24/7, use tools like tmux
, screen
, or systemd
.
👉 Optionally, use Nginx + SSL + domain to reverse proxy your app like a pro.
🔐 Bonus Tips
- You can customize your Streamlit app with themes, layout tweaks, and state handling.
- Add a
secrets.toml
file if you need to manage API keys securely on Streamlit Cloud. - For analytics or multi-page apps, check out
st.experimental_*
or use Streamlit Multipage.
📝 Wrapping Up
Streamlit makes it ridiculously easy to go from a Python script to a live app in minutes. Whether you’re showcasing your data project, building an AI demo, or just experimenting—Streamlit helps you focus on the logic, not the UI.
Let’s recap:
- ✅ Installed and ran a Streamlit app locally
- ✅ Deployed it for free on Streamlit Cloud
- ✅ Learned how to self-host it with full control