-
Notifications
You must be signed in to change notification settings - Fork 0
Home
lv_oz2 edited this page Aug 22, 2025
·
4 revisions
python_sri is a Python module to generate Subresource Integrity hashes on the fly. It supports Python 3.10+, including free threading, and has zero dependencies
Use the package manager pip to install python_sri.
pip install python_sriThen import, setup and hash!
from python_sri import SRI
# Creating an instance, providing your site's domain name and some config
sri = SRI('https://example.com', static={'directory': 'static', 'url_path': '/static'})
@sri.html_uses_sri('/')
def index() -> str:
return '''
...
<link rel="stylesheet" href="static/main.css" integrity></link>
...
'''
# -> ...
# <link rel="stylesheet" href="static/main.css"></link>
# ...
sri.hash_html('/', '<script src="/static/main.js" integrity></script>')
# -> <script src="/static/main.js"></script>