httpx transport for curl_cffi (python bindings for curl-impersonate)
Maintained. Last release 4 days ago, commits in 1 of the last 26 weeks. Weaker on commit activity and contributor spread.
pip install httpx-curl-cffiREADME as published on PyPI with version 0.1.7.
httpx-curl-cffi
httpx transport for curl_cffi - python binding for curl-impersonate fork
Unlike other pure python http clients
like httpx (with native transport) or requests,
curl_cffi can impersonate browser's TLS/JA3 and HTTP/2 fingerprints.
Browser simulation implemented by low-level customizations
and usage of native browser TLS libraries
(BoringSSL for Chrome, nss for Firefox) -
which is impossible to achieve with Python's OpenSSL binding.
If you are blocked by some website for no obvious reason,
you can give curl_cffi a try.
Install
pip install httpx-curl-cffi
Usage
from httpx import Client, AsyncClient
from httpx_curl_cffi import CurlTransport, AsyncCurlTransport, CurlOpt
client = Client(transport=CurlTransport(impersonate="chrome", default_headers=True))
client.get("https://tools.scrapfly.io/api/fp/ja3")
async_client = AsyncClient(
transport=AsyncCurlTransport(
impersonate="chrome",
default_headers=True,
# required for parallel requests, see curl_cffi issues below
curl_options={CurlOpt.FRESH_CONNECT: True},
)
)
httpx2
httpx2 is supported along with httpx
(installed as dependency) without any changes, the same transports are
accepted by httpx2.Client and httpx2.AsyncClient (by type checkers too):
pip install httpx-curl-cffi[httpx2]
The httpx2 extra installs httpx2[brotli,zstd] - decoders of encodings
accepted by impersonated browsers
(e.g. chrome sends Accept-Encoding: gzip, deflate, br, zstd).
from httpx2 import Client
from httpx_curl_cffi import CurlTransport
client = Client(transport=CurlTransport(impersonate="chrome", default_headers=True))
Responses and errors are created of the request's module, e.g. raised for . httpx aliased by is supported as well.