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.
🏁 Check the benchmark for more details.

Provides precompiled wheels:

  • Linux: amd64, aarch64, armv7.
  • Windows: amd64.
  • MacOS: amd64, aarch64.

Table of Contents

Installation

pip install -U pyreqwest_impersonate

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. This feature is crucial for avoiding detection as a bot and potential blocking by websites.
  • Thread-safe: The Client is designed to be thread-safe, allowing it to be safely used in multithreaded environments.
  • High Performance: The attributes of the Response object are executed in Rust, which is known for its high performance. This ensures that operations like accessing headers, decoding text, or parsing JSON are very fast.
  • Lazy Execution: All attributes of the Response object are executed lazily. This means that the actual computation or data retrieval happens only when you access the attribute, not when the Response object is created.
  • Automatic Character Encoding Detection: The Response object intelligently detects the character encoding of the response body from the "Content-Type" header. If the encoding is not specified, it defaults to "UTF-8".

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
resp = pri.get("https://httpbin.org/anything") # Default Client does not impersonate a browser
resp = pri.Client(impersonate="chrome_123").get("https://httpbin.org/anything")  

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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.8+ Windows x86-64

pyreqwest_impersonate-0.3.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

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

pyreqwest_impersonate-0.3.2-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.5 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ARMv7l

pyreqwest_impersonate-0.3.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.8+ macOS 11.0+ ARM64

pyreqwest_impersonate-0.3.2-cp38-abi3-macosx_10_12_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.8+ macOS 10.12+ x86-64

File details

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

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.3.2.tar.gz
Algorithm Hash digest
SHA256 e6fba2f947c44e34c44405f7918834fb951ffdf12a884b7a4e17791b5ed20dd4
MD5 0b08ea4c169c3a03d305d1969fecd31a
BLAKE2b-256 036bb3eba49b5da88a3522aacf492893691a7bbf291d3896fddd4b55cdd773be

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.3.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1a15d83b47e94714aff9f650f6a1c047385969f1f4266da3a3e471bc348e0497
MD5 974a95fc63e48b0097d6b000ce03a6c4
BLAKE2b-256 e1eabab459882d2d3e16b259e5cc945c53b35aae1ef170d7a74c9809644a09d4

See more details on using hashes here.

Provenance

File details

Details for the file pyreqwest_impersonate-0.3.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.3.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f5bf31b52f7a6b8e4e791441bd9ade5e51d87789bd1919f79360d64ab701268e
MD5 3a617a472fe336ffd64f1ab3ba32c6ed
BLAKE2b-256 6245c72512e735f7f69c6b4b2b4bfdca42b025f13c503858f63e3260984343d5

See more details on using hashes here.

Provenance

File details

Details for the file pyreqwest_impersonate-0.3.2-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.3.2-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 2dc07de2263094da13bb43df19ed5da75bb79b5faa9328e1e032b6df1e9f6352
MD5 ac416497cde369fcda3a87f13f53fb6e
BLAKE2b-256 1e7e991493708e696d419fb375c263599090dfac9fbe18f50c2522d25d340fbc

See more details on using hashes here.

Provenance

File details

Details for the file pyreqwest_impersonate-0.3.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.3.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 beae84c1faaf0690d9301d73c23c80f5c2a6ec0d7a93bb5e112f64843159b657
MD5 5d8b7d613d786984a0c71ffd3672644c
BLAKE2b-256 fbcca23bc833dec9cd719e37b78fe3bfcd9554e8480c0b3f0e314be0e9edc712

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.3.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9e3746207290d81380170d3f2668e597052b54596791c4ec7c81929a6dd2e929
MD5 cbaf8e1d1bc957890af12b4fe90e7c56
BLAKE2b-256 9c606f9bcf059089ea8f9f7b09b1a591ff69cfebc57823bd15996e6317539b32

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pyreqwest_impersonate-0.3.2-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5be526c79b4a7d939da0b592645516511ebd8c733e7038eb62a2e856b356d586
MD5 bbcb1188815f440628852d779dcf0f6e
BLAKE2b-256 7e32f4ea0d9da86249e311f5d5fdb9ea60b9636f51fef6d7fdf2b6e55b8f962b

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