all Python 3socketterm
ssl
module
TLS/SSL encryption over sockets built on OpenSSL: secure connections and certificate checks.
Syntax
import ssl
ssl wraps an ordinary socket in an encrypted one: connections are built from an SSLContext, and ssl.create_default_context gives safe defaults — certificate and hostname verification. Turning those checks off just to make it work is the classic mistake. You rarely need the module directly: urllib.request, http.client and asyncio use it for you. The old ssl.wrap_socket function was removed in 3.12.
Examples
import importlib.util
print(importlib.util.find_spec('ssl') is not None) # → ? True, если Python собран с OpenSSL
if importlib.util.find_spec('ssl') is not None:
import ssl
ctx = ssl.create_default_context()
print(ctx.check_hostname, ctx.verify_mode == ssl.CERT_REQUIRED) # → ? True True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy