The `hstspreload` Python package provides an offline, queryable version of the Chromium HSTS (HTTP Strict Transport Security) preload list. It allows users to check if a given hostname is included in this list, indicating that web browsers should only access it via HTTPS. The package's data is updated monthly by an automated script, ensuring a regularly refreshed snapshot of the official list.
pip install hstspreloadVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import and use the `in_hsts_preload` function to check if a hostname is on the HSTS preload list. It includes an important step for IDNA encoding to correctly handle internationalized domain names (IDNs) like `bücher.example`.
Ensure hostnames are IDNA-encoded before passing them to `in_hsts_preload()`. Example: `idna.encode('bücher.example').decode('ascii')`.Be aware of the monthly update cycle. For applications requiring the absolute latest state, consider monitoring the Chromium repository directly or manually triggering a package update if available for critical changes.
If consistency across all browsers is critical, consult browser-specific documentation or testing tools in addition to this library.
Use hstspreload.org for validating preloading eligibility and configuration issues. This library is for querying the list state, not for site configuration analysis.
pip install hstspreload
from hstspreload import in_hsts_preload
is_preloaded = in_hsts_preload('example.com')import idna
hostname = 'bücher.example'
encoded_hostname = idna.encode(hostname).decode('ascii')
is_preloaded = in_hsts_preload(encoded_hostname)from hstspreload import in_hsts_preload
is_preloaded = in_hsts_preload('example.com')No dependency data recorded yet.