Skip to main content

Browser fingerprint emulation HTTP client with HTTP/1.1, HTTP/2, and HTTP/3 support

Project description

HTTPCloak Python

Browser fingerprint emulation HTTP client with HTTP/1.1, HTTP/2, and HTTP/3 support.

Installation

pip install httpcloak

Quick Start

Synchronous Usage

from httpcloak import Session

# Create a session with Chrome fingerprint
session = Session(preset="chrome-143")

# Make requests
response = session.get("https://www.cloudflare.com/cdn-cgi/trace")
print(response.status_code)
print(response.text)

# POST request with JSON
response = session.post_json("https://api.example.com/data", {"key": "value"})

# POST request with form data
response = session.post("https://api.example.com/form", body="field1=value1&field2=value2")

# Custom headers
response = session.get("https://example.com", headers={"X-Custom": "value"})

# With proxy
session = Session(preset="chrome-143", proxy="http://user:pass@host:port")

# Always close when done
session.close()

Context Manager (Recommended)

from httpcloak import Session

with Session(preset="chrome-143") as session:
    response = session.get("https://example.com")
    print(response.text)
# Session automatically closed

Asynchronous Usage

import asyncio
from httpcloak import Session

async def main():
    session = Session(preset="chrome-143")

    # Async GET
    response = await session.get_async("https://example.com")
    print(response.text)

    # Async POST
    response = await session.post_async("https://api.example.com/data", body={"key": "value"})

    # Multiple concurrent requests
    responses = await asyncio.gather(
        session.get_async("https://example.com/1"),
        session.get_async("https://example.com/2"),
        session.get_async("https://example.com/3"),
    )

    session.close()

asyncio.run(main())

Fast Response Mode

For performance-critical applications, use get_fast() which returns a lightweight response:

from httpcloak import Session

with Session(preset="chrome-143") as session:
    # Fast mode - minimal overhead
    response = session.get_fast("https://example.com")
    data = bytes(response.content)  # Raw bytes
    print(f"Status: {response.status_code}")
    print(f"Size: {len(data)} bytes")

Streaming Downloads

For large downloads, use streaming to avoid loading entire response into memory:

from httpcloak import Session

with Session(preset="chrome-143") as session:
    # Stream a large file
    stream = session.get_stream("https://example.com/large-file.zip")
    print(f"Status: {stream.status_code}")
    print(f"Content-Length: {stream.content_length}")

    # Read in chunks
    with open("downloaded-file.zip", "wb") as f:
        for chunk in stream.read_chunks(65536):  # 64KB chunks
            f.write(chunk)

    stream.close()

# Or use context manager
with Session(preset="chrome-143") as session:
    with session.get_stream("https://example.com/large-file.zip") as stream:
        total = 0
        for chunk in stream.read_chunks(65536):
            total += len(chunk)
        print(f"Downloaded {total} bytes")

Proxy Support

HTTPCloak supports HTTP, SOCKS5, and HTTP/3 (MASQUE) proxies with full fingerprint preservation.

HTTP Proxy

from httpcloak import Session

# Basic HTTP proxy
session = Session(preset="chrome-143", proxy="http://host:port")

# With authentication
session = Session(preset="chrome-143", proxy="http://user:pass@host:port")

# HTTPS proxy
session = Session(preset="chrome-143", proxy="https://user:pass@host:port")

SOCKS5 Proxy

from httpcloak import Session

# SOCKS5 proxy (with DNS resolution on proxy)
session = Session(preset="chrome-143", proxy="socks5h://host:port")

# With authentication
session = Session(preset="chrome-143", proxy="socks5h://user:pass@host:port")

response = session.get("https://www.cloudflare.com/cdn-cgi/trace")
print(response.protocol)  # h3 (HTTP/3 through SOCKS5!)

HTTP/3 MASQUE Proxy

MASQUE (RFC 9484) enables HTTP/3 connections through compatible proxies:

from httpcloak import Session

# MASQUE proxy (auto-detected for known providers like Bright Data)
session = Session(preset="chrome-143", proxy="https://user:pass@brd.superproxy.io:10001")

response = session.get("https://www.cloudflare.com/cdn-cgi/trace")
print(response.protocol)  # h3

Split Proxy Configuration

Use different proxies for TCP (HTTP/1.1, HTTP/2) and UDP (HTTP/3) traffic:

from httpcloak import Session

session = Session(
    preset="chrome-143",
    tcp_proxy="http://tcp-proxy:port",      # For HTTP/1.1, HTTP/2
    udp_proxy="https://masque-proxy:port"   # For HTTP/3
)

Advanced Features

Encrypted Client Hello (ECH)

ECH encrypts the SNI (Server Name Indication) to prevent traffic analysis. Works with all Cloudflare domains:

from httpcloak import Session

# Enable ECH for Cloudflare domains
session = Session(preset="chrome-143", ech_config_domain="cloudflare-ech.com")

response = session.get("https://www.cloudflare.com/cdn-cgi/trace")
print(response.text)
# Output includes: sni=encrypted, http=http/3

Domain Fronting (Connect-To)

Connect to one server while requesting a different domain:

from httpcloak import Session

# Connect to claude.ai's IP but request www.cloudflare.com
session = Session(
    preset="chrome-143",
    connect_to={"www.cloudflare.com": "claude.ai"}
)

response = session.get("https://www.cloudflare.com/cdn-cgi/trace")

Combined: SOCKS5 + ECH

Get HTTP/3 with encrypted SNI through a SOCKS5 proxy:

from httpcloak import Session

session = Session(
    preset="chrome-143",
    proxy="socks5h://user:pass@host:port",
    ech_config_domain="cloudflare-ech.com"
)

response = session.get("https://www.cloudflare.com/cdn-cgi/trace")
# Response shows: http=http/3, sni=encrypted

Cookie Management

from httpcloak import Session

session = Session()

# Set a cookie
session.set_cookie("session_id", "abc123")

# Get all cookies
cookies = session.get_cookies()
print(cookies)

# Access cookies as property
print(session.cookies)

# Clear a cookie
session.clear_cookie("session_id")

# Clear all cookies
session.clear_cookies()

session.close()

Session Configuration

from httpcloak import Session

session = Session(
    preset="chrome-143",           # Browser fingerprint preset
    proxy=None,                    # Proxy URL
    tcp_proxy=None,                # Separate TCP proxy
    udp_proxy=None,                # Separate UDP proxy (MASQUE)
    timeout=30,                    # Request timeout in seconds
    http_version="auto",           # "auto", "h1", "h2", "h3"
    verify=True,                   # SSL certificate verification
    allow_redirects=True,          # Follow redirects
    max_redirects=10,              # Maximum redirect count
    retry=3,                       # Retry count on failure
    prefer_ipv4=False,             # Prefer IPv4 over IPv6
    auth=("user", "pass"),         # Default basic auth
    connect_to=None,               # Domain fronting map
    ech_config_domain=None         # ECH config domain
)

Available Presets

from httpcloak import available_presets

print(available_presets())
# ['chrome-143', 'chrome-143-windows', 'chrome-143-linux', 'chrome-143-macos',
#  'chrome-131', 'firefox-133', 'safari-18', ...]

Response Object

Standard Response

response = session.get("https://example.com")

response.status_code   # int: HTTP status code
response.headers       # dict[str, list[str]]: Response headers (multi-value)
response.content       # bytes: Raw response body
response.text          # str: Response body as text
response.url           # str: Final URL after redirects
response.protocol      # str: Protocol used (h2, h3)
response.ok            # bool: True if status < 400
response.elapsed       # float: Request duration in seconds
response.cookies       # list: Cookies from response
response.history       # list: Redirect history
response.reason        # str: Status reason phrase

# Get specific header
content_type = response.get_header("Content-Type")
all_cookies = response.get_headers("Set-Cookie")

# Parse JSON
data = response.json()

Fast Response

response = session.get_fast("https://example.com")

response.status_code   # int: HTTP status code
response.headers       # dict: Response headers
response.content       # memoryview: Raw response body (zero-copy)
response.url           # str: Final URL after redirects
response.protocol      # str: Protocol used

Streaming Response

stream = session.get_stream("https://example.com")

stream.status_code      # int: HTTP status code
stream.headers          # dict[str, list[str]]: Response headers
stream.content_length   # int: Content length (-1 if unknown)
stream.url              # str: Final URL after redirects
stream.protocol         # str: Protocol used

# Read all bytes
data = stream.read_all()

# Read in chunks (memory efficient)
for chunk in stream.read_chunks(65536):
    process(chunk)

stream.close()

HTTP Methods

from httpcloak import Session

with Session(preset="chrome-143") as session:
    # GET
    response = session.get("https://example.com")

    # POST
    response = session.post("https://example.com", body="data")
    response = session.post_json("https://example.com", {"key": "value"})

    # PUT
    response = session.put("https://example.com", body="data")

    # PATCH
    response = session.patch("https://example.com", body="data")

    # DELETE
    response = session.delete("https://example.com")

    # HEAD
    response = session.head("https://example.com")

    # OPTIONS
    response = session.options("https://example.com")

    # Custom method
    response = session.request("CUSTOM", "https://example.com")

Error Handling

from httpcloak import Session, HTTPCloakError

try:
    session = Session()
    response = session.get("https://example.com")
except HTTPCloakError as e:
    print(f"Request failed: {e}")
finally:
    session.close()

Convenience Functions

For one-off requests without managing a session:

import httpcloak

# Simple GET
response = httpcloak.get("https://example.com")
print(response.text)

# With options
response = httpcloak.get(
    "https://example.com",
    headers={"X-Custom": "value"},
    timeout=60
)

# POST
response = httpcloak.post("https://api.example.com", body={"key": "value"})

Platform Support

  • Linux (x64, arm64)
  • macOS (x64, arm64)
  • Windows (x64, arm64)
  • Python 3.8+

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

httpcloak-1.5.7-py3-none-win_amd64.whl (4.2 MB view details)

Uploaded Python 3Windows x86-64

httpcloak-1.5.7-py3-none-manylinux_2_17_x86_64.whl (4.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

httpcloak-1.5.7-py3-none-manylinux_2_17_aarch64.whl (4.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

httpcloak-1.5.7-py3-none-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

httpcloak-1.5.7-py3-none-macosx_10_9_x86_64.whl (4.2 MB view details)

Uploaded Python 3macOS 10.9+ x86-64

File details

Details for the file httpcloak-1.5.7-py3-none-win_amd64.whl.

File metadata

  • Download URL: httpcloak-1.5.7-py3-none-win_amd64.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for httpcloak-1.5.7-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 cc9deb1581cc1634e85056ef0e1a17d743b1b138f1c3c390198d5af64183a5d3
MD5 afce77e137eb13b04a994175d5031310
BLAKE2b-256 ecd7fba1fc0b635775c5e6f215ea33f7eccd94c0bbf1064a33b725e1158d0561

See more details on using hashes here.

File details

Details for the file httpcloak-1.5.7-py3-none-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for httpcloak-1.5.7-py3-none-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 6b009197623c1260a70a1372b8f76618d8edca23fa0c8d17e93ff262d244df8e
MD5 5bf4c148d037a66a08d500371ebf8906
BLAKE2b-256 113aac2d450a9e69c661aaf6c9b307dc0c998d3afe821bb50b3c33158e4d1b93

See more details on using hashes here.

File details

Details for the file httpcloak-1.5.7-py3-none-manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for httpcloak-1.5.7-py3-none-manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 87eb736e5c1e9b701738034ab6184480c4f951c087ad0b51d46f8fff9548b7d2
MD5 68c44d9142537eaa4df4e91852b0f748
BLAKE2b-256 fa16f2cdc3051b136d2a626dd1e328825302d58fbf766d54891f8038bbea2fb9

See more details on using hashes here.

File details

Details for the file httpcloak-1.5.7-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for httpcloak-1.5.7-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c1686b60466ed3450355957d40762d6fb894bb2609828ffce2494f554b446a77
MD5 7ce95ea0b462b7fec7c9cfde8117c0ac
BLAKE2b-256 08bd56657260aa8eaff03b725e3a145eed275a885ba838df8ec65d3099037622

See more details on using hashes here.

File details

Details for the file httpcloak-1.5.7-py3-none-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for httpcloak-1.5.7-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 614ccc555e8cef3e6425ab52fb9462c05daaeed59fe18dcc07c230dd711bd9fc
MD5 3733971661768f05e659812214fc426e
BLAKE2b-256 8577db686d6947f94c8958ba43e19824ce2b4c6ae879b692d6040273f52f790b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page