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

🪞PRIMP

🪞PRIMP = Python Requests IMPersonate

The fastest python HTTP client that can impersonate web browsers.
Provides precompiled wheels:

  • 🐧 linux: amd64, aarch64, armv7 (⚠️aarch64 and armv7 builds are manylinux_2_34 compatible - ubuntu>=22.04, debian>=12);
  • 🐧 musllinux: amd64, aarch64;
  • 🪟 windows: amd64;
  • 🍏 macos: amd64, aarch64.

Table of Contents

Installation

pip install -U primp

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[str, str| None] | None): Username and password for basic authentication. Default is None.
        auth_bearer (str | None): Bearer token for authentication. Default is None.
        params (dict[str, str] | None): Default query parameters to include in all requests. Default is None.
        headers (dict[str, str] | None): Default headers to send with requests. If `impersonate` is set, this will be ignored.
        cookies (dict[str, str] | None): - Map of cookies to send with requests as the `Cookie` header.
        timeout (float | None): HTTP request timeout in seconds. Default is 30.
        cookie_store (bool | None): Enable a persistent cookie store. Received cookies will be preserved and included
            in additional requests. Default is True.
        referer (bool | None): Enable or disable automatic setting of the `Referer` header. Default is True.
        proxy (str | None): Proxy URL for HTTP requests. Example: "socks5://127.0.0.1:9150". Default is None.
        impersonate (str | None): Entity to impersonate. Example: "chrome_124". Default is None.
            Chrome: "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","chrome_127","chrome_128","chrome_129","chrome_130",
                "chrome_131"
            Safari: "safari_ios_16.5","safari_ios_17.2","safari_ios_17.4.1","safari_ios_18.1.1",
                "safari_15.3","safari_15.5","safari_15.6.1","safari_16","safari_16.5","safari_17.0",
                "safari_17.2.1","safari_17.4.1","safari_17.5","safari_18","safari_18.2","safari_ipad_18"
            OkHttp: "okhttp_3.9","okhttp_3.11","okhttp_3.13","okhttp_3.14","okhttp_4.9","okhttp_4.10","okhttp_5"
            Edge: "edge_101","edge_122","edge_127","edge_131"
            Firefox: "firefox_109","firefox_117","firefox_128","firefox_133"
        follow_redirects (bool | None): Whether to follow redirects. Default is True.
        max_redirects (int | None): Maximum redirects to follow. Default 20. Applies if `follow_redirects` is True.
        verify (bool | None): Verify SSL certificates. Default is True.
        ca_cert_file (str | None): Path to CA certificate store. Default is None.
        https_only` (bool | None): Restrict the Client to be used with HTTPS only requests. Default is `false`.
        http2_only` (bool | None): If true - use only HTTP/2; if false - use only HTTP/1. Default is `false`.

    """

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: dict[str, str] | None = None,
    headers: dict[str, str] | None = None,
    cookies: dict[str, str] | None = None,
    auth: tuple[str, str| None] | None = None,
    auth_bearer: str | None = None,
    timeout: float | None = 30,
):
    """Performs a GET request to the specified URL.

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

    """
def post(
    url: str,
    params: dict[str, str] | None = None,
    headers: dict[str, str] | None = None,
    cookies: dict[str, str] | None = None,
    content: bytes | None = None,
    data: dict[str, Any] | None = None,
    json: Any | None = None,
    files: dict[str, str] | None = None,
    auth: tuple[str, str| None] | None = None,
    auth_bearer: str | None = None,
    timeout: float | None = 30,
):
    """Performs a POST request to the specified URL.

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

    """

Response object

resp.content
resp.cookies
resp.encoding
resp.headers
resp.json()
resp.status_code
resp.text
resp.text_markdown  # html is converted to markdown text
resp.text_plain  # html is converted to plain text
resp.text_rich  # html is converted to rich text
resp.url

Devices

  • Chrome: chrome_100chrome_101chrome_104chrome_105chrome_106chrome_107chrome_108chrome_109chrome_114chrome_116chrome_117chrome_118chrome_119chrome_120chrome_123chrome_124chrome_126chrome_127chrome_128chrome_129chrome_130chrome_131

  • Edge: edge_101edge_122edge_127, edge_131

  • Safari: safari_ios_17.2safari_ios_17.4.1safari_ios_16.5safari_ios_18.1.1, safari_15.3safari_15.5safari_15.6.1safari_16safari_16.5safari_17.0safari_17.2.1safari_17.4.1safari_17.5safari_18safari_18.2, safari_ipad_18

  • OkHttp: okhttp_3.9okhttp_3.11okhttp_3.13okhttp_3.14okhttp_4.9okhttp_4.10okhttp_5

  • Firefox: firefox_109, firefox_117, firefox_128, firefox_133

Examples

import primp

# Impersonate
client = primp.Client(impersonate="chrome_131")  # chrome_131

# 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': '/home/root/file1.txt', 'file2': 'home/root/file2.txt'}
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 or env var PRIMP_PROXY
resp = primp.Client(proxy="http://127.0.0.1:8080").get("https://tls.peet.ws/api/all")
print(resp.json())
export PRIMP_PROXY="socks5://127.0.0.1:1080"
resp = primp.Client().get("https://tls.peet.ws/api/all")
print(resp.json())

# Using custom CA certificate store: env var PRIMP_CA_BUNDLE
#(Primp built with the Mozilla's latest trusted root certificates, so maybe it's not necessary)
resp = primp.Client(ca_cert_file="/cert/cacert.pem").get("https://tls.peet.ws/api/all")
print(resp.json())
resp = primp.Client(ca_cert_file=certifi.where()).get("https://tls.peet.ws/api/all")
print(resp.json())
export PRIMP_CA_BUNDLE="/home/user/Downloads/cert.pem"
resp = primp.Client().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:
# primp.get() | primp.head() | primp.options() | primp.delete() | primp.post() | primp.patch() | primp.put()
# These functions can accept the `impersonate` parameter:
resp = primp.get("https://httpbin.org/anything", impersonate="chrome_131")
print(r.text)

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

primp-0.10.0.tar.gz (84.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

primp-0.10.0-cp38-abi3-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.8+Windows x86-64

primp-0.10.0-cp38-abi3-musllinux_1_2_x86_64.whl (3.6 MB view details)

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

primp-0.10.0-cp38-abi3-musllinux_1_2_aarch64.whl (3.4 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

primp-0.10.0-cp38-abi3-manylinux_2_34_armv7l.whl (3.0 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.34+ ARMv7l

primp-0.10.0-cp38-abi3-manylinux_2_34_aarch64.whl (3.2 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.34+ ARM64

primp-0.10.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

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

primp-0.10.0-cp38-abi3-macosx_11_0_arm64.whl (2.9 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

primp-0.10.0-cp38-abi3-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file primp-0.10.0.tar.gz.

File metadata

  • Download URL: primp-0.10.0.tar.gz
  • Upload date:
  • Size: 84.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.1

File hashes

Hashes for primp-0.10.0.tar.gz
Algorithm Hash digest
SHA256 93142590a5a1958240ee5b74faaf2f55185ed499ccaabc622d71cb0cc8a47a0b
MD5 f26d5c16622026d27bd96dc8c569d99e
BLAKE2b-256 bb8953593df582f3bb35ad5e1a96cb00246c8b6f8b7f116253b9542c8d8c44b9

See more details on using hashes here.

File details

Details for the file primp-0.10.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: primp-0.10.0-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.1

File hashes

Hashes for primp-0.10.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7fe94c3164c2efffff08f7f54c018ac445112961b3ce4f4f499315ba0a9d1ef3
MD5 5684bb81a441dd2cc7f120d658ac8453
BLAKE2b-256 70cc8dd693b9e2577690e86fb589478e8788df2920859e04743800eb7d02213c

See more details on using hashes here.

File details

Details for the file primp-0.10.0-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for primp-0.10.0-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a27c5d997c37bf8237963c11e376eaa66e7eccee39164e3e259a1c3767c304d6
MD5 7df3432121e524b2e53e73b3ce961054
BLAKE2b-256 f59f2b6c0322e33b8ee88489e5eac8f5e7dfe4a53cf75cc43cd6e712e76597e0

See more details on using hashes here.

File details

Details for the file primp-0.10.0-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for primp-0.10.0-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 dc875cc9a733fe3e6344a37f2b5888e0a9605bb37807fc3009f3b03786408f34
MD5 ee549f6439181691be998f119a80a06e
BLAKE2b-256 9b07c42bc5772e5f1655139d7a2b72f141f8a1fa9686684af50c7aab3d944840

See more details on using hashes here.

File details

Details for the file primp-0.10.0-cp38-abi3-manylinux_2_34_armv7l.whl.

File metadata

File hashes

Hashes for primp-0.10.0-cp38-abi3-manylinux_2_34_armv7l.whl
Algorithm Hash digest
SHA256 b859336d9a35669b68a29c5d8f050e0dca380452dabf6c9667bb8599f010d164
MD5 85420f78aa4149e47408481997586583
BLAKE2b-256 4bbc2ce42b5024931c2178999f526a0d6654285e95c178ed5f1c35e3e16ef9bb

See more details on using hashes here.

File details

Details for the file primp-0.10.0-cp38-abi3-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for primp-0.10.0-cp38-abi3-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 8e711cfa019fa9bdc0cba4d5d596f319c884a4329e505bd73e92eee0b024061a
MD5 7030bf9378a31d71ff26b6ac48cbc000
BLAKE2b-256 763920c100140827f0e82e8c3c68284be3292b8345dd5bb7dd5886cd08a2f984

See more details on using hashes here.

File details

Details for the file primp-0.10.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for primp-0.10.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a959e9a83cff0ae7a85a02cc183e4db636f69ff41dddb7c4e32f997924923417
MD5 7e7b0665712b8c39c2218902d866771d
BLAKE2b-256 2656dae7ba34f6f41402b1e0a8c17640fa5b44c06012d5d07d69399da2db5cea

See more details on using hashes here.

File details

Details for the file primp-0.10.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for primp-0.10.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0128453cce81552f7aa6ac2bf9b8741b7816cdb2d10536e62c77daaf6483b9af
MD5 8206ab62f9dcc7b63cfbf2a629b4a417
BLAKE2b-256 84157fedf1280f04c17fb06095694403d27134758b70bf508948a796ed668f06

See more details on using hashes here.

File details

Details for the file primp-0.10.0-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for primp-0.10.0-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7a91a089bf2962b5b56c8d83d09535eb81cf55b53c09d83208b9e5a715cf2c17
MD5 2752a5792456f2908d1131e214789c2b
BLAKE2b-256 70efecfbcea6a136ef758ba3f5644dc4d06df506f669e9381d52fa09b0952de7

See more details on using hashes here.

Supported by

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