Streamlit Cheat Sheet: Python Data Apps Fast

Streamlit turns Python scripts into interactive web apps: one call per widget or chart, with st.session_state keeping values across reruns.

Key Terms

  • st.session_state: Dictionary-like store that survives reruns; initialize with 'key' not in st.session_state before reading.
  • st.form: Groups inputs so the script runs only when its form_submit_button is clicked.
  • st.cache_data: Decorator that stores a function's return value so reruns skip recomputing it.
  • st.navigation: Multipage API: build st.Page objects, pass them to st.navigation, then call pg.run().
  • st.empty: Placeholder container whose content is overwritten by later write() calls.

Pro Tips

  • Wrap multi-field entry in st.form because every widget change otherwise reruns the whole script.
  • Decorate data-loading functions with @st.cache_data so reruns don't reload the same data.
  • Pass value=st.session_state.get('name','') to keep typed text across reruns.
  • Bind to 0.0.0.0 with --server.address in Docker, because localhost-only binding blocks outside access to the container.

Pitfalls to Avoid

  • Reading st.session_state.counter before initializing it raises an error that crashes the page.
  • Omitting --server.address=0.0.0.0 in the Dockerfile CMD leaves the app unreachable from the host.
  • Skipping requirements.txt makes the container build fail, because pip install -r has no file to read.

Related cheat sheets

  • Python Classes and Inheritance Cheat Sheet
  • Software Testing Fundamentals
  • Object-Oriented Programming Cheat Sheet
  • Testing, Debugging, Exceptions, and Assertions Cheat Sheet

More like this

  • More cheat sheets by @sonny000
  • Coding cheat sheets
  • Explore all cheat sheets

ClipSheet — AI Cheat Sheet Generator

ClipSheet transforms YouTube videos, PDFs, and text into structured cheat sheets and study notes using AI. Built for students, professionals, and content creators who need to learn faster.

Features

  • AI-powered extraction of key concepts, formulas, and action steps
  • Automatic quiz and flashcard generation for active recall
  • PDF export and public sharing via unique URLs
  • Support for YouTube videos, PDFs, and raw text input

Browse by Category

  • All Cheat Sheets
  • Science & Academic
  • Technology
  • Health & Fitness
  • Coding
  • Business
  • Education
  • Productivity
  • Finance
  • Lifestyle

Legal

  • Privacy Policy
  • Terms of Service
  • Imprint
  • Verträge hier kündigen