FastAPI Static Digest
A Starlette/FastAPI plugin to digest and compress static files, and integrate with Jinja templates.
pip install fastapi-static-digest
Overview
There are two classes: StaticDigest and StaticDigestCompiler.
The StaticDigestCompiler.compiler method will produce the digested directory. The StaticDigest (and starlette.staticfiles.StaticFiles) should be configured to read this directory.
The compilation can be added to your build process, for instance with a click CLI command (see below). Alternatively, the FASTAPI_STATICDIGEST_RELOAD=1 environment variable can be set to enable "hot reloading" during development.
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!
Metadata
Release files for fastapi-static-digest 1.1.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 | Actions |
|---|---|---|---|---|
| fastapi-static-digest-1.1.0.tar.gz | 5.1 kB | Without provenance | Details for fastapi-static-digest-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_static_digest-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for fastapi_static_digest-1.1.0-py3-none-any.whl |
Total release size: 11.5 kB
Release files / fastapi-static-digest-1.1.0.tar.gz
| Download URL | fastapi-static-digest-1.1.0.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35ed3fc8fa8e584dd64bdff48bc8044d8bf217d254f240ff813fd5e3636bafb7
|
|
BLAKE2b-256 checksum How to use checksums |
5ff16a9ef65b30a0f83aa1d144c704116f9e9ea045aeef02d40249199ff67924
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.15
|
Release files / fastapi_static_digest-1.1.0-py3-none-any.whl
| Download URL | fastapi_static_digest-1.1.0-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e914148bfca39b5bad8d784ffd50037a2b7be577d5630dbb378ff59ab5ec3c2c
|
|
BLAKE2b-256 checksum How to use checksums |
b6940a64fcc042af4428c8fdc29cb3ef943e3ff893d856c0cf2939fa99d90e81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.15
|
Security for fastapi-static-digest 1.1.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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.