HTTP client that can impersonate web browsers, mimicking their headers and `TLS/JA3/JA4/HTTP2` fingerprints
Project description
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_ios_17.2","safari_15.3","safari_15.5","safari_15.6.1","safari_16","safari_16.5","safari_17.2.1",
"safari_17.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_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file pyreqwest_impersonate-0.4.4.tar.gz
.
File metadata
- Download URL: pyreqwest_impersonate-0.4.4.tar.gz
- Upload date:
- Size: 129.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31c9e258ab2a15c0a5facd3d4e64b16754164b2f82df0f18d15a4a6797b03a8d |
|
MD5 | e4b78c21953c693dad72942de0261958 |
|
BLAKE2b-256 | 8b7354275cf21a673e2f46b3fa3f59780967b7469240ebae74fbc34305e16413 |
Provenance
File details
Details for the file pyreqwest_impersonate-0.4.4-cp38-abi3-win_amd64.whl
.
File metadata
- Download URL: pyreqwest_impersonate-0.4.4-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82efb56976d64035178a942a93d163e15c1b81bd7ccef707b56da83f737d36f4 |
|
MD5 | 481a045cffdd9135dc8a4e9f95dda7d7 |
|
BLAKE2b-256 | 5e11298365785787f443f283d52b7bf3be6c4c3b1a186988d6967525210fafc7 |
Provenance
File details
Details for the file pyreqwest_impersonate-0.4.4-cp38-abi3-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: pyreqwest_impersonate-0.4.4-cp38-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.8+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89bd4ac8fe34a338a4ef4de42efe0ae5c4711efe81da041c59e029302571dc16 |
|
MD5 | 219abe7ea2d6c0888ff0652f603105fe |
|
BLAKE2b-256 | fcbc71d7879bf6197bbed2c3276f306ca20c9ee5b3ce98b1cae8a53f43744c22 |
Provenance
File details
Details for the file pyreqwest_impersonate-0.4.4-cp38-abi3-musllinux_1_2_aarch64.whl
.
File metadata
- Download URL: pyreqwest_impersonate-0.4.4-cp38-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.8+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0a718adcbe699701423b2f5306167c13b2e12e7dc890c5583b47f0ddadfb5e5 |
|
MD5 | 382a30cbf2650dee9caa5c36860f3541 |
|
BLAKE2b-256 | b009201d797aa4efe56fe61c10f1065520d63ca1c083f1518f2408b68bfb1fba |
Provenance
File details
Details for the file pyreqwest_impersonate-0.4.4-cp38-abi3-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: pyreqwest_impersonate-0.4.4-cp38-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.8+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5646946a8e1174d354ba914993758b10c5a5ebece67800bc4ec2189fae071fe6 |
|
MD5 | a00f8ee3f8ed8ac289b695eac290eb96 |
|
BLAKE2b-256 | 3dc83efc771a6196f18e572121312ad363de26122144cd2f012b9c4559e2da6d |
Provenance
File details
Details for the file pyreqwest_impersonate-0.4.4-cp38-abi3-manylinux_2_28_aarch64.whl
.
File metadata
- Download URL: pyreqwest_impersonate-0.4.4-cp38-abi3-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.8+, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1bf9659bbfcb09cf1f961eb6ac08aaeb5888c6fb274e4c7ff89a9231f05a55c |
|
MD5 | 6f007b62ad7442d22f0c5db97a4e96f2 |
|
BLAKE2b-256 | 6ea464c184a45b02b508d0b590d0acc27236b9ef2a67c20d09a84c8a1fc48b39 |
Provenance
File details
Details for the file pyreqwest_impersonate-0.4.4-cp38-abi3-macosx_11_0_arm64.whl
.
File metadata
- Download URL: pyreqwest_impersonate-0.4.4-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84b6db2fe301d73e5b3630634622360fce6c24890927ae29661eb9760ddec748 |
|
MD5 | 243bde7853d8ca8ee723fd3a37d3e96b |
|
BLAKE2b-256 | 6df7b55bc6754ada10926a3ff8f98e5ecd2914477009dac5d764bf70a0dae497 |
Provenance
File details
Details for the file pyreqwest_impersonate-0.4.4-cp38-abi3-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: pyreqwest_impersonate-0.4.4-cp38-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.8+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5766ff3aff12cfd43c606e6b625a78ddcd67e86e9037e0659e8a06e65f8ad165 |
|
MD5 | 14e64a79d1e5a3071603176fcda45f9e |
|
BLAKE2b-256 | 39eecbfba1f6e0b94987f513b25ea7457102172abb2e166e63c273ba7f08bc20 |