django-sri
Subresource Integrity for Django
What it is and what it does
django-sri is a Django app that automatically computes and injects Subresource Integrity (SRI) hashes into your static file references. It works through template tags that wrap Django's static file system, generating integrity attributes for script and link elements so browsers can verify that fetched resources haven't been tampered with. The package supports SHA256, SHA384, and SHA512 algorithms, caches hashes in Django's caching framework for performance, and integrates seamlessly with static file storage backends like WhiteNoise and manifest-based storage.
You install it, add it to INSTALLED_APPS, then use template tags like `{% sri_static "index.js" %}` instead of the standard static tag. It also provides a Python API for computing integrity hashes directly. By default, hashes are suppressed during local development (when DEBUG=True) to avoid churn as files change, but this is configurable.
Use it for:
- Add SRI verification to production Django sites to detect CDN or network-level tampering with static assets.
- Integrate SRI into a Django app serving static files through WhiteNoise or similar middleware without manual hash management.
- Generate SHA512 integrity hashes for high-security applications requiring stronger algorithms than the default SHA256.
- Retrieve bare integrity values for use in custom script/link generation or Content Security Policy headers.
- Support Jinja2 templates alongside Django templates using the sri.jinja2.sri extension for consistent SRI output.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Generates Subresource Integrity (SRI) hashes for Django static files and outputs them in template tags and script/link elements to verify file integrity in the browser.
Yes. django-sri is actively maintained, has no known vulnerabilities, low install friction (Django only), and solves a real security need with a clean API. Use it if you serve static files in Django and want browser-level integrity verification without manual hash management.
Install
django-sri on PyPI
pip
pip install django-sriuv
uv add django-sripoetry
poetry add django-sriInstalling django-sri
Before you install
Low friction: pure Python wheel with only Django as a runtime dependency. Actively maintained as of 2026-08-13 with recent releases; supports Django 4.2, 5.0, and 5.1 across Python 3.9–3.13.
License in practice
BSD license (permissive) places no restrictions on use, modification, or redistribution in commercial or private projects.
Quickstart
pip install django-sri
# In settings.py: add 'sri' to INSTALLED_APPS
# In template:
{% load sri %}
{% sri_static "index.js" %}
{% sri_static "index.css" algorithm="sha512" %}
# Or in Python:
from sri import calculate_integrity_of_static
integrity = calculate_integrity_of_static("index.js")
Requires Django to be installed; SRI hashes are not output by default when DEBUG=True (set USE_SRI=True to override for local development).
Verify before relying
- Performance impact of cache lookups and hash computation on large static file sets.
- Compatibility with non-standard static file storage backends beyond manifest-based ones.
Package facts
| License | BSD (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — Django |
| Maintenance | actively maintained — 570 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 140,075/month — #11,278 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_sri-0.8.0-py3-none-any.whl
Keywords: django, subresource, integrity, sri
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
django-js-assetAdds script, stylesheet, and JSON tags with…
permissive · top 5,000 on PyPI
filehashCalculates and verifies file checksums and…
permissive · top 15,000 on PyPI
django-pipelinedjango-pipeline bundles and compresses CSS and…
permissive · top 15,000 on PyPI
dirhashComputes a single hash value for an entire…
permissive · top 5,000 on PyPI
hashinAutomates the process of adding cryptographic…
permissive · top 15,000 on PyPI
dict-hashGenerates consistent hashes for Python…
permissive · top 15,000 on PyPI
checksumdirComputes a single hash digest of all file…
permissive · top 15,000 on PyPI
poochPooch downloads files from HTTP, FTP, and data…
permissive · top 5,000 on PyPI
django-statici18nCompiles Django's JavaScript…
permissive · top 15,000 on PyPI
sphinxcontrib-jqueryA Sphinx extension that ensures jQuery is…
permissive · top 5,000 on PyPI