streamlit-video-background
A small, reusable Streamlit extension that renders a fullscreen, blurred, translucent video as the page background, with a backdrop color that follows the Light/Dark theme — including live theme switching and an opaque, readable sidebar on mobile.
Build & distribute with Poetry.
poetry buildproduces bothsdistandwheel; install viapipor publish to PyPI.
What it does
import streamlit as st
from streamlit_video_background import render_video_background, configure_static_serving
st.set_page_config("Demo", layout="wide")
# Ensure Streamlit serves the app's `static/` folder (and warn you to restart).
configure_static_serving() # sets `server.enableStaticServing = true`
render_video_background(
"/app/static/background_720p.mp4", # a URL (recommended) ...
blur="8px", # CSS blur on the video
opacity=0.5, # translucent video (0..1)
)
st.title("Welcome")
- The video sits fixed behind the page content (
z-index:-1), so it never intercepts clicks. - Blur + opacity give a soft, readable background.
- A JS watcher keeps the backdrop in sync with the actual live theme, so
switching Light ↔ Dark updates the backdrop instantly (Streamlit does not
rerun the script on a theme switch, so
st.context.theme.typealone isn't enough). - The top nav and the sidebar keep their own opaque theme background, so the mobile nav drawer stays readable.
Installation
pip install streamlit-video-background
Alternatively, build locally:
git clone <your-repo> && cd streamlit-video-background
poetry install # dev environment
poetry build # produces dist/*.whl and dist/*.tar.gz
pip install dist/*.whl
Setup for a local video file
Streamlit serves everything in the static/ folder of your app directory at
/app/static/<name> when server.enableStaticServing is enabled.
from streamlit_video_background import ensure_static, render_video_background
url = ensure_static("path/to/background.mp4", project_root=".") # copies into ./static/
render_video_background(url)
Enable static serving in .streamlit/config.toml (or let
configure_static_serving() do it):
[server]
runOnSave = true
enableStaticServing = true
enableStaticServingis a server-level option: restart Streamlit after changing it.
Compress a heavy video (optional)
Backgrounds don't need 1080p or a high bitrate. compress_video downsizes and
re-encodes with FFmpeg (called from round() / CLI / notebook):
from streamlit_video_background import compress_video, probe
info = probe("background.mp4") # duration, bitrate, dimensions
compress_video("background.mp4",
output_path="static/background_720p.mp4",
scale=1280, crf=27, fps=20)
Bake the blur into the file instead of CSS
Pass blur=8 to compress_video to burn a box blur into the output. If you
do, set blur="0px" in render_video_background to avoid a double blur.
API
| Function | Purpose |
|---|---|
render_video_background(video_source, *, blur, opacity, backdrop_light, backdrop_dark, autoplay, loop, muted, playsinline, object_fit) |
Render the background into the current page. |
build_background_html(video_url, **options) |
Pure HTML/CSS/JS builder (testable, no Streamlit). |
ensure_static(video_file, project_root=None, *, overwrite=False) |
Copy a video into static/ and return the URL. |
static_url(name) |
Build /app/static/<name>. |
static_serving_enabled() |
Whether enableStaticServing is on. |
configure_static_serving(enable=True, project_root=None) |
Idempotently set enableStaticServing in config.toml. |
compress_video(input, output=None, *, scale, crf, preset, fps, blur, keep_audio) |
FFmpeg compression helper. |
probe(path) |
FFprobe metadata helper. |
Notes
- The background is injected via
st.html(..., unsafe_allow_javascript=True). The JavaScript only reads the live theme and adjusts abackground-color; it does not call out to the network or touch user data. - Tune
blurandopacityfreely; the backdrop colors default to the standard Streamlit light/dark background but can be overridden.
License
MIT
Metadata
Release files for streamlit-video-background 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| streamlit_video_background-0.2.0.tar.gz | 9.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| streamlit_video_background-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.6 kB
Release files / streamlit_video_background-0.2.0.tar.gz
| Download URL | streamlit_video_background-0.2.0.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7a18610d87a327a6dcb52994b5a7b89d1fb428558347b3479df611060d7608f4
|
|
BLAKE2b-256 checksum How to use checksums |
339c64565fab98db147d28c81649a7f5cf9911bbed95d42d7c48448f7f69be16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.13.5 Windows/11
|
Release files / streamlit_video_background-0.2.0-py3-none-any.whl
| Download URL | streamlit_video_background-0.2.0-py3-none-any.whl |
|---|---|
| Size | 12.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f0026784579e10aee681fac4364ac29a5ae36ac0ee2c19cf04a97382fd0cc8d3
|
|
BLAKE2b-256 checksum How to use checksums |
4735bfcaa4a455a1a2c995d32467f54e1e2879e6a60b7b936c621fd483ea7b4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.13.5 Windows/11
|
Security for streamlit-video-background 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.