liveBook · Manning

Chapter 5: Sharing your apps with the world

What you will learn in chapter 5 of Build Python Web Apps with Streamlit

This chapter introduces moving a Streamlit app from local development to public deployment, including hosting choices, external services, secrets, and dependencies.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This chapter introduces moving a Streamlit app from local development to public deployment, including hosting choices, external services, secrets, and dependencies.

Key terms: deployment, local development, production, Streamlit Community Cloud, API, API keys, secrets, dependencies, requirements.txt

5.1 Deploying apps

This section introduces the need to share the functional Streamlit applications built so far so that other people can experience them.

Key terms: Streamlit, applications

5.1.1 What is deployment?

This section defines deployment as hosting a Streamlit app so intended users can reach its continuously running server through an accessible URL.

Key terms: deployment, hosting, backend server, frontend, URL, port, localhost, connection

5.1.2 Options for deployment

This section compares local-network, dedicated-server, cloud-platform, and Streamlit Community Cloud deployment options by their reach, operational demands, benefits, and limits.

Key terms: streamlit run, Streamlit server, local URL, network URL, local network, Wi-Fi, dedicated server, physical machine, virtual machine, port

5.2 Deploying the to-do list app to Streamlit Community Cloud

This section introduces deploying the chapter 4 to-do list app to free, Streamlit-specific Community Cloud so it is accessible on the internet.

Key terms: Streamlit Community Cloud, deployment, to-do list app

5.2.1 Prerequisites

This section prepares a developer to deploy on Streamlit Community Cloud by setting up GitHub access, a personal access token, and a connected Community Cloud account.

Key terms: git, GitHub, Streamlit Community Cloud, GitHub account, Community Cloud account, Git repository, version control, revision history, personal access token, PAT

5.2.2 Deployment steps

This section deploys the chapter 4 to-do app by placing its code in GitHub and configuring Streamlit Community Cloud to run it.

Key terms: GitHub repository, Streamlit Community Cloud, deployment, git init, staging area, commit, remote, origin, personal access token, Create an App

5.3 Deploying an app that uses an external service

This introduction explains why real-world Streamlit apps commonly need third-party libraries and external APIs, and previews adding and deploying those dependencies in the to-do app.

Key terms: third-party libraries, Python, Streamlit, external service, application programming interface (API), API, to-do list app, Streamlit Community Cloud, deployment

5.3.1 A joke of the day to entertain users

This section motivates adding a daily joke to the to-do app and explains the API, HTTP, and Dad Jokes API details needed to obtain one from an external service.

Key terms: API, external service, API documentation, contract, HTTP, HTTP client, HTTP request, HTTP response, GET, POST

5.3.2 Using the requests library to connect to an API

This section shows how to install and use Python’s requests library to call a web API, read its response, and supply an API key in an HTTP header.

Key terms: requests, HTTP, pip show requests, requests.get, Response, response.text, response body, HTTP request, X-Api-Key, headers

5.3.3 Incorporating jokes in the app

This section adds a joke-of-the-day feature to the to-do app by fetching, displaying, and caching a joke from an external API.

Key terms: jokes.py, generate_joke, Dad Jokes API, API_URL, API key, requests.get, status code, requests.codes.ok, response.json(), JSON

5.3.4 Accessing an API key safely with st.secrets

This section moves an API key out of Streamlit app code into a local secrets.toml file and accesses it safely through st.secrets.

Key terms: API key, secret information, credential, public GitHub repository, st.secrets, secrets.toml, .streamlit, Streamlit Community Cloud, TOML, jokes_api

5.4 Deploying changes to Streamlit Community Cloud

This section explains that Community Cloud normally redeploys pushed GitHub changes automatically, but dependency and secret-handling changes require additional deployment configuration.

Key terms: git push, GitHub repo, Streamlit Community Cloud, requests, third-party library, secrets.toml, API key

5.4.1 Using a requirements.txt file to manage Python dependencies

This section explains how a requirements.txt file keeps Python dependencies compatible between development and Streamlit Community Cloud production environments.

Key terms: development environment, dev, production environment, prod, dependencies, requests, requirements.txt, pip, pip install -r requirements.txt, GitHub repository

5.4.2 Using .gitignore to protect secrets.toml

This section shows how to keep a local Streamlit secrets.toml file out of Git commits with .gitignore, including how to stop tracking it if it was already committed.

Key terms: .gitignore, .streamlit, secrets.toml, Git repository, commit, Git index, tracked, git rm -r --cached .streamlit/, git push, GitHub

5.4.3 Configuring secrets in Community Cloud

This section shows how to place a development API secret into Streamlit Community Cloud so the deployed app can use it in production.

Key terms: App Settings, Secrets, Secrets textbox, secrets.toml, Streamlit Community Cloud, Manage App, public URL, app list, Settings

5.5 Summary

This section summarizes how to deploy Streamlit apps, manage their code and dependencies, and protect credentials when using Community Cloud and external services.

Where this is used later

Concepts explained in this chapter

← Chapter 4: Streamlit’s execution model Chapter 6: A dashboard fit for a CEO →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.