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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file streamlit_video_background-0.1.0.tar.gz.
File metadata
- Download URL: streamlit_video_background-0.1.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/2.4.1 CPython/3.13.5 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd51f3db406221803e32b6d477a4be9aa707dd9cbbb5e56bdc328a17a9344c1a
|
|
| MD5 |
1d1438a22b1e3f3d45b553a5d309d682
|
|
| BLAKE2b-256 |
a2471c274ce34480a43af5ff54885aafbec5d395b6084526c1aa2f4628bbeeec
|
File details
Details for the file streamlit_video_background-0.1.0-py3-none-any.whl.
File metadata
- Download URL: streamlit_video_background-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/2.4.1 CPython/3.13.5 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89d9cddaeb1c9fe4aa22829c7c0ecb5ed5fb331a27278b77a890356e5cc19c44
|
|
| MD5 |
a199bd8699557edfd77de7d51bb3e4b6
|
|
| BLAKE2b-256 |
fc3d8190930e11432aa6a9795465866be7d516e77195f88435178872ba6393b0
|