What this thread does
Do first: guard st.file_uploader(..., type="csv") against None, then pass uploaded bytes and every analysis filter into the cached computation.
Short answer
As of November 2026, this card targets Streamlit 1.67.0 (November 5 release). Separate upload parsing, filter state and pure analysis. Cache data by actual inputs; cache shared resources only when their lifetime and thread safety are appropriate.
Choose / don't choose
- st.cache_data: choose for parsed tables and computed results; callers receive separate copies. (data cache).
- st.cache_resource: choose for a shared model or connection. Global resources share the same instance across users/reruns and must be thread-safe; use
scope="session"or Session State for resources that cannot be shared safely (resource cache). - Form: Form filters reach Python together on submit. Choose to apply several filters together; don't put a dependent selector inside a form when its choices must update before submit (forms).
Not for: correcting an agent's Streamlit API knowledge; see streamlit-official-agent-skill-for-claude-code.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
server.maxUploadSize | Default 200 MB per file; example app policy 20 MB in the [server] section | Current Streamlit config | config |
st.file_uploader.type | "csv" for this analysis; default None accepts all extensions. This is not content validation | Current uploader API | uploader |
accept_multiple_files, max_upload_size | False for one analysis file; None inherits server limit, a positive widget MB value overrides it | Current uploader API | uploader |
st.cache_data.ttl | Example 3600 seconds; default None never expires | Current cache API | caching guide |
st.cache_data.max_entries | Example 1000; default None is unbounded. Lower it for large results | Current cache API | caching guide |
persist | Leave disabled when relying on TTL; disk persistence ignores TTL | Current cache API | cache_data |
st.form.clear_on_submit | False (default) retains submitted filters; include st.form_submit_button | Current form API | forms |
The 20 MB limit is an illustrative application choice, not a CSV memory bound.; this release also adds max_size and server.maxCacheDataSize (release, caching guide).
Order of operations
1. Render upload and stop below it when no file exists. Read upload.getvalue() into stable bytes; parse those bytes, catch malformed input and validate the required columns/types before analysis (uploader). 2. Give the upload a content identity and reset incompatible filter selections when that identity changes. Store widget/filter state per session; initialize or change it before constructing affected widgets. Callbacks execute before the top-to-bottom rerun; read keyed widget values from st.session_state inside callbacks (Session State). 3. Render column selection outside a form when it changes the available values. Batch remaining filters inside a form with explicit submit.; form edits reach Python together on submit (form contract). 4. Use a pure cached function whose arguments include the raw bytes or an equivalent complete content key, all filter values and any external data/model version affecting the result. Example application signature: analyze(raw, column, selected_values, model_revision). Make list selections a stable tuple. Never prefix result-changing arguments with _: those arguments are excluded from hashing (cache contract). 5. Render results and exports from that same returned filtered dataset. A new upload must not retain an old table merely because a Session State result key exists. For user-restricted data, include the authorized data scope in cache identity or choose session scope; global caching is not access control. 6. Compare two different uploads, two filter choices and a return to a prior choice. Repeated identical inputs may reuse computation; changed inputs must produce their own result. Use a short TTL during development to inspect expiry behavior.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
NameError: name 'df' is not defined | Dataframe use occurs before any successful upload/parse | Keep dataframe construction and all dependent operations behind the upload guard | Paul_Smith, October 3, 2021 report |
| Wrong result after filter change | Underscore-excluded arguments are not hashed | Pass every result-changing input explicitly; inspect custom hashing if present | cache key rules |
| Filters do not apply until submit | Form batching is intentional | Submit the form; move only controls needing immediate dependent reruns outside it | forms |
Diagnostic: wrong result after changing a filter
Missing
- The linked source does not confirm: Don't read an unkeyed widget/global inside a cached function and expect its changes to invalidate the result
- The linked source does not confirm: Parsed tables and cached copies can use substantially more memory than the upload.
- The linked source does not confirm: Entry count alone is not a byte budget
- The linked source does not confirm: A widget change outside forms reruns the script
- The linked source does not confirm: Compare the cached call's arguments before clearing all caches. If they are unchanged, TTL cannot repair missing identity; it only delays the same collision. Check whether the display instead reads an old Session State result.
- Accepted schema, upload-memory budget and freshness requirements are application inputs; 20 MB, one hour and 1000 entries are examples.
- A globally shared connection must obey its driver's concurrency contract; caching does not make it thread-safe.
Checked
2026-11-12; Streamlit 1.67.0 (release); linked upload/config/cache/forms/state docs and Paul_Smith report read. No Streamlit app commands executed.
Started from a post by @Streamlit, packaged by the editor. Original post