localhost:8501: Running a Streamlit App

Streamlit prints 'Local URL: http://localhost:8501' when streamlit run starts your script. That address works only while the command keeps running in its terminal. If it refuses to connect, the process stopped or picked 8502 because 8501 was taken. On a remote server or container, use the Network URL or publish the port.

Streamlit server settings that matter
SettingDefaultSet it with
server.port8501--server.port 8502
server.addressAll interfaces--server.address 127.0.0.1
server.headlessfalse--server.headless true

Updated

Streamlit reruns your whole script on every interaction, and it serves the app over a WebSocket after the first page load. A page that loads its frame but spins forever usually means that socket is blocked, often by a proxy in front of the app.

Pin the port and run headless

.streamlit/config.toml

Put the .streamlit folder in the directory you run streamlit run from, or in your home directory for a global default.

[server]
port = 8501
headless = true
address = "0.0.0.0"

The same for one run

Flags override the config file.

streamlit run app.py --server.port 8501 --server.headless true

Sharing the app beyond your machine

The Network URL works for colleagues on the same network if the firewall allows the port. For anything public, deploy the app to a host and keep secrets in that host's settings, not in the script.

Streamlit is built for data apps. A company homepage with services, prices and a contact form is a better fit for We.Inc, which publishes such a page on its own address.

How it works

  1. Run streamlit run app.py from the folder that holds your script.
  2. Open the Local URL it prints, including the port number.
  3. Pin the port in .streamlit/config.toml if something depends on it.
  4. On a server, run headless and open the Network URL from your own machine.

Tips

  • Running python app.py on a Streamlit script does not start the server; always launch it with streamlit run.
  • Behind Nginx, forward the Upgrade and Connection headers so the WebSocket at /_stcore/stream can connect.
  • Opening the app on Windows while a second copy still runs gives you 8502, and edits may appear in only one of them.

Frequently asked questions

How do I change the Streamlit port from 8501?

Pass --server.port, for example streamlit run app.py --server.port 8080, or set port under [server] in .streamlit/config.toml.

Why does localhost:8501 not open in my browser?

The streamlit run command has ended, perhaps with an import error printed above the prompt, or the app is on another machine. Restart it and read the first error line.

How do I stop Streamlit from opening a browser tab?

Set server.headless to true. Servers and containers need this anyway, since there is no browser to open.

How do I run Streamlit in Docker?

Expose 8501 in the image, start Streamlit with --server.address 0.0.0.0, and run the container with -p 8501:8501. Then open http://localhost:8501 on the host.

Related: localhost:8888 (Jupyter), localhost:8000, localhost:11434 (Ollama), localhost refused to connect.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Guides

Product

Who It's For

Features

Resources

Company

View Sitemap