Skip to main content

Ultra fast python binding for curl-impersonate via cython, with impersonation support.

Project description

cycurl

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

Documentation

Python binding for curl-impersonate fork via cython.

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

Only Python 3.8 and above are supported. Python 3.7 has reached its end of life.


Scrapfly.io

Scrapfly is an enterprise-grade solution providing Web Scraping API that aims to simplify the scraping process by managing everything: real browser rendering, rotating proxies, and fingerprints (TLS, HTTP, browser) to bypass all major anti-bots. Scrapfly also unlocks the observability by providing an analytical dashboard and measuring the success rate/block rate in detail.

Scrapfly is a good solution if you are looking for a cloud-managed solution for curl_cffi. If you are managing TLS/HTTP fingerprint by yourself with curl_cffi, they also maintain a curl to python converter.


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


Scrape Ninja

ScrapeNinja is a web scraping API with two engines: fast, with high performance and TLS fingerprint; and slower with a real browser under the hood.

ScrapeNinja handles headless browsers, proxies, timeouts, retries, and helps with data extraction, so you can just get the data in JSON. Rotating proxies are available out of the box on all subscription plans.


Features

  • Supports JA3/TLS and http2 fingerprints impersonation, including recent browsers and custome fingerprints.
  • Much faster than requests/httpx, on par with aiohttp/pycurl, see benchmarks.
  • Mimics 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, which requests does not.
  • Supports websocket.
requests aiohttp httpx pycurl curl_cffi cycurl
http2
sync
async
websocket
fingerprints
speed 🐇 🐇🐇 🐇 🐇🐇 🐇🐇 🐇🐇

Install

pip install cycurl --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 cycurl --upgrade --pre

To install unstable version from GitHub:

git clone https://github.com/synodriver/cycurl/
cd cycurl
python setup.py bdist_wheel

Usage

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

requests-like

from cycurl import requests

# Notice the impersonate parameter
r = requests.get("https://tools.scrapfly.io/api/fp/ja3", 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 = requests.get("https://tools.scrapfly.io/api/fp/ja3", impersonate="chrome")

# To pin a specific version, use version numbers together.
r = requests.get("https://tools.scrapfly.io/api/fp/ja3", impersonate="chrome124")

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

# http/socks proxies are supported
proxies = {"https": "http://localhost:3128"}
r = requests.get("https://tools.scrapfly.io/api/fp/ja3", impersonate="chrome", proxies=proxies)

proxies = {"https": "socks://localhost:3128"}
r = requests.get("https://tools.scrapfly.io/api/fp/ja3", impersonate="chrome", proxies=proxies)

Sessions

s = requests.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'}}

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

However, only WebKit-based browsers are supported. Firefox support is tracked in #59.

Browser versions will be added only when their fingerprints change. If you see a version, e.g. chrome122, were skipped, you can simply impersonate it with your own headers and the previous version.

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 impersonatation for details.

  • chrome99
  • chrome100
  • chrome101
  • chrome104
  • chrome107
  • chrome110
  • chrome116 [1]
  • chrome119 [1]
  • chrome120 [1]
  • chrome123 [3]
  • chrome124 [3]
  • chrome99_android
  • edge99
  • edge101
  • safari15_3 [2]
  • safari15_5 [2]
  • safari17_0 [1]
  • safari17_2_ios [1]
  • safari18_0 [4]
  • safari18_0_ios [4]

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.

asyncio

from cycurl.requests import AsyncSession

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

More concurrency:

import asyncio
from cycurl.requests 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)

WebSockets

from cycurl.requests import Session, WebSocket

def on_message(ws: WebSocket, message):
    print(message)

with Session() as s:
    ws = s.ws_connect(
        "wss://api.gemini.com/v1/marketdata/BTCUSD",
        on_message=on_message,
    )
    ws.run_forever()

curl-like

Alternatively, you can use the low-level curl-like API:

from cycurl import Curl, CURLOPT_URL, CURLOPT_WRITEDATA
from io import BytesIO

buffer = BytesIO()
c = Curl()
c.setopt(CURLOPT_URL, b'https://tls.browserleaks.com/json')
c.setopt(CURLOPT_WRITEDATA, buffer)

c.impersonate("chrome110")

c.perform()
c.close()
body = buffer.getvalue()
print(body.decode())

See the docs for more details.

scrapy

If you are using scrapy, check out these middlewares:

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

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 WebSocket API is inspired by websocket_client.

Sponsor

Buy Me A Coffee

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

cycurl-0.8.0b1.tar.gz (50.0 MB view details)

Uploaded Source

Built Distributions

cycurl-0.8.0b1-cp312-cp312-win_amd64.whl (5.6 MB view details)

Uploaded CPython 3.12 Windows x86-64

cycurl-0.8.0b1-cp312-cp312-manylinux2014_x86_64.whl (6.9 MB view details)

Uploaded CPython 3.12

cycurl-0.8.0b1-cp312-cp312-macosx_14_0_arm64.whl (3.5 MB view details)

Uploaded CPython 3.12 macOS 14.0+ ARM64

cycurl-0.8.0b1-cp312-cp312-macosx_12_0_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.12 macOS 12.0+ x86-64

cycurl-0.8.0b1-cp311-cp311-win_amd64.whl (5.6 MB view details)

Uploaded CPython 3.11 Windows x86-64

cycurl-0.8.0b1-cp311-cp311-manylinux2014_x86_64.whl (6.9 MB view details)

Uploaded CPython 3.11

cycurl-0.8.0b1-cp311-cp311-macosx_14_0_arm64.whl (3.5 MB view details)

Uploaded CPython 3.11 macOS 14.0+ ARM64

cycurl-0.8.0b1-cp311-cp311-macosx_12_0_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.11 macOS 12.0+ x86-64

cycurl-0.8.0b1-cp310-cp310-win_amd64.whl (5.6 MB view details)

Uploaded CPython 3.10 Windows x86-64

cycurl-0.8.0b1-cp310-cp310-manylinux2014_x86_64.whl (6.9 MB view details)

Uploaded CPython 3.10

cycurl-0.8.0b1-cp310-cp310-macosx_14_0_arm64.whl (3.5 MB view details)

Uploaded CPython 3.10 macOS 14.0+ ARM64

cycurl-0.8.0b1-cp310-cp310-macosx_12_0_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.10 macOS 12.0+ x86-64

cycurl-0.8.0b1-cp39-cp39-win_amd64.whl (5.6 MB view details)

Uploaded CPython 3.9 Windows x86-64

cycurl-0.8.0b1-cp39-cp39-manylinux2014_x86_64.whl (6.9 MB view details)

Uploaded CPython 3.9

cycurl-0.8.0b1-cp39-cp39-macosx_14_0_arm64.whl (3.5 MB view details)

Uploaded CPython 3.9 macOS 14.0+ ARM64

cycurl-0.8.0b1-cp39-cp39-macosx_12_0_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.9 macOS 12.0+ x86-64

cycurl-0.8.0b1-cp38-cp38-win_amd64.whl (5.6 MB view details)

Uploaded CPython 3.8 Windows x86-64

cycurl-0.8.0b1-cp38-cp38-manylinux2014_x86_64.whl (6.9 MB view details)

Uploaded CPython 3.8

cycurl-0.8.0b1-cp38-cp38-macosx_14_0_arm64.whl (3.5 MB view details)

Uploaded CPython 3.8 macOS 14.0+ ARM64

cycurl-0.8.0b1-cp38-cp38-macosx_12_0_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.8 macOS 12.0+ x86-64

File details

Details for the file cycurl-0.8.0b1.tar.gz.

File metadata

  • Download URL: cycurl-0.8.0b1.tar.gz
  • Upload date:
  • Size: 50.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for cycurl-0.8.0b1.tar.gz
Algorithm Hash digest
SHA256 45996cf3379c7bba81bbe5b0a330a04c1cb593dc032b8970cdaee50c94199da1
MD5 29b952f47bfbaa877ca879dd4b0f3abc
BLAKE2b-256 8033e7d1a086688f268ea62ccfc223b2766d16c81e12a3720ee9e5e670f7a424

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for cycurl-0.8.0b1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 301851659461ea17cebb5030849a92efe75de3730cf196b5f992b7901c1bdb57
MD5 01aa391c877c5a7e6e17541226ab029e
BLAKE2b-256 06668f543dda5efdeaf637693cb1498fb71eb90ed725da391bb5f6adf96ca35f

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp312-cp312-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cycurl-0.8.0b1-cp312-cp312-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 96e4aadd8cce807995885cde01dfa301316b67b147dc7447c149a938458e4bba
MD5 2db863292c218107c76ab5625ddb2eeb
BLAKE2b-256 e21ab7825f6caaa371302803826158228b688084130625ccf81f3cf393cd86c0

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for cycurl-0.8.0b1-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f0bada45474b2462c83fc3ad3908b9fcd1e5e2040f6ee39e8a17d13975abad11
MD5 a96c19f13637ef917bc50130214bbdda
BLAKE2b-256 3b2696df4de22045106cd9e0b335cc183e6045e91fc0323c5449e3a355f45fca

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp312-cp312-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for cycurl-0.8.0b1-cp312-cp312-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 3837c90e2dcf5f2dd140645d7655eee16593c6cc87af233c48b9d3ab9b5138dd
MD5 8f3c70d0e465779fb2c3ea6515be260f
BLAKE2b-256 8819bfadfd9cfa6a02b51e6e17c610aa9f6fe9e28ae8de90fd60e2fff632e54a

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for cycurl-0.8.0b1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ed48cfdfb98b169b0fd799aaa07bfa0a6302cc395f564c52adb860ef07bf5508
MD5 a065c6d5e3728cca68c07b2be41a0419
BLAKE2b-256 00cbc382906a0faf46f3f1b287bdfd9419cd7dbd9d808752c8d5b09c3c731963

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp311-cp311-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cycurl-0.8.0b1-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6d55b7401f88620b5af6137fffb1b8699f28bde5de17bb97d34a651cda53fd97
MD5 54d517561d8093bcfc46224b0cb3d665
BLAKE2b-256 56d48f94336d8adb20fb4ab6a52aa4b1a29199936723b75a27654d63db7fec5d

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for cycurl-0.8.0b1-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 dd00773ba8d2e58314c81ecc19a4e990bc21af41a8bce80b263ccebdedb3b589
MD5 f99cf8e600f4aa821203a388bfc2c2dd
BLAKE2b-256 c754b594a21650b1132c5f189851850cadbf2f0bcfde7280a7251513dcfeed99

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp311-cp311-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for cycurl-0.8.0b1-cp311-cp311-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 99d20d9fff0a69297cd285307867f5f9c5e2e1eb55e58a631eeb93d2e44b9aff
MD5 d31b678d8c5a4c146d61089b2e4e5662
BLAKE2b-256 88189f777f0a268a4f7edb1f8373ee2943bd204176fccda54289e8d559893c6d

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: cycurl-0.8.0b1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 5.6 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for cycurl-0.8.0b1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3521c55dbb4e4f501ae3fcb0d15c7cb215d0c47be7b2a2c0fed8af01c4a08a7d
MD5 a66aa43e9af3b384cfd466c11876ee92
BLAKE2b-256 fe02d5233e620553b9cb9a336e4d41407cadf2551bdec926c9fb74a589b8e72b

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp310-cp310-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cycurl-0.8.0b1-cp310-cp310-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 283ffa522cb93736818eeb20b097c1fae721e3e5787d935d970d0f0b06c19236
MD5 327ae22224cb0a87a0694cee69389d2c
BLAKE2b-256 910bd37be86ff1a9c47af744d9835878b0aa83410d51d207490765b91bb6c37e

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for cycurl-0.8.0b1-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 505fae451e92c6e58e72986ecd17be918a935e364b783f446a8ab2493d746aa0
MD5 0d4aca0854ac956f96d567e8f8bfe783
BLAKE2b-256 34013c378ea24a4a84aa1686e601ce3474092be2164b53fb2bc71fc1c4d0f30a

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp310-cp310-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for cycurl-0.8.0b1-cp310-cp310-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 ab1f7115081bf91537b4757a7e6747812fcded65f4f4e48da80a0793acf1010d
MD5 734223ce1a63ee80a266180e6b564114
BLAKE2b-256 5275cf7b40e48dacdc96e64500d6c7b1df7423e21496b01bab52d7f791d5757f

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: cycurl-0.8.0b1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 5.6 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.13

File hashes

Hashes for cycurl-0.8.0b1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 8b816ac691aee8e4c2b48f6a66a3cd5de2e0b3209c20a427a7465c2c48d3ca5c
MD5 8931cdb590a734e3417643f672ee3c93
BLAKE2b-256 b7f41e0c541b9e694d30b8c78c7076046217a25eb9ed22ced16f189402f4ff9d

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cycurl-0.8.0b1-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fde6245fafa8a27d0c57e68859b15531dd02c1ee17b90ba1e8d81548091c7398
MD5 835a59b48b2ba944951fb39d8d7cc9af
BLAKE2b-256 00f41ae1ab5b69cce0c05d7870771edb7b4f70b40e23681a0d57a2ea904c45a3

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp39-cp39-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for cycurl-0.8.0b1-cp39-cp39-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9a4f7b8ad6765210548a3698a830bc5328839e54ef062eb810225f9b515aa1f7
MD5 c812664898a9dd6d6a7693cf15a78654
BLAKE2b-256 346fd51c16bcbe67fd2c2c183419b6d314e8097fa49c58372a17a9b685eb7af0

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp39-cp39-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for cycurl-0.8.0b1-cp39-cp39-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 0ad963d9ea61e9f585bf9646808b234bdb53188e5b60bdc32fc5ea45ee73295a
MD5 6c41b2ebfa30fd3f27723b4014cabaa9
BLAKE2b-256 0e153680969a6b7cc7538ca95e8d83dd09f638e9c657169261aff04c46fff7e3

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: cycurl-0.8.0b1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 5.6 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for cycurl-0.8.0b1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 d7806c12bfa191052124badd287d3b146195514157023fdfec5752a4bbb4ab25
MD5 707ee1df9bc8aa6c808d9d40a18fb7d6
BLAKE2b-256 f9fd4869cbc7077f7133adf215e54941e3d32e64279ff4ef301515d33025cbe2

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cycurl-0.8.0b1-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 31d12bcb972148a780162b2c2ce28de81b8287e308cb8bb032f405d2ede02711
MD5 04eeb9f226e3c37dd6c9e70348cf3604
BLAKE2b-256 df364790a9c4da311b5d00547a7ed03de661ec5b52901265e6663c45e4d0722b

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp38-cp38-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for cycurl-0.8.0b1-cp38-cp38-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5440ada8992cdbc6ce155a8b66f0f024fb028f86f930a34af86c847c3c597526
MD5 5893bec3c294048fd2824e7fd95012c4
BLAKE2b-256 354758a89ca4ca84ac57649a66c2a1cf39f8d29ee9c2b3e658203c095408b30a

See more details on using hashes here.

File details

Details for the file cycurl-0.8.0b1-cp38-cp38-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for cycurl-0.8.0b1-cp38-cp38-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 050f50ed275120599cb59adf686af0b0df97fb0764cd0768590f16ff7c4a63b9
MD5 b6eaad015317251a79909c655e8ce456
BLAKE2b-256 5a9fd6d7f1cffd8a57807de93fd7118ef010b88402e51ccc7c8bc15e513a33af

See more details on using hashes here.

Supported by

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