Chromium HSTS Preload List Python Package

2025.1.1 · active · verified Mon Apr 13

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.

Warnings

Install

Imports

Quickstart

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`.

import idna
from hstspreload import in_hsts_preload

def check_hsts_preload(hostname):
    # Ensure the hostname is IDNA-encoded for internationalized domain names
    # For ASCII domains, this step typically returns the original hostname.
    encoded_hostname = idna.encode(hostname).decode('ascii')
    is_preloaded = in_hsts_preload(encoded_hostname)
    print(f"Is '{hostname}' (IDNA: '{encoded_hostname}') on the HSTS preload list? {is_preloaded}")

# Example usage
check_hsts_preload('google.com')
check_hsts_preload('example.com') # Often not preloaded for general use
check_hsts_preload('bücher.example') # Internationalized Domain Name (IDN)

view raw JSON →