Skip to main content

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 build produces both sdist and wheel; install via pip or 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.type alone 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

enableStaticServing is 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 a background-color; it does not call out to the network or touch user data.
  • Tune blur and opacity freely; 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

streamlit_video_background-0.2.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_video_background-0.2.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_video_background-0.2.0.tar.gz.

File metadata

  • Download URL: streamlit_video_background-0.2.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.13.5 Windows/11

File hashes

Hashes for streamlit_video_background-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7a18610d87a327a6dcb52994b5a7b89d1fb428558347b3479df611060d7608f4
MD5 4c15a3ed6efb8086a0197a50ad7e27b2
BLAKE2b-256 339c64565fab98db147d28c81649a7f5cf9911bbed95d42d7c48448f7f69be16

See more details on using hashes here.

File details

Details for the file streamlit_video_background-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_video_background-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f0026784579e10aee681fac4364ac29a5ae36ac0ee2c19cf04a97382fd0cc8d3
MD5 615283901fa0f053ebd67b3fd6fec646
BLAKE2b-256 4735bfcaa4a455a1a2c995d32467f54e1e2879e6a60b7b936c621fd483ea7b4d

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page