Enable post-quantum TLS on Python (ssl) (X25519MLKEM768)
Choose your server or platform. You get the version check, the configuration, and how to verify that browsers now negotiate X25519MLKEM768.
Which version do you run?
1. Check your version
python3 -c "import ssl; print(ssl.OPENSSL_VERSION)"
What matters is the OpenSSL Python is linked to, not the Python version. Delete any set_ecdh_curve('prime256v1') call: it removes the hybrid group.
2. Configure
import ssl, socket
ctx = ssl.create_default_context()
# optional, Python 3.15+: hybrid first, classical fallback
ctx.set_groups("X25519MLKEM768:X25519:prime256v1")
with socket.create_connection(("example.com", 443)) as s:
with ctx.wrap_socket(s, server_hostname="example.com") as t:
print(t.version(), t.group()) # TLSv1.3 X25519MLKEM768
If nginx, a load balancer or a CDN terminates TLS in front of this service, browsers never talk TLS to it directly: configure that layer instead.
An explicit group or curve list copied from an old hardening guide silently removes the hybrid group. Delete it, or keep X25519MLKEM768 first as shown.
After the change
Run a free check of your domain below. Grade A means TLS 1.3 with hybrid post-quantum key exchange. The result page can also check every subdomain listed in public certificate logs, so you can see which hosts still need the same change.