Skip to main content

HTTP client that can impersonate web browsers, mimicking their headers and `TLS/JA3/JA4/HTTP2` fingerprints

Project description

Python >= 3.8 Downloads CI

Pyreqwest_impersonate

The fastest python HTTP client that can impersonate web browsers by mimicking their headers and TLS/JA3/JA4/HTTP2 fingerprints.
Binding to the Rust reqwest_impersonate library.

Provides precompiled wheels:

  • Linux|musl: amd64, aarch64.
  • Windows: amd64.
  • MacOS: amd64, aarch64.

Table of Contents

Installation

pip install -U pyreqwest_impersonate

To improve the performance of the library for your particular processor, you can build the library yourself using Rust. Install Rust: https://www.rust-lang.org/tools/install

git clone https://github.com/deedy5/pyreqwest_impersonate.git
cd pyreqwest_impersonate
python3 -m venv .venv
source .venv/bin/activate
pip install maturin
RUSTFLAGS="-C target-cpu=native" maturin develop --release  # Compiled library will be here: .venv/lib/python3.1x/site-packages

Key Features

  • Impersonate: The Client offers an impersonate option, enabling it to mimic web browsers by replicating their headers and TLS/JA3/JA4/HTTP2 fingerprints.
  • Thread-safe: The Client is designed to be thread-safe, allowing it to be safely used in multithreaded environments.
  • Automatic Character Encoding Detection: The encoding is taken from the "Content-Type" header, but if not specified, "UTF-8". If encoding does not match the content, the package automatically detects and uses the correct encoding to decode the text.
  • Small Size: The compiled library is about 5.8MB in size.
  • High Performance: The library is designed for a large number of threads, uses all processors, and releases the GIL. All operations like accessing headers, decoding text, or parsing JSON are executed in Rust.

Usage

I. Client

HTTP client that can impersonate web browsers.

class Client:
    """Initializes an HTTP client that can impersonate web browsers.
    
    Args:
        auth (tuple, optional): A tuple containing the username and password for basic authentication. Default is None.
        auth_bearer (str, optional): Bearer token for authentication. Default is None.
        params (dict, optional): Default query parameters to include in all requests. Default is None.
        headers (dict, optional): Default headers to send with requests. If `impersonate` is set, this will be ignored.
        timeout (float, optional): HTTP request timeout in seconds. Default is 30.
        cookie_store (bool, optional): Enable a persistent cookie store. Received cookies will be preserved and included 
            in additional requests. Default is True.
        referer (bool, optional): Enable or disable automatic setting of the `Referer` header. Default is True.
        proxy (str, optional): Proxy URL for HTTP requests. Example: "socks5://127.0.0.1:9150". Default is None.
        impersonate (str, optional): Entity to impersonate. Example: "chrome_123". Default is None.
            Chrome: "chrome_99","chrome_100","chrome_101","chrome_104","chrome_105","chrome_106","chrome_108", 
                "chrome_107","chrome_109","chrome_114","chrome_116","chrome_117","chrome_118","chrome_119", 
                "chrome_120","chrome_123"
            Safari: "safari_ios_17_2","safari_12","safari_15_3","safari_15_5","safari_15_6_1","safari_16","safari_16_5",
                "safari_17_2_1","safari17_4_1"
            OkHttp: "okhttp_3_9","okhttp_3_11","okhttp_3_13","okhttp_3_14","okhttp_4_9","okhttp_4_10","okhttp_5"
            Edge: "edge_99","edge_101","edge_122"
        follow_redirects (bool, optional): Whether to follow redirects. Default is True.
        max_redirects (int, optional): Maximum redirects to follow. Default 20. Applies if `follow_redirects` is True.
        verify (bool, optional): Verify SSL certificates. Default is False.
        http1 (bool, optional): Use only HTTP/1.1. Default is None.
        http2 (bool, optional): Use only HTTP/2. Default is None.
         
    """

Client Methods

The Client class provides a set of methods for making HTTP requests: get, head, options, delete, post, put, patch, each of which internally utilizes the request() method for execution. The parameters for these methods closely resemble those in httpx.

def get(url, params=None, headers=None, auth=None, auth_bearer=None, timeout=None):
    """Performs a GET request to the specified URL.

    Args:
        url (str): The URL to which the request will be made.
        params (Optional[Dict[str, str]]): A map of query parameters to append to the URL. Default is None.
        headers (Optional[Dict[str, str]]): A map of HTTP headers to send with the request. Default is None.
        auth (Optional[Tuple[str, Optional[str]]]): A tuple containing the username and an optional password 
            for basic authentication. Default is None.
        auth_bearer (Optional[str]): A string representing the bearer token for bearer token authentication. Default is None.
        timeout (Optional[float]): The timeout for the request in seconds. Default is 30.

    """
def post(url, params=None, headers=None, content=None, data=None, files=None, auth=None, auth_bearer=None, timeout=None):
    """Performs a POST request to the specified URL.

    Args:
        url (str): The URL to which the request will be made.
        params (Optional[Dict[str, str]]): A map of query parameters to append to the URL. Default is None.
        headers (Optional[Dict[str, str]]): A map of HTTP headers to send with the request. Default is None.
        content (Optional[bytes]): The content to send in the request body as bytes. Default is None.
        data (Optional[Dict[str, str]]): The form data to send in the request body. Default is None.
        files (Optional[Dict[str, str]]): A map of file fields to file paths to be sent as multipart/form-data. Default is None.
        auth (Optional[Tuple[str, Optional[str]]]): A tuple containing the username and an optional password 
            for basic authentication. Default is None.
        auth_bearer (Optional[str]): A string representing the bearer token for bearer token authentication. Default is None.
        timeout (Optional[float]): The timeout for the request in seconds. Default is 30.

    """

Example

import pyreqwest_impersonate as pri

client = pri.Client(impersonate="chrome_123")

# get request
resp = client.get("https://tls.peet.ws/api/all")
print(resp.json())

# post request
data = {"key1": "value1", "key2": "value2"}
auth = ("user", "password")
resp = client.post(url="https://httpbin.org/anything", data=data, auth=auth)
print(resp.content)
print(resp.cookies)
print(resp.headers)
print(resp.json())
print(resp.status_code)
print(resp.text)
print(resp.url)

# You can also use convenience functions that use a default Client instance under the hood:
# pri.get() | pri.head() | pri.options() | pri.delete() | pri.post | pri.patch | pri.put
# These functions can accept the `impersonate` parameter:
resp = pri.get("https://httpbin.org/anything", impersonate="chrome_123")  

II. AsyncClient

TODO

Project details


Download files

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

Source Distribution

pyreqwest_impersonate-0.4.2.tar.gz (101.8 kB view details)

Uploaded Source

Built Distributions

pyreqwest_impersonate-0.4.2-cp38-abi3-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.8+ Windows x86-64

pyreqwest_impersonate-0.4.2-cp38-abi3-musllinux_1_2_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.8+ musllinux: musl 1.2+ x86-64

pyreqwest_impersonate-0.4.2-cp38-abi3-musllinux_1_2_aarch64.whl (2.5 MB view details)

Uploaded CPython 3.8+ musllinux: musl 1.2+ ARM64

pyreqwest_impersonate-0.4.2-cp38-abi3-manylinux_2_28_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.28+ x86-64

pyreqwest_impersonate-0.4.2-cp38-abi3-manylinux_2_28_aarch64.whl (2.5 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.28+ ARM64

pyreqwest_impersonate-0.4.2-cp38-abi3-macosx_11_0_arm64.whl (2.5 MB view details)

Uploaded CPython 3.8+ macOS 11.0+ ARM64

pyreqwest_impersonate-0.4.2-cp38-abi3-macosx_10_12_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.8+ macOS 10.12+ x86-64

File details

Details for the file pyreqwest_impersonate-0.4.2.tar.gz.

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.4.2.tar.gz
Algorithm Hash digest
SHA256 a73e2c86241a9e2cb3a7a78775dd3229ace194d63ae0c91ae3bdd1b325a5eac1
MD5 907c427928925713e6a01a81e34cd6c7
BLAKE2b-256 b845588b23dd76142404b012a7f3972938faaa65c50931ed6272a81a87f8da49

See more details on using hashes here.

Provenance

File details

Details for the file pyreqwest_impersonate-0.4.2-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.4.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6b38158374e6e1ec5336b9408673e62c41999de2aba4bf0c134dfc0eeedb620e
MD5 a59fabe7e5f36b7b9974007a3b9cb6fd
BLAKE2b-256 2eaab9e18acb1321c6d43e74c99fe1cc87a384c76b36526acf7a2ab3a54d900c

See more details on using hashes here.

Provenance

File details

Details for the file pyreqwest_impersonate-0.4.2-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.4.2-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3e2d6aef2bd12b2042381f3bf6c528f4a7a3b05a2d35de4ebde98cb75ca7b1d7
MD5 c5f6a3062619b5c53c6c5ba4c96b478f
BLAKE2b-256 1df0cd67f453dcc37f060470306f2f6aa62ea4cd2f1d93f8947ba2f3884c8c83

See more details on using hashes here.

Provenance

File details

Details for the file pyreqwest_impersonate-0.4.2-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.4.2-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 c380664b0b2874fc76a69a9e1ebb793c3783793f1447c8159ec971236e3a7bb8
MD5 6ce12daeb83d818b241fc4e19d96a7f4
BLAKE2b-256 81a535e650818a72fb6f5776484420d5b118d8e55ce4e77e80c6bdc5c42ea2d0

See more details on using hashes here.

Provenance

File details

Details for the file pyreqwest_impersonate-0.4.2-cp38-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.4.2-cp38-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 55d153e11f1185e68cfbab7ae688add1ccb59807270f807d981044ee8a7c5a88
MD5 40e85701fd26ae67e040dcdc00979019
BLAKE2b-256 39526577159e7d9246f87436dac6999c625407abf0b40f7c722257a6a1be2395

See more details on using hashes here.

Provenance

File details

Details for the file pyreqwest_impersonate-0.4.2-cp38-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.4.2-cp38-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0944ecc53d773cb6b5fe77c03dfaf8bd42cfcc045b13f8c752fab1e78fdc550f
MD5 525ff694889110d1bc38d222c0d10305
BLAKE2b-256 0cc337b92feb9ab0941d70a6c5f335ca3bcb637a8cae1d88f6ff2ab9a241cbc9

See more details on using hashes here.

Provenance

File details

Details for the file pyreqwest_impersonate-0.4.2-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.4.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 14345a580d0017a7c8d83f63be40da30a09ea09baa6c5b1236bd0d7818abddf2
MD5 e24fe3539cbb79c318d9379f1c3bfcc7
BLAKE2b-256 f301a4a0cec390287eb56e9aa8021ac4f087c8ba7d70b2c77ac9895e3792d439

See more details on using hashes here.

Provenance

File details

Details for the file pyreqwest_impersonate-0.4.2-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.4.2-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9442ec37fbd99e4b00151e2e8fe064e6159f6075f1c631f9b7b2b2294d5461ad
MD5 204d49df4203ce4154d1fee477d02e1b
BLAKE2b-256 e6e64d6d975c289f6842375338f7481cefbb18c0375ef25aad34af18d4e3da85

See more details on using hashes here.

Provenance

Supported by

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