Skip to main content

Curl Adapter

PyPI Downloads

A module that plugs directly into the Python requests library and replaces the default urllib3 HTTP adapter with cURL, equipped with TLS fingerprint-changing capabilities.

Why?

Specifically, this module is meant to be used with the "curl impersonate" python bindings (lexiforest/curl_cffi), in order to send HTTP requests with custom, browser-like TLS & HTTP/2 fingerprints for bypassing sites that detect and block normal python requests (such as Cloudflare for example).

Note Even though curl_cffi already has an API that *mimicks* the requests library, it comes with some compatibility issues (e.g. response.raw not available, response.history, differences in headers, cookies, json, etc.).

With curl-adapter, instead of copying and mimicking the requests library API, the low level HTTP adapter is changed with a custom crafted one, and everything else is exactly the same (even the exceptions are mapped).

With a single switch you can enable/disable curl for your requests, without needing to worry about changing the way you normally work with requests.

Though, if you're looking for async support or websockets, you should definitely checkout the curl_cffi instead, since by default, the requests library is only sync.

You can also use curl-adapter with pycurl.

Additionally, this module is optimized for seamless integration with Gevent.

Installation

pip install curl-adapter --upgrade --ignore-installed

Usage

Basic example:

import requests
from curl_adapter import CurlCffiAdapter

session = requests.Session()
session.mount("http://", CurlCffiAdapter())
session.mount("https://", CurlCffiAdapter())

# just use requests session like you normally would
session.get("https://example.com")

Configuring curl impersonate options:

import requests
from curl_adapter import CurlCffiAdapter

curl_cffi_adapter = CurlCffiAdapter(
    # This is the default
    impersonate_browser_type="chrome", 

    # Optionally set additional options
    tls_configuration_options={
        "ja3_str": "...",
        "akamai_str": "...",
        "extra_fp": ExtraFingerprints(...),
    }
)

# you can use 'with ...' for just making a single request
with requests.Session() as s:
    s.mount("http://", curl_cffi_adapter)
    s.mount("https://", curl_cffi_adapter)

    s.get("https://example.com")

Using it with pycurl:

import requests
from curl_adapter import PyCurlAdapter

with requests.Session() as s:
    s.mount("http://", PyCurlAdapter())
    s.mount("https://", PyCurlAdapter())

    s.get("https://example.com")

More

You can get extra information from the curl response info:

import requests
from curl_adapter import PyCurlAdapter, get_curl_info

with requests.Session() as s:
    s.mount("http://", PyCurlAdapter())
    s.mount("https://", PyCurlAdapter())

    response = s.get("https://example.com")

    body = response.text

    curl_info = get_curl_info(response)

    print(
        curl_info
    )

Returns a simple dict:

{
    'local_ip':'192.168.1.1',
    'local_port':19219,
    'primary_ip':'142.250.200.142',
    'primary_port':443,
    'request_size':0,
    'request_body_size':0,
    'response_header_size':418,
    'ssl_verify_result':0,
    'proxy_ssl_verify_result':0,
    'starttransfer_time':171335,
    'connect_time':33231,
    'appconnect_time':47274,
    'pretransfer_time':47378,
    'namelookup_time':1025,
    'has_used_proxy':0,
    'speed_download':52081115, # only available after the body has been read
    'speed_upload':0, # only available after the body has been read
    'response_body_size':519958376, # only available after the body has been read
    'total_time':9983626, # only available after the body has been read
}

Note that some cURL information fields are only availabe after the body stream has been fully consumed, so keep that in mind when using stream=True option.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

curl_adapter-1.2.2.tar.gz (25.9 kB view details)

Uploaded Source

Built Distribution

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

curl_adapter-1.2.2-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file curl_adapter-1.2.2.tar.gz.

File metadata

  • Download URL: curl_adapter-1.2.2.tar.gz
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for curl_adapter-1.2.2.tar.gz
Algorithm Hash digest
SHA256 4e76546b5f038e06df93f9f1f8e3c2a96ab388a41aa959eb349ed4fdd71280c8
MD5 4c3c5b15d1bb998137c059e5abb89999
BLAKE2b-256 b4bf6ea3d6b8c6ca989d6ac736a5f6a423d0ffb5ced5c2055838a757c020d718

See more details on using hashes here.

File details

Details for the file curl_adapter-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: curl_adapter-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 30.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for curl_adapter-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e86735b68255ebaaa32017612d85c6b60b1ff0fbdc63c368d432d51028915904
MD5 a459b5dc2c013d0de97c801bd79071a5
BLAKE2b-256 06dc6ed8dac01edbf814c9c19920182dd2f08741d72a49887e99dd352d938039

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.2.2 This release

2 files

1.2.1

2 files

1.2.0

2 files

1.1.0

2 files

1.0.0.post3

2 files

1.0.0.post2

2 files

1.0.0.post1

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page