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 Linux(x86_64/aarch64), macOS(Intel), Windows(amd64). 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
# proxies are supported
proxies = {"https": "http://localhost:3128"}
r = requests.get("https://tls.browserleaks.com/json", impersonate="chrome101", proxies=proxies)
For a list of supported impersonation versions, please check the curl-impersonate repo.
Alternatively, use 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/
for 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
.
Trouble Shooting
Pyinstaller ModuleNotFoundError: No module named '_cffi_backend'
You need to tell pyinstaller to pack cffi and data files inside the package:
pyinstaller -F .\example.py --hidden-import=_cffi_backend --collect-all curl_cffi
Using https proxy, error: OPENSSL_internal:WRONG_VERSION_NUMBER
You are messing up https-over-http proxy and https-over-https proxy, for most cases, you
should change {"https": "https://localhost:3128"}
to {"https": "http://localhost:3128"}
.
Note the protocol in the url for https proxy is http
not https
.
See this issue for a detailed explaination
Current Status
This implementation is very hacky now, but it works for most common systems.
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(Intel) and Windows.
- Support musllinux(alpine) and macOS(Apple Silicon) bdist by building from source.
- Exclude the curl headers from source, download them when building.
- Update curl header files and constants via scripts.
- Implement
requests.Session/httpx.Session
. - Create ABI3 wheels to reduce package size and build time.
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.5-pp39-pypy39_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cae8cf770ba442c0084866ebe618e35e3c5d750e6256e3830d8b107abf4512c0 |
|
MD5 | 84f581f3254c65043728d1c0f6f7cef6 |
|
BLAKE2b-256 | f86fac98ef63babc4b16d980facb2a53656daa4e1983b8d4063452a181fd7dd9 |
Hashes for curl_cffi-0.2.5-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc584024be400411efccfac21f674eb2e053c4bf49bd3b9617b2ac7861e55e3c |
|
MD5 | 6ea098850e81c0e6f50af15d6aa02ea2 |
|
BLAKE2b-256 | 25385b4918a28d710d580c17568e78466772035ffd980fcb658f4ef8eed7f629 |
Hashes for curl_cffi-0.2.5-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5d7314dc4c14ce3cba5c7a5cc703e859f956790bb1d6d4897fc91c61f15a0c3 |
|
MD5 | c5390ab92ac1c5a03ddb605ffbbbfd74 |
|
BLAKE2b-256 | 744705c7d6c8ed06e6c341db00f0d044ca464af192fe16a5fe7f93eddb63777f |
Hashes for curl_cffi-0.2.5-pp39-pypy39_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa64f1a6f352f1a6e1ba0bf9cf8a9b650402dccdbb7920fae7da1105aff90ff8 |
|
MD5 | fc06d4d2591429942dda27c147d10ccd |
|
BLAKE2b-256 | 99db3ea5137f7ada11ac650c2cbefb8be1eb2e642fce80f45b2d879e1116b1b5 |
Hashes for curl_cffi-0.2.5-pp38-pypy38_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc3452784d8d1d39a5a1537a43f40706e2286175a0d97e9097cb61a8ea599da4 |
|
MD5 | bd0791e093cee4020f849d40d342f676 |
|
BLAKE2b-256 | 3aa261185ae3174a16f1f77c6d72573ed89126b90516a5e0bd92ff7f5737dd5d |
Hashes for curl_cffi-0.2.5-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14eea0118df5b5815ada8d31aca4318cf89b36ba2dc7be3abb4b4210455dd11c |
|
MD5 | b144723dd5192bfd712fbed4a5880567 |
|
BLAKE2b-256 | 229c5d0aa7dfaae640d4feae7099e9283c48011b8298f9ef1e443738c3a93682 |
Hashes for curl_cffi-0.2.5-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 775e1829d49d0382ead8811a6755c8031658bb47cc1c587cedf14307406f84a2 |
|
MD5 | a2226b3f4125e59e78f53383f4bf07ea |
|
BLAKE2b-256 | 15b3e24fae4eccb944ba04af1b2485304f169f1664cba762a4d752880a416170 |
Hashes for curl_cffi-0.2.5-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 001e5203afd9f2e806b4f87d91d99bed369e7a1f4cff2c129dda710971622c5a |
|
MD5 | 4513c261d334e2c0d9fca6b25d49c5de |
|
BLAKE2b-256 | 2d3c62f417c236481429136bf7d4141f13ddaead58e773bfa4badfadb1145117 |
Hashes for curl_cffi-0.2.5-pp37-pypy37_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35540d4e86b0ee98cca967f055234263ee933ce489cff3ced35f8ef2c656b489 |
|
MD5 | fe0f4f8b713a00f6190be81ee7f6c9cc |
|
BLAKE2b-256 | 8ccdd9b25a67ea02457f8ba6d19ee7bb075eb577f59fa9e9956e26c4f356db8f |
Hashes for curl_cffi-0.2.5-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2e36cb64f1ec7e81bd9b00a8adc3fb7a0dc21c98fbc74535135b5c2b0fe7532 |
|
MD5 | e9f3b7e5df7678250d3b6d098cea75b8 |
|
BLAKE2b-256 | 8957f28668e5835fcbf6fbaee99b09df710932aabb1be6e23e8b89a5de148f7b |
Hashes for curl_cffi-0.2.5-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72b00a6527d9afb1d73fb4c1e9bdfaa3cbf6674e60a3f54a235b32249fbb1515 |
|
MD5 | a001b8e41c3797d0ac4a554fb048753a |
|
BLAKE2b-256 | 3003b4992312e07a10bc5b11a5c9aae0c719f17fd193ff5aba63a945c3fd9759 |
Hashes for curl_cffi-0.2.5-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45e3d9e67c5cce84550285730ffa8341dff8ec27b43d080f0370d9fb8de06fdd |
|
MD5 | 782514a473eaaf9c4829c51ce4f26cd2 |
|
BLAKE2b-256 | 310b028cfa6ef89762cf607c04a5fdead419da26a891246db8b90561cf479362 |
Hashes for curl_cffi-0.2.5-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c369815eaca834d2c68dae5d7c5f03ec670b534694eee44b627a9e7b1c67159d |
|
MD5 | 5c66d7ab78d90856479b2ab009de824e |
|
BLAKE2b-256 | c7affcbc01df6c224617f57c3824d0423096e36f874b7c1394dca654a1e98e87 |
Hashes for curl_cffi-0.2.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67b44277b8aa6889c8f9c78b7245d531ae814a8653ef11f0d05ce2ff24c83ea3 |
|
MD5 | e69c794d8a4d13305ca9030337c0cfe0 |
|
BLAKE2b-256 | 2c852f91f51281508277b68301b8cc13879dc3dd2a78e9dd6aebe1afe60cc84f |
Hashes for curl_cffi-0.2.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23f035abec6564b99ef7a2b27780641383e2a92f30a4467c87bf75ac5453bde3 |
|
MD5 | 24d6cf2036e28f655749c8cc8ec848ff |
|
BLAKE2b-256 | e403b521c8b596a998c7964ad8b38917b1dd658b5c72dcd9e8a3902a02c2ec4a |
Hashes for curl_cffi-0.2.5-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 928c3d4c5977b8b63bf7b791e4e943cdc80221ab93c5a13f81dd4782bfc894b6 |
|
MD5 | 0989a3a7a0f14e22ad094fea7b46ad2e |
|
BLAKE2b-256 | cdf68e0746fe2b916a42171582ea1102ca701844783071e78ab8455953a4c4e3 |
Hashes for curl_cffi-0.2.5-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c71a8df590e682624acb459755140f74b3443bbbe49c9f61dcdbfd6eb77edbb |
|
MD5 | d606fce3c12f4e010354dbd312e4f0ad |
|
BLAKE2b-256 | 721bd27caac4cde741b2ceab95dc9bfe5ba20ec5a4dbbc93918aba5887dcf09f |
Hashes for curl_cffi-0.2.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74c0eb316bfefe9b5b82e8e4962d1494827cea1c6e77be0f7f9baeea7fadb722 |
|
MD5 | 988b1acb7b48a47d908bc26735508e68 |
|
BLAKE2b-256 | 71e4ccd3d519d5b885d478d4e016c658b55493eec7c723e268929b5b20b1c208 |
Hashes for curl_cffi-0.2.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7d2d34d6b0c789c32214d9099a84f505b67a2e172d1d89b670e86b347929b1c |
|
MD5 | cad72b91d3a5301c4ba132551061d86f |
|
BLAKE2b-256 | 4870523951d49ea913afa1dfe0513b8d5226cb6e4d3b47a718f5a563c112e2a2 |
Hashes for curl_cffi-0.2.5-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 605c6baf7f8b01a9896b8389fc7f6520b46c0848b49ab237b3d08545f73dc631 |
|
MD5 | 2c3d717e79c1935a51fcd6c6d43fac7e |
|
BLAKE2b-256 | 82d668657cca523af2c3e2c253cfbd738d847ebb33cb77a14be45a118715ae69 |
Hashes for curl_cffi-0.2.5-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36bc64c2a4b4c9f0a13dffe06e1974e6d5ceda28fccb0f11c423cf7a64671295 |
|
MD5 | c5da3835c8206e20e90f8f3d77bd4297 |
|
BLAKE2b-256 | 81ab0e0aef54bc8852a631e35fdaa77961084d407fd3f48480533ccb56b14b69 |
Hashes for curl_cffi-0.2.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4c4955018244c512c4767513f68628c31afc99855d7b3edb899e0ced956af7f |
|
MD5 | c81ba1638a3b50badf5f537e285efc2d |
|
BLAKE2b-256 | 929823856dd2dd0a9e54823680f08634737394a9154a0cd8e096d5528b6055c4 |
Hashes for curl_cffi-0.2.5-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c0d220af7bed3fbfe56e53f09accfe19908982e536996b2257884f2a5d09f20 |
|
MD5 | 478573c6b9bfe54aa204fea939540510 |
|
BLAKE2b-256 | 69e87dd2baffedea0f318625119623cc98cc89a23bdaeb56f057da78885bbb5b |
Hashes for curl_cffi-0.2.5-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f05df29fc4620f45390437f514560471df048468c33ac16997c41fcf6635802 |
|
MD5 | dce838bc43ba2b5e31fba8d6330b2794 |
|
BLAKE2b-256 | d39a41e7c3df6a0e9ea9a6a6ca0092b53b6b1e15d180c15a31bfd2820a7d3ef6 |
Hashes for curl_cffi-0.2.5-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a75a0abe361bd0620fe1efb38d6be60e7eaddf9eaaee3c4d05b7eeb6fd94ad0 |
|
MD5 | 421d9719ccf354ccb78af0703df532d1 |
|
BLAKE2b-256 | d8079531e328bd9a55756c6447aa510e035691dcee6800aadccef2757072a07f |
Hashes for curl_cffi-0.2.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e02b6264da69559f40655f7c47199b7174fcff32c8f4260c3805ffd34def4d7 |
|
MD5 | 3577553bb9a785d5d693db1e69cd2cd4 |
|
BLAKE2b-256 | 9fa558c6e22a2758a5a59dc3b80b90683893cf404a24f84254458e095690a34b |
Hashes for curl_cffi-0.2.5-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f36af9fafba5848c11a058041837d364b53afe748e8ecdf50855ef89a4a59759 |
|
MD5 | 4660f8bdf0d4e08185408163b632d6d2 |
|
BLAKE2b-256 | 0409c7c15d14bcb57f2e9da072e1979c8863b708f47a6a75acbb05471269234e |
Hashes for curl_cffi-0.2.5-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c5d2403858db33eb12e356fd457d5c1f7dc11cb9d819f639f8ac5e823ee04c9 |
|
MD5 | 34830877ee317d7315bccfd91d6b225b |
|
BLAKE2b-256 | 5faa8f294564b167d4c625d70de418f8d4ca23c8653389736fca416cbc7bbfa3 |
Hashes for curl_cffi-0.2.5-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffc273b8b8e86c716315b99e590bca73d4baa94d49afa21d2671ae1fc28e22b6 |
|
MD5 | d27c61513f30deccc153a0a3e6fec177 |
|
BLAKE2b-256 | 8ec32f4de8c399bf14855308f27c7a1ac43fe1c0f7398862d0b9e6e6f390773a |
Hashes for curl_cffi-0.2.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 531abb6be6b3852740b67600badfdb3c253f912d9e26dc4d10b7f2224cbbee78 |
|
MD5 | 533bdfd4852b8020f79629fbafacfbd9 |
|
BLAKE2b-256 | a5ea52c7790b4c2f3cd820c4002e50fdd981d07dbd86686d25c5101bf8b437e5 |
Hashes for curl_cffi-0.2.5-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1bbc3169c36c8ecbf77721fb4939952f7cff5b2c3a2af27bb5d429b272d045f |
|
MD5 | 5c597bcf290b565bd414dd177a096578 |
|
BLAKE2b-256 | 9b044dd4500d6a5d238a59c51037c6e92705335bee7495356f2ca9f616d5ed1b |
Hashes for curl_cffi-0.2.5-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5f1d56a04da89c0ea204c0193de3cac24f00264204a7970e0a1544bd72766b8 |
|
MD5 | e605e757306734f3307a805460f26dda |
|
BLAKE2b-256 | 6ee54371de4d0909e8296783a3d5281f4e7afecd62a851735744bea3082cc7a9 |