Skip to main content

libcurl ffi bindings for Python, with impersonation support.

Project description

curl_cffi

PyPI Downloads PyPI - Python Version PyPI version Generic badge Generic badge

Documentation

Python binding for curl-impersonate fork via cffi. For commercial support, visit impersonate.pro.

curl_cffi is the most popular Python binding for curl. Unlike other pure python http clients like httpx or requests, curl_cffi can impersonate browsers' TLS/JA3 and HTTP/2 fingerprints. If you are blocked by some website for no obvious reason, you can give curl_cffi a try.

Python 3.9 is the minimum supported version since v0.10.

Recall.ai - API for meeting recordings

Recall.ai

If you’re looking for a meeting recording API, consider checking out Recall.ai, an API that records Zoom, Google Meet, Microsoft Teams, in-person meetings, and more.

Residential Proxies

Thordata

Thordata: A reliable and cost-effective proxy service provider. One-click collection of public network data, providing enterprises and developers with stable, efficient, and compliant global proxy IP services. Register for a free trial of residential proxies and receive 2000 free SERP API calls.

Sponsors

Maintenance of this project is made possible by all the contributors and sponsors. If you'd like to sponsor this project and have your avatar or company logo appear below click here. 💖


Bypass Cloudflare with API

Yes Captcha!

Yescaptcha is a proxy service that bypasses Cloudflare and uses the API interface to obtain verified cookies (e.g. cf_clearance). Click here to register: https://yescaptcha.com/i/stfnIO


TLS fingerprinting alone isn't enough for modern bot protection. Hyper Solutions provides the missing piece - API endpoints that generate valid antibot tokens for:

Akamai • DataDome • Kasada • Incapsula

No browser automation. Just simple API calls that return the exact cookies and headers these systems require.

🚀 Get Your API Key | 📖 Docs | 💬 Discord


Features

  • Supports JA3/TLS and http2 fingerprints impersonation, including recent browsers and custom fingerprints.
  • Much faster than requests/httpx, on par with aiohttp/pycurl, see benchmarks.
  • Mimics the requests API, no need to learn another one.
  • Pre-compiled, so you don't have to compile on your machine.
  • Supports asyncio with proxy rotation on each request.
  • Supports http 2.0 & 3.0, which requests does not.
  • Supports websocket.
  • MIT licensed.
requests aiohttp httpx pycurl curl_cffi
http/2
http/3 ☑️1 2
sync
async
websocket
fingerprints
speed 🐇 🐇🐇 🐇 🐇🐇 🐇🐇

Notes:

  1. For pycurl, you need an http/3 enabled libcurl to make it work, while curl_cffi packages libcurl-impersonate inside Python wheels.
  2. Since v0.11.4.

Install

pip install curl_cffi --upgrade

This should work on Linux, macOS and Windows out of the box. If it does not work on you platform, you may need to compile and install curl-impersonate first and set some environment variables like LD_LIBRARY_PATH.

To install beta releases:

pip install curl_cffi --upgrade --pre

To install unstable version from GitHub:

git clone https://github.com/lexiforest/curl_cffi/
cd curl_cffi
make preprocess
pip install .

On macOS, you may need to install the following dependencies:

brew install zstd nghttp2

Usage

curl_cffi comes with a low-level curl API and a high-level requests-like API.

requests-like

import curl_cffi

# Notice the impersonate parameter
r = curl_cffi.get("https://tls.browserleaks.com/json", impersonate="chrome")

print(r.json())
# output: {..., "ja3n_hash": "aa56c057ad164ec4fdcb7a5a283be9fc", ...}
# the js3n fingerprint should be the same as target browser

# To keep using the latest browser version as `curl_cffi` updates,
# simply set impersonate="chrome" without specifying a version.
# Other similar values are: "safari" and "safari_ios"
r = curl_cffi.get("https://tls.browserleaks.com/json", impersonate="chrome")

# Randomly choose a browser version based on current market share in real world
# from: https://caniuse.com/usage-table
# NOTE: this is a pro feature.
r = curl_cffi.get("https://example.com", impersonate="realworld")

# To pin a specific version, use version numbers together.
r = curl_cffi.get("https://tls.browserleaks.com/json", impersonate="chrome124")

# To impersonate other than browsers, bring your own ja3/akamai strings
# See examples directory for details.
r = curl_cffi.get("https://tls.browserleaks.com/json", ja3=..., akamai=...)

# http/socks proxies are supported
proxies = {"https": "http://localhost:3128"}
r = curl_cffi.get("https://tls.browserleaks.com/json", impersonate="chrome", proxies=proxies)

proxies = {"https": "socks://localhost:3128"}
r = curl_cffi.get("https://tls.browserleaks.com/json", impersonate="chrome", proxies=proxies)

Sessions

s = curl_cffi.Session()

# httpbin is a http test website, this endpoint makes the server set cookies
s.get("https://httpbin.org/cookies/set/foo/bar")
print(s.cookies)
# <Cookies[<Cookie foo=bar for httpbin.org />]>

# retrieve cookies again to verify
r = s.get("https://httpbin.org/cookies")
print(r.json())
# {'cookies': {'foo': 'bar'}}

Supported impersonate browsers

curl_cffi supports the same browser versions as supported by my fork of curl-impersonate:

Open source version of curl_cffi includes versions whose fingerprints differ from previous versions. If you see a version, e.g. chrome135, were skipped, you can simply impersonate it with your own headers and the previous version.

If you don't want to look up the headers etc, by yourself, consider buying commercial support from impersonate.pro, we have comprehensive browser fingerprints database for almost all the browser versions on various platforms.

If you are trying to impersonate a target other than a browser, use ja3=... and akamai=... to specify your own customized fingerprints. See the docs on impersonation for details.

Browser Open Source Pro version
Chrome chrome99, chrome100, chrome101, chrome104, chrome107, chrome110, chrome116[1], chrome119[1], chrome120[1], chrome123[3], chrome124[3], chrome131[4], chrome133a[5][6], chrome136[6] chrome132, chrome134, chrome135
Chrome Android chrome99_android, chrome131_android [4] chrome132_android, chrome133_android, chrome134_android, chrome135_android
Chrome iOS N/A coming soon
Safari [7] safari153 [2], safari155 [2], safari170 [1], safari180 [4], safari184 [6], safari260 [8] coming soon
Safari iOS [7] safari172_ios[1], safari180_ios[4], safari184_ios [6], safari260_ios [8] coming soon
Firefox firefox133[5], firefox135[7] coming soon
Firefox Android N/A firefox135_android
Tor tor145 [7] coming soon
Edge edge99, edge101 edge133, edge135
Opera N/A coming soon
Brave N/A coming soon

Notes:

  1. Added in version 0.6.0.
  2. Fixed in version 0.6.0, previous http2 fingerprints were not correct.
  3. Added in version 0.7.0.
  4. Added in version 0.8.0.
  5. Added in version 0.9.0.
  6. The version postfix -a(e.g. chrome133a) means that this is an alternative version, i.e. the fingerprint has not been officially updated by browser, but has been observed because of A/B testing.
  7. Added in version 0.10.0.
  8. Added in version 0.11.0.
  9. Since 0.11.0, the format safari184_ios is preferred over safari18_4_ios, both are supported, but the latter is quite confusing and hard to parse.
  10. Added in 0.12.0.

Asyncio

from curl_cffi import AsyncSession

async with AsyncSession() as s:
    r = await s.get("https://example.com")

More concurrency:

import asyncio
from curl_cffi import AsyncSession

urls = [
    "https://google.com/",
    "https://facebook.com/",
    "https://twitter.com/",
]

async with AsyncSession() as s:
    tasks = []
    for url in urls:
        task = s.get(url)
        tasks.append(task)
    results = await asyncio.gather(*tasks)

For low-level APIs, Scrapy integration and other advanced topics, see the docs for more details.

WebSockets

from curl_cffi import WebSocket

def on_message(ws: WebSocket, message: str | bytes):
    print(message)

ws = WebSocket(on_message=on_message)
ws.run_forever("wss://api.gemini.com/v1/marketdata/BTCUSD")

Asyncio WebSockets

import asyncio
from curl_cffi import AsyncSession

async with AsyncSession() as s:
    ws = await s.ws_connect("wss://echo.websocket.org")
    await asyncio.gather(*[ws.send_str("Hello, World!") for _ in range(10)])
    await ws.flush()
    async for message in ws:
        print(message)
    await ws.close()

Ecosystem

Acknowledgement

  • Originally forked from multippt/python_curl_cffi, which is under the MIT license.
  • Headers/Cookies files are copied from httpx, which is under the BSD license.
  • Asyncio support is inspired by Tornado's curl http client.
  • The synchronous WebSocket API is inspired by websocket_client.
  • The asynchronous WebSocket API is inspired by aiohttp.

Contributing

When submitting an PR, please use a different branch other than main and check the "Allow edits by maintainers" box, so I can update your PR with lint or style fixes. Thanks!

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

curl_cffi-0.14.0.tar.gz (162.6 kB view details)

Uploaded Source

Built Distributions

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

curl_cffi-0.14.0-cp39-abi3-win_arm64.whl (1.4 MB view details)

Uploaded CPython 3.9+Windows ARM64

curl_cffi-0.14.0-cp39-abi3-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.9+Windows x86-64

curl_cffi-0.14.0-cp39-abi3-musllinux_1_2_x86_64.whl (9.5 MB view details)

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

curl_cffi-0.14.0-cp39-abi3-musllinux_1_2_aarch64.whl (9.1 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

curl_cffi-0.14.0-cp39-abi3-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl (8.0 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.34+ riscv64manylinux: glibc 2.39+ riscv64

curl_cffi-0.14.0-cp39-abi3-manylinux_2_28_i686.whl (7.8 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ i686

curl_cffi-0.14.0-cp39-abi3-manylinux_2_28_armv7l.manylinux_2_31_armv7l.whl (8.0 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARMv7lmanylinux: glibc 2.31+ ARMv7l

curl_cffi-0.14.0-cp39-abi3-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl (8.7 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.26+ x86-64manylinux: glibc 2.28+ x86-64

curl_cffi-0.14.0-cp39-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (8.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

curl_cffi-0.14.0-cp39-abi3-macosx_15_0_x86_64.whl (5.8 MB view details)

Uploaded CPython 3.9+macOS 15.0+ x86-64

curl_cffi-0.14.0-cp39-abi3-macosx_14_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.9+macOS 14.0+ ARM64

File details

Details for the file curl_cffi-0.14.0.tar.gz.

File metadata

  • Download URL: curl_cffi-0.14.0.tar.gz
  • Upload date:
  • Size: 162.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for curl_cffi-0.14.0.tar.gz
Algorithm Hash digest
SHA256 5ffbc82e59f05008ec08ea432f0e535418823cda44178ee518906a54f27a5f0f
MD5 efddbe3d093a2c8e156172ec9bc980a8
BLAKE2b-256 9bc90067d9a25ed4592b022d4558157fcdb6e123516083700786d38091688767

See more details on using hashes here.

File details

Details for the file curl_cffi-0.14.0-cp39-abi3-win_arm64.whl.

File metadata

  • Download URL: curl_cffi-0.14.0-cp39-abi3-win_arm64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.9+, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for curl_cffi-0.14.0-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 2eed50a969201605c863c4c31269dfc3e0da52916086ac54553cfa353022425c
MD5 cb2b11bef99108a80f8bc825956168fc
BLAKE2b-256 5c7cd2ba86b0b3e1e2830bd94163d047de122c69a8df03c5c7c36326c456ad82

See more details on using hashes here.

File details

Details for the file curl_cffi-0.14.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: curl_cffi-0.14.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for curl_cffi-0.14.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6e503f9a103f6ae7acfb3890c843b53ec030785a22ae7682a22cc43afb94123e
MD5 90591c215df8e100bd5d7140a4c04138
BLAKE2b-256 a27778900e9b0833066d2274bda75cba426fdb4cef7fbf6a4f6a6ca447607bec

See more details on using hashes here.

File details

Details for the file curl_cffi-0.14.0-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for curl_cffi-0.14.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 58ebf02de64ee5c95613209ddacb014c2d2f86298d7080c0a1c12ed876ee0690
MD5 6d78415780fada3b7cb19661ad1bfa4c
BLAKE2b-256 7503a942d7119d3e8911094d157598ae0169b1c6ca1bd3f27d7991b279bcc45b

See more details on using hashes here.

File details

Details for the file curl_cffi-0.14.0-cp39-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for curl_cffi-0.14.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 03f21ade2d72978c2bb8670e9b6de5260e2755092b02d94b70b906813662998d
MD5 53d9d1a7e89a65c0727147d46cd3a021
BLAKE2b-256 237ccca39c0ed4e1772613d3cba13091c0e9d3b89365e84b9bf9838259a3cd8f

See more details on using hashes here.

File details

Details for the file curl_cffi-0.14.0-cp39-abi3-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl.

File metadata

File hashes

Hashes for curl_cffi-0.14.0-cp39-abi3-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl
Algorithm Hash digest
SHA256 e7176f2c2d22b542e3cf261072a81deb018cfa7688930f95dddef215caddb469
MD5 803d707eeb909e67e510517d5c25975e
BLAKE2b-256 5176d6f7bb76c2d12811aa7ff16f5e17b678abdd1b357b9a8ac56310ceccabd5

See more details on using hashes here.

File details

Details for the file curl_cffi-0.14.0-cp39-abi3-manylinux_2_28_i686.whl.

File metadata

File hashes

Hashes for curl_cffi-0.14.0-cp39-abi3-manylinux_2_28_i686.whl
Algorithm Hash digest
SHA256 1439fbef3500fb723333c826adf0efb0e2e5065a703fb5eccce637a2250db34a
MD5 12c1b215087affd161d0e28317ea1053
BLAKE2b-256 fb10ff64249e516b103cb762e0a9dca3ee0f04cf25e2a1d5d9838e0f1273d071

See more details on using hashes here.

File details

Details for the file curl_cffi-0.14.0-cp39-abi3-manylinux_2_28_armv7l.manylinux_2_31_armv7l.whl.

File metadata

File hashes

Hashes for curl_cffi-0.14.0-cp39-abi3-manylinux_2_28_armv7l.manylinux_2_31_armv7l.whl
Algorithm Hash digest
SHA256 b158c41a25388690dd0d40b5bc38d1e0f512135f17fdb8029868cbc1993d2e5b
MD5 cefd1a04311424c455e21aa9411bc75d
BLAKE2b-256 f2ae6256995b18c75e6ef76b30753a5109e786813aa79088b27c8eabb1ef85c9

See more details on using hashes here.

File details

Details for the file curl_cffi-0.14.0-cp39-abi3-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for curl_cffi-0.14.0-cp39-abi3-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 060fe2c99c41d3cb7f894de318ddf4b0301b08dca70453d769bd4e74b36b8483
MD5 c8541bbd34fadb5d5979ac35e7f94ae0
BLAKE2b-256 7cd2ce907c9b37b5caf76ac08db40cc4ce3d9f94c5500db68a195af3513eacbc

See more details on using hashes here.

File details

Details for the file curl_cffi-0.14.0-cp39-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for curl_cffi-0.14.0-cp39-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c42e8fa3c667db9ccd2e696ee47adcd3cd5b0838d7282f3fc45f6c0ef3cfdfa7
MD5 a7bff04df273ada3ca96cb44fba66b81
BLAKE2b-256 e207a238dd062b7841b8caa2fa8a359eb997147ff3161288f0dd46654d898b4d

See more details on using hashes here.

File details

Details for the file curl_cffi-0.14.0-cp39-abi3-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for curl_cffi-0.14.0-cp39-abi3-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 5945478cd28ad7dfb5c54473bcfb6743ee1d66554d57951fdf8fc0e7d8cf4e45
MD5 71d1bb2edaddc1630d5282282386ebbc
BLAKE2b-256 baa30419bd48fce5b145cb6a2344c6ac17efa588f5b0061f212c88e0723da026

See more details on using hashes here.

File details

Details for the file curl_cffi-0.14.0-cp39-abi3-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for curl_cffi-0.14.0-cp39-abi3-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e35e89c6a69872f9749d6d5fda642ed4fc159619329e99d577d0104c9aad5893
MD5 1555e7f7875055e6881ffe6a190f7f7a
BLAKE2b-256 aaf00f21e9688eaac85e705537b3a87a5588d0cefb2f09d83e83e0e8be93aa99

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