TLS Client

1.0.1 · active · verified Sun Apr 12

Python-TLS-Client is an advanced HTTP client library (version 1.0.1) designed to mimic browser-like TLS fingerprints and behavior, helping to bypass bot protection mechanisms. It offers a similar syntax to the popular `requests` library. The library maintains an active development pace, with frequent updates incorporating new features and shared library improvements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a TLS client session, configure it to mimic a specific browser (Chrome 120), make a GET request to a URL with appropriate headers, and ensure the session is properly closed to avoid resource leaks.

import tls_client
import os

# Initialize a TLS client session mimicking Chrome 120
session = tls_client.Session(
    client_identifier="chrome120", 
    random_tls_extension_order=True,
    proxy=os.environ.get('TLS_PROXY', '') # Optional: load proxy from environment variable
)

try:
    # Make a GET request with browser-like headers
    response = session.get(
        "https://www.example.com/",
        headers={
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
            "Accept-Language": "en-US,en;q=0.9",
            "Accept-Encoding": "gzip, deflate, br"
        },
        timeout_seconds=30
    )

    print(f"Status Code: {response.status_code}")
    print(f"Response Body (first 200 chars): {response.text[:200]}")
except Exception as e:
    print(f"An error occurred: {e}")
finally:
    session.close() # Crucial for releasing resources and preventing memory leaks

view raw JSON →