libcurl ffi bindings for Python, with impersonation support
Project description
curl_cffi
Python binding for curl-impersonate via CFFI.
Unlike other pure python http clients like httpx
or requests
, this package can
impersonate browsers' TLS signatures or JA3 fingerprints. If you are blocked by some
website for no obvious reason, you can give this package a try.
Install
pip install --upgrade curl_cffi
This should work for most Linux systems. If it does not work, you may need to compile and install curl-impersonate first.
Usage
requests/httpx
-like API:
from curl_cffi import requests
# Notice the impersonate parameter
r = requests.get("https://tls.browserleaks.com/json", impersonate="chrome101")
print(r.json())
# output: {'ja3_hash': '53ff64ddf993ca882b70e1c82af5da49'
# the fingerprint should be the same as target browser
Or, the low-level curl-like API:
from curl_cffi import Curl, CurlOpt
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("chrome101")
c.perform()
c.close()
body = buffer.getvalue()
print(body.decode())
See example.py
or tests/
from more examples.
API
Requests: almost the same as requests.
Curl object:
setopt(CurlOpt, value)
: Sets curl options as incurl_easy_setopt
perform()
: Performs curl request, as incurl_easy_perform
getinfo(CurlInfo)
: Gets information in response after curl perform, as incurl_easy_getinfo
close()
: Closes and cleans up the curl object, as incurl_easy_cleanup
Enum values to be used with setopt
and getinfo
can be accessed from CurlOpt
and CurlInfo
.
Current Status
This repo is very early stage for now, the pypi package only works on Linux, not macOS or Windows. If you wish to use it on macOS or Windows, you need to clone it and the curl-impersonate repo, and then compile them by yourself.
When people installing other python curl bindings, like pycurl
, they often face
compiling issues or OpenSSL issues, so I really hope that this package can be distributed
as a compiled binary package, uses would be able to use it by a simple pip install
, no
more compile errors.
For now, I just download the pre-compiled libcurl-impersonate
from github and build a
bdist wheel, which is a binary package format used by PyPI, and upload it. However, the
right way is to download curl and curl-impersonate sources on our side and compile them
all together.
Help wanted!
TODOs:
- write docs.
- binary package for macOS and Windows.
- Support musllinux(alpine) bdist by building curl-impersonate from source.
- Update curl header files and constants via scripts.
- Implement
requests.Session/httpx.Session
.
Acknowledgement
This package was originally forked from https://github.com/multippt/python_curl_cffi
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
Built Distributions
Hashes for curl_cffi-0.2.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ce9a53e01e2d6259c10fe4fb5e86b4330b837cde24f3edc550c4b8dc00c2ca4 |
|
MD5 | 1f243e08c42893f151584cc5c40acd4f |
|
BLAKE2b-256 | f0a995b2a1695f215ef55009334d505f7667905f15ff04a018d0b9dbb4a735a6 |
Hashes for curl_cffi-0.2.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eaf2a338f1908c386e50c813a68450eb1c568ea4e9c245c0207f58072827ccf6 |
|
MD5 | 991171e395262cd293d0298f3e9752de |
|
BLAKE2b-256 | d46b65122ab893ea2be8f5157da75f4fc4a790ae32c0d7d729d7eb9da7c6bd17 |
Hashes for curl_cffi-0.2.1-pp39-pypy39_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bae6a6e774bf4dd9194f16c91932c209c90f9a5dedac9a90febbab4020f3ef93 |
|
MD5 | 34af25768e463ad90fca7ff61b99f1a4 |
|
BLAKE2b-256 | 86f900cb8a53da35df2a260293e214d975b5e1e45c598755aec4e2405088bd04 |
Hashes for curl_cffi-0.2.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb57f4f5b5018ecc95387f25e35d6b479b98c3a6e03220ff2f1c011527d16443 |
|
MD5 | 62359d5923ababb0b9fe4ceb3c554ac2 |
|
BLAKE2b-256 | 2810e87e50c4fcd402bd637ef9d5d2840ad1606ee6913c3fcf6bbdb0357b91d8 |
Hashes for curl_cffi-0.2.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2a86ac1edf1affd77c1845c28c56784fa29da49995b76d51152cfa8a6a96d46 |
|
MD5 | 858550b8516eeef5fb0c9a8f07562b7b |
|
BLAKE2b-256 | ff53cf3b2b6451151fb7c59cc52a13cfc8e0f7aea9049c43e03c8f2a094b0333 |
Hashes for curl_cffi-0.2.1-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3725bba7ede60b73a452716a4774407711bb78fa1bcd3570db5e82a108c2fff |
|
MD5 | 7fea021e8210da06eda3999274fc2cac |
|
BLAKE2b-256 | ea9b9461968b00ffac26f8c574570733590b6bc19f55bf03428822f335be4fac |
Hashes for curl_cffi-0.2.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab5d707cb320c0456e9a5daabd6ed83d218b2a76c404021ac2bfded9aac85ce9 |
|
MD5 | 9a943a636661c1f0ac474c805bba4e47 |
|
BLAKE2b-256 | 516ef686a726ac4d7ac5136a951e5463897dc462d3423c1eb6822cab81ccc164 |
Hashes for curl_cffi-0.2.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bd654433c6bd528529164a3b0eb9030e4d486e554c476e7ca69f27ca5966e1b |
|
MD5 | 61fdf8e3883f655b5d9945da454b6168 |
|
BLAKE2b-256 | 04481a89b91984aac11ab9b5e8ea8509941cda89b6fd1a2945dc290ebac421a7 |
Hashes for curl_cffi-0.2.1-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 815abe41f42197d44eed305947aa87a1557d0df61ed13703cf196230a9c2048c |
|
MD5 | 2e01badfc208e2f8ebdc15cbc0e66ffe |
|
BLAKE2b-256 | 94b8670460e85d7ff9743e38263a9056c940827180f30b8ee51aa5536410e828 |
Hashes for curl_cffi-0.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da571737df089bc0145da6d7eb2f39eba4c5ed6170508f2836c718c00142cdba |
|
MD5 | 39e04cc8ec39289440c96d94e02a746f |
|
BLAKE2b-256 | 645fc5682d2143055b44ce99df696033961c44569c7fdbe06609692d0ee9de3f |
Hashes for curl_cffi-0.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fd7a57945d3998d74155b1e559106463ec263aebdb8adeeebd274c9aa689096 |
|
MD5 | 68229cdb95b14a5ab0449c818fef570b |
|
BLAKE2b-256 | 75e649b8b1f773aef5cf0ae3e588c844ed69adf7fc560b2d16ad359b5ef7571e |
Hashes for curl_cffi-0.2.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11a893b974ba0f34325a45350974a63521b5f2e9c6778df9470c9851b28f1c1c |
|
MD5 | d4761216caea6b041de3f17b56dc8f61 |
|
BLAKE2b-256 | 9a23e717d2bb196c19325f6e4b7d8cb2943bb8ae6688fae8cce4f283e0a56ff4 |
Hashes for curl_cffi-0.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71895294f7e83f253f918c7c5defdcfb406af422bc93c930481bc50080936edf |
|
MD5 | e85a54dfb3b1959c069fea7f04651b14 |
|
BLAKE2b-256 | 9c1bd5388d7cde5bc927fec4a21c23184c81217dcaef153691da73c18e4e9e39 |
Hashes for curl_cffi-0.2.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d0be495b0023c965f957f7a8e9b0ccca131942065ef4ef46c0857cc92bf8666 |
|
MD5 | 7aeb9ac38d9da4c9d4f5d7320c9e13e4 |
|
BLAKE2b-256 | 281b3a755ed13d5d35b2a8922e7c6780a1f7ceafa1b9bd037f3b1baf04780e62 |
Hashes for curl_cffi-0.2.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8bd104cd32180ee5c06f2abd53a83095439b31018382bf7b4e76054db359c35 |
|
MD5 | 0f0bae74f95b1d58fc149b80f53bdbfb |
|
BLAKE2b-256 | 0b25b70de1f65b2134bd53cd486de8cc484149f5c3d80ee3cdab6169bd3f8ba2 |
Hashes for curl_cffi-0.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24a12231f5711fc9a1372b34a6c3eade765e725551ca0f93d94f63ed0454e855 |
|
MD5 | 054c6997ba6b9c06676799e7f0425f29 |
|
BLAKE2b-256 | f5e8468ebb73ebae5b29df80fb12fa8e2b0c5e73e0f716b9fa3d26ec26413227 |
Hashes for curl_cffi-0.2.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08a9b634c869727dfe68c7994d516dab0300f1d9d6ac140579df6474f688d38c |
|
MD5 | e3189a48874818e71d74bc80fffcea79 |
|
BLAKE2b-256 | c964dd9ad809b1e6d7a80360861ed892c0b1d9e944e8d100f24a7c4f0d9f0dea |
Hashes for curl_cffi-0.2.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e98f8ed5232580018376fba818a35256fe961a1353c3154de5e791139513286 |
|
MD5 | 434972f783e37ab3f39917ef89a6b8a9 |
|
BLAKE2b-256 | 5f77a5f53f78458bf4f7d1cb8ddb524b2297f09c7555424f995753f0ff6f9889 |
Hashes for curl_cffi-0.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec295c1e32d5cdb83db4da6971b2f558b465bf0d865a100f87d8c9427ebcbac5 |
|
MD5 | ab7dce097c178cc93798ba4baba2a1a5 |
|
BLAKE2b-256 | 0b52c7dcd54f83e2a16ba4f2037ac7e103569c176f4c960e13421302963705f7 |
Hashes for curl_cffi-0.2.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c79ecb8812404239986a7cde385dd992f5dea28551b8e02aef5bd2081f361048 |
|
MD5 | 597b17d7531c526b227bcf6de7e30a38 |
|
BLAKE2b-256 | 5fcbb56b28ecbf5089d6bc7b802a26bc4538037c0d17942a54d7d6cce67a3f23 |
Hashes for curl_cffi-0.2.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec65d0622d4ad9978521b919b27561f9b0d85e91dd8da0939d33f003509f7590 |
|
MD5 | f6fe72e16f56b97080dee1cefb76d0e3 |
|
BLAKE2b-256 | 583e4693d9ed0207617903232b05482085e37b6705c828b75e224ea6b5fe65ab |
Hashes for curl_cffi-0.2.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb14012d6579306287ffa2df690282b29e6f3943c4f5f2255ab13c63e33ab1ee |
|
MD5 | 57804e24555c5e2eabf4959e38ab4cab |
|
BLAKE2b-256 | f80a5c5cb7b1137cd3fe6bd4e21919bd9f7e3f0a80ec8511040d1fc1f5315cf5 |
Hashes for curl_cffi-0.2.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e8b5f411c34304f39ad8fab593af06adf5ff7eddd8eae423cec7da1b6496476 |
|
MD5 | 0074996b342c42bb18b5efbdbc15633e |
|
BLAKE2b-256 | f0baf1d65c94cb209ca66f7c6ad39bc78b8815688cc0661ea2ac9c022859219f |
Hashes for curl_cffi-0.2.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7858b04108ff1a5c6108a3077b7ac3844ddba8e98707073090ac7dddb469a749 |
|
MD5 | 0298acdf0aaa3958b8743dad370936a3 |
|
BLAKE2b-256 | 37f7ad7c80495abbfd23e4ac4d19a0180f2b64af584ac0b5c7da570c6b0e482b |