Python ssl Module
Example
Get SSL/TLS protocol version:
import ssl
print(f'OpenSSL version: {ssl.OPENSSL_VERSION}')
print(f'Has SNI: {ssl.HAS_SNI}')
Try it Yourself »
Definition and Usage
The ssl module provides TLS/SSL wrapper functionality for socket objects to create secure network connections.
Use it to add encryption and authentication to network communications, verify certificates, or create secure servers.
Members
| Member | Description |
|---|---|
| CERT_NONE | Don't require or validate certificates. |
| CERT_OPTIONAL | Request peer certificate but don't require it. |
| CERT_REQUIRED | Require and validate peer certificate. |
| HAS_SNI | Whether SNI (Server Name Indication) is available. |
| OPENSSL_VERSION | OpenSSL version string. |
| PROTOCOL_TLS | Auto-negotiate highest TLS version. |
| SSLContext | SSL configuration and settings holder. |
| SSLError | Base exception for SSL errors. |
| SSLSocket | SSL-wrapped socket object. |
| create_default_context() | Create SSLContext with secure default settings. |
| get_server_certificate() | Retrieve server's certificate. |
| wrap_socket() | Wrap an existing socket in SSL/TLS. |