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_124". 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","chrome_124"
            Safari: "safari_12","safari_15_3","safari_15_5","safari_15_6_1","safari_16","safari_16_5",
                "safari_17_2_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_120"
        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 True.
        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: str, 
    params: Optional[Dict[str, str]] = None, 
    headers: Optional[Dict[str, str]] = None, 
    auth: Optional[Tuple[str, Optional[str]]] = None, 
    auth_bearer: Optional[str] = None, 
    timeout: Optional[float] = 30,
):
    """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: str, 
    params: Optional[Dict[str, str]] = None, 
    headers: Optional[Dict[str, str]] = None, 
    content: Optional[bytes] = None, 
    data: Optional[Dict[str, str]] = None, 
    json: Any = None, 
    files: Optional[Dict[str, str]] = None, 
    auth: Optional[Tuple[str, Optional[str]]] = None, 
    auth_bearer: Optional[str] = None, 
    timeout: Optional[float] = 30,
):
    """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.
        json (Any): A JSON serializable object 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_124")

# 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_124")  

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.3.tar.gz (129.8 kB view details)

Uploaded Source

Built Distributions

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

Uploaded CPython 3.8+ Windows x86-64

pyreqwest_impersonate-0.4.3-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.3-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.3-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.3-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.3-cp38-abi3-macosx_11_0_arm64.whl (2.5 MB view details)

Uploaded CPython 3.8+ macOS 11.0+ ARM64

pyreqwest_impersonate-0.4.3-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.3.tar.gz.

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.4.3.tar.gz
Algorithm Hash digest
SHA256 094dbab3c5aa3f5e20b86f9bb8258056f80041699819988eefa9c7f9882d1a71
MD5 d8d8e7db5b430f75c450011aec9a4e09
BLAKE2b-256 f83a9485bfe6ce4985100c36ad8971a6e3021044c9a68837e4eab2351139a1ca

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.4.3-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 46b4ba74844a3350c5ffacb5f8bf3efae87613113baf7e6a6489e7fc1b00f19b
MD5 2e814aa225e3f91f09aaa557598782e4
BLAKE2b-256 43a931b1839c800f46a92a13f63fe33baffe990a15efe49ebdac8e78fe5a6be1

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.4.3-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9aa413bb315916fd30b800e5d9f314298b4c9dfaf0f01d66f172536c967157ca
MD5 0b87dc621497a61d1379a7ff7a7c1cc2
BLAKE2b-256 d3ff932dd5db2003c0a609c740f8670acf66971fd0699164b0e44d25e2967629

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.4.3-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 511607047347e6c15993d42a43782be027567ec741a9543d5c220b08e8ea97c4
MD5 8fe6a060e588e7cc8897259bb9ec2a62
BLAKE2b-256 1049423a88f71e1c22a1a9712e9329b629a5726fef170ec6eb968c9f2aaf5d41

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.4.3-cp38-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 129fe8966f7676c86443a3dde1187671ba7a9028f7d60d1a9cdef2dd1931d9e9
MD5 3930219ab72dc79d39eb7322d9fe4488
BLAKE2b-256 53fbffca85912310154d1a97944f572c83b1ad644b06fea22593ee52b7ec40cd

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.4.3-cp38-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f9f7d07e181b7485292cd52cea368b9c1726a6e5233288779d12479e1e413fc2
MD5 a5398747c312d9c15141088a0d834bce
BLAKE2b-256 7df54adbbb3408c19267c0b39c8e65d90944eab47dd3418035de4ccc8f284a24

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.4.3-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ad4bf9d6a5393ae08396c7daae269bb50f2a6b0479956d6862c8f2a2cb5e499b
MD5 8248216ac0f9cd2c9235ef091e19bff8
BLAKE2b-256 1d1a6ed487b4fef96e8efc17218a2b5dc5028dace9c9b5cb255081b9412f6699

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.4.3-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d6383c7f4254005424106165f0d90f2b66424349c70c40c25172808dbb2af015
MD5 34a5a0d89f6d53eaf4a21dcdee2c0f86
BLAKE2b-256 f87404b373a3cde06622d0a430a9fc0b138e72df5827764a4e89d299743af93a

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