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.
Provides precompiled wheels: linux
(amd64, aarch64), windows
(amd64); macos
(amd64, aarch64).
Table of Contents
Installation
pip install -U pyreqwest_impersonate
Benchmark
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.
cookies (dict, optional): - An optional map of cookies to send with requests as the `Cookie` header.
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_107",
"chrome_108","chrome_109","chrome_114","chrome_116","chrome_117","chrome_118","chrome_119",
"chrome_120","chrome_123","chrome_124","chrome_126"
Safari: "safari_ios_16.5","safari_ios_17.2","safari_ios_17.4.1","safari_15.3","safari_15.5","safari_15.6.1",
"safari_16","safari_16.5","safari_17.2.1","safari_17.4.1","safari_17.5"
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 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,
cookies: 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.
cookies (Optional[Dict[str, str]]): - An optional map of cookies to send with requests as the `Cookie` header.
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,
cookies: Optional[Dict[str, str]] = None,
content: Optional[bytes] = None,
data: Optional[Dict[str, str]] = None,
json: Any = None,
files: Optional[Dict[str, bytes]] = 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.
cookies (Optional[Dict[str, str]]): - An optional map of cookies to send with requests as the `Cookie` header.
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, bytes]]): A map of file fields to file contents 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.
"""
Response object
resp.content
resp.cookies
resp.headers
resp.json()
resp.plaintext # html is converted to markdown text
resp.status_code
resp.text
resp.url
Examples
import pyreqwest_impersonate as pri
client = pri.Client(impersonate="chrome_126")
# GET request
resp = client.get("https://tls.peet.ws/api/all")
print(resp.json())
# GET request with passing params and setting timeout
params = {"param1": "value1", "param2": "value2"}
resp = client.post(url="https://httpbin.org/anything", params=params, timeout=10)
print(r.text)
# POST Binary Request Data
content = b"some_data"
resp = client.post(url="https://httpbin.org/anything", content=content)
print(r.text)
# POST Form Encoded Data
data = {"key1": "value1", "key2": "value2"}
resp = client.post(url="https://httpbin.org/anything", data=data)
print(r.text)
# POST JSON Encoded Data
json = {"key1": "value1", "key2": "value2"}
resp = client.post(url="https://httpbin.org/anything", json=json)
print(r.text)
# POST Multipart-Encoded Files
files = {'file1': open('file1.txt', 'rb').read(), 'file2': open('file2.txt', 'rb').read()}
r = client.post("https://httpbin.org/post", files=files)
print(r.text)
# Authentication using user/password
auth = ("user", "password")
resp = client.post(url="https://httpbin.org/anything", auth=auth)
print(r.text)
# Authentication using auth bearer
auth_bearer = "bearerXXXXXXXXXXXXXXXXXXXX"
resp = client.post(url="https://httpbin.org/anything", auth_bearer=auth_bearer)
print(r.text)
# Using proxy
resp = pri.Client(proxy="http://127.0.0.1:8080").get("https://tls.peet.ws/api/all")
print(resp.json())
# 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_126")
print(r.text)
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.5.2.tar.gz
.
File metadata
- Download URL: pyreqwest_impersonate-0.5.2.tar.gz
- Upload date:
- Size: 94.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50a57c4b139788606b311757ddf36efd82ea1c952decea808b4196220bd43803 |
|
MD5 | 0e7485beebb8dd24b3c448bbe945f51a |
|
BLAKE2b-256 | aba3101133a903c60d76d6d89b4af006e085a0f8a6538dc364301a86baaed2e2 |
Provenance
File details
Details for the file pyreqwest_impersonate-0.5.2-cp38-abi3-win_amd64.whl
.
File metadata
- Download URL: pyreqwest_impersonate-0.5.2-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e72b39a64c12a35a1689af558d62c67f94d14310043e404a90550e39ddd4af7c |
|
MD5 | fea018baacd6f841f8491d028b2e281a |
|
BLAKE2b-256 | 56dba3555b77c24a6a3cc6cc23307105fb2587ae1d14c15b705ade2a8643b895 |
Provenance
File details
Details for the file pyreqwest_impersonate-0.5.2-cp38-abi3-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: pyreqwest_impersonate-0.5.2-cp38-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.8+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ce34743e3ce2656ba262a325103b96e1d4f301be5f3dd8cb21ee4eec4c6e1b7 |
|
MD5 | 4dadf877448b159264404f11c2996ba6 |
|
BLAKE2b-256 | eaea3f91c24b6c37967a7f273e9f6071f2f5f80e80395ab0410b226ceb2bb093 |
Provenance
File details
Details for the file pyreqwest_impersonate-0.5.2-cp38-abi3-musllinux_1_2_aarch64.whl
.
File metadata
- Download URL: pyreqwest_impersonate-0.5.2-cp38-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 2.8 MB
- Tags: CPython 3.8+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31db4e6e491868c227a252ef3a8fa8b7accc306e741934f74ad3e6fb096e334c |
|
MD5 | ae4a962f8779eb4559eff960f57fb0ca |
|
BLAKE2b-256 | 9dbac10c40c4402e7c3f624c06caf59a677a754ceda44cb1291873faf53db0f6 |
Provenance
File details
Details for the file pyreqwest_impersonate-0.5.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pyreqwest_impersonate-0.5.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9c78ab908cc10a195ddbfc60c18b205237233f76b4f56c28ebc1afe80210335 |
|
MD5 | 4aa5c7173d185daf129991fee67aa316 |
|
BLAKE2b-256 | cfa3065dd379f1c40f48b58d0f1cdf8161331430c0c9d735643ac50f4734d9cf |
Provenance
File details
Details for the file pyreqwest_impersonate-0.5.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: pyreqwest_impersonate-0.5.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 2.8 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b453ab0a7f30a279151e88bd52449a01931307986d7c2a6a92a699d3ba58b66 |
|
MD5 | 346ea424cf67b6dc8070ef794e343d54 |
|
BLAKE2b-256 | d515df6e597428031e0700f64ac8bd58763472695fdd1411c9e66c198868ab34 |
Provenance
File details
Details for the file pyreqwest_impersonate-0.5.2-cp38-abi3-macosx_11_0_arm64.whl
.
File metadata
- Download URL: pyreqwest_impersonate-0.5.2-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca7fc399a672558de1d50b5beb5a153c7002adbe332edd7a752f1d19c35d7f7f |
|
MD5 | 4e6b1291210aced01d1725d0630617dd |
|
BLAKE2b-256 | 453f0ede32f36f33ae3d7e2df0b85feebac3bada7e8c1cde48ce0bd6b5964a70 |
Provenance
File details
Details for the file pyreqwest_impersonate-0.5.2-cp38-abi3-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: pyreqwest_impersonate-0.5.2-cp38-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.8+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec8c9318190020bad3f12a62aedc5faaa92078c38cf48189e98cd692b82e7c28 |
|
MD5 | 5375cb1dc207dd3c9e65b126fd1653bc |
|
BLAKE2b-256 | a89773a2d354d7d8519c2211f4fa918e0459717276a349f8357bae6b76ff37b7 |