Search notes:

Python standard library: ssl.SSLSocket

The class ssl.SSLSocket is derived from socket.socket and wraps the underlying OS socket in an SSL context when necessary, and provides read and write method over that channel.
SSLSocket instances must be created with ssl_context.wrap_socket() (where ssl_context is an instance of ssl.SSLContext).
import socket
import ssl

hostname = "raw.githubusercontent.com"
port     =  443
path     = "/python/cpython/refs/heads/main/Lib/ssl.py"

context = ssl.create_default_context()

with socket.create_connection((hostname, port)) as sock:
    with context.wrap_socket(sock, server_hostname=hostname) as ssock:

        request = (
           f"GET {path} HTTP/1.1\r\n"
           f"Host: {hostname}\r\n"
            "Connection: close\r\n"
            "\r\n"
        ).encode()

        ssock.sendall(request)

        response = b""
        while True:
            chunk = ssock.recv(4096)
            if not chunk:
                break
            response += chunk

print(response.decode())

See also

ssl

Index