Static file digest cache busting for FastAPI/Starlette
Project description
FastAPI Static Digest
A Starlette/FastAPI plugin to digest and compress static files, and integrate with Jinja templates.
pip install fastapi-static-digest
Usage
# app.py
app_root = Path(__file__).parent
static_src = app_root / "static"
static = StaticDigest(source_dir=static_src)
routes = [
Mount('/static', app=StaticFiles(directory=static.directory), name="static"),
]
app = Starlette(routes=routes)
# manage.py
from .app import app_root
@click.command()
def compile():
src = app_root / "static"
click.echo("Source dir %s" % src)
compiler = StaticDigestCompiler(source_directory=src)
compiler.compile()
click.echo("Done.")
Jinja2 Integration
# app.py
app_root = Path(__file__).parent
static_src = app_root / "static"
static = StaticDigest(source_dir=static_src)
templates = Jinja2Templates(app_root / "templates")
static.register_static_url_for(templates)
routes = [
Mount('/static', app=StaticFiles(directory=static.directory), name="static"),
]
app = Starlette(routes=routes)
<!-- index.html -->
{{ static_url_for("static", "app.css" )}}
renders to
https://myhost.com/static/app.92fede82119d2e012f890e1102080a45.css
Development
PRs and issues are welcome!
Project details
Release history Release notifications | RSS feed
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
Close
Hashes for fastapi-static-digest-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77cfa1bb02e5bfca53074c292ee080fcea94afb99070c05add50433d859b085f |
|
MD5 | 7117c6df0b59e05eab8010f9a5e05f4d |
|
BLAKE2b-256 | 448fdfacd0ffcc44184aa2c18023040bb4488f28e1cc64307a16b5bd576039cf |
Close
Hashes for fastapi_static_digest-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cc912870ec085b3ea6db6c5c0c98857c3174ef855c582bcb1f5e698bc9216de |
|
MD5 | d09d22107f3794b9a63072a1a267f5ec |
|
BLAKE2b-256 | f82a5143a97c2fd1cf1877d89049aaa589bdf87a2e9678140f596a5503cfba31 |