curl-adapter


Namecurl-adapter JSON
Version 1.0.0b2 PyPI version JSON
download
home_pageNone
SummaryA curl HTTP adapter switch for requests library — make browser-like requests with custom TLS fingerprints.
upload_time2025-01-20 21:10:23
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2025 Elis K. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords curl requests adapter tls fingerprint pycurl curl_cffi curl impersonate
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Curl Adapter
A module that plugs straight-in to the python *[requests](https://github.com/psf/requests)* library and replaces the default *urllib3* HTTP adapter with cURL.

## Why?

Specifically, this module is meant to be used with the "curl impersonate" python bindings ([lexiforest/curl_cffi](https://github.com/lexiforest/curl_cffi)), in order to send HTTP requests with custom, browser-like TLS & HTTP/2 fingerprints for bypassing sites that detect and block normal python requests (such as [Cloudflare](https://www.nstbrowser.io/en/blog/how-does-cloudflare-detect-bots) for example).
<details>
  <summary>Note</summary>
Even though <i><a href="https://github.com/lexiforest/curl_cffi">curl_cffi</a></i> already has an API that *mimicks* the <i>requests</i>  library, it comes with some compatibility issues (e.g. response.raw not available, response.history, differences in headers, cookies, json, etc.).
<br><br>
    With curl adapter, instead of copying and mimicking the <i>requests</i> library API, just the low level HTTP adapter is changed, and everything else is exactly the same (even the exceptions). 
<br><br>
With a single switch you can enable/disable curl for your requests, without needing to worry about changing the way you normally work with requests.
<br><br>
Though, if you're looking for async support or websockets, you should definitely checkout the <i>curl_cffi</i> instead, since by default, the requests library is only sync.
</details>
<br>

Additionally, you can even use curl adapter with [pycurl](https://github.com/pycurl/pycurl). 

## Installation
`pip install curl_adapter`

## Usage
Basic example:
```python
import requests
from curl_adapter import CurlCffiAdapter

session = requests.Session()
session.mount("http://", CurlCffiAdapter())
session.mount("https://", CurlCffiAdapter())

# just use requests session like you normally would
session.get("https://example.com")
```

Configuring curl impersonate options:

```python
import requests
from curl_adapter import CurlCffiAdapter

# you can use 'with ...' for just making a single request
with requests.Session() as s:
    s.mount("http://", CurlCffiAdapter(impersonate_browser_type="chrome"))
    s.mount("https://", CurlCffiAdapter(impersonate_browser_type="chrome"))

    s.get("https://example.com")
```

Using it with [pycurl](https://github.com/pycurl/pycurl):

```python
import requests
from curl_adapter import PyCurlAdapter

with requests.Session() as s:
    s.mount("http://", PyCurlAdapter())
    s.mount("https://", PyCurlAdapter())

    s.get("https://example.com")
```

## More
You can get extra information from curl response info:
```python
import requests
from curl_adapter import PyCurlAdapter, CurlInfo

with requests.Session() as s:
    s.mount("http://", PyCurlAdapter())
    s.mount("https://", PyCurlAdapter())

    response = s.get("https://example.com")
    curl_info: CurlInfo = response.get_curl_info()
    print(
        curl_info
    )
```

Returns:
```python
{
    'local_ip': '192.168.1.1', 
    'local_port': 40164,
    'primary_ip': '3.210.94.60', 
    'primary_port': 443, 
    'total_time': 429186, 
    'speed_download': 472, 
    'speed_upload': 0, 
    'size_upload': 0, 
    'request_size': 0, 
    'response_body_size': 203, 
    'response_header_size': 224
}
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "curl-adapter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "curl, requests, adapter, tls fingerprint, pycurl, curl_cffi, curl impersonate",
    "author": null,
    "author_email": "\"Elis K.\" <github@elis.cc>",
    "download_url": "https://files.pythonhosted.org/packages/f8/47/714f81e86a229a8622ea154fe8205ae4fb207d3c688fee78bb51ab0a261f/curl_adapter-1.0.0b2.tar.gz",
    "platform": null,
    "description": "# Curl Adapter\r\nA module that plugs straight-in to the python *[requests](https://github.com/psf/requests)* library and replaces the default *urllib3* HTTP adapter with cURL.\r\n\r\n## Why?\r\n\r\nSpecifically, this module is meant to be used with the \"curl impersonate\" python bindings ([lexiforest/curl_cffi](https://github.com/lexiforest/curl_cffi)), in order to send HTTP requests with custom, browser-like TLS & HTTP/2 fingerprints for bypassing sites that detect and block normal python requests (such as [Cloudflare](https://www.nstbrowser.io/en/blog/how-does-cloudflare-detect-bots) for example).\r\n<details>\r\n  <summary>Note</summary>\r\nEven though <i><a href=\"https://github.com/lexiforest/curl_cffi\">curl_cffi</a></i> already has an API that *mimicks* the <i>requests</i>  library, it comes with some compatibility issues (e.g. response.raw not available, response.history, differences in headers, cookies, json, etc.).\r\n<br><br>\r\n    With curl adapter, instead of copying and mimicking the <i>requests</i> library API, just the low level HTTP adapter is changed, and everything else is exactly the same (even the exceptions). \r\n<br><br>\r\nWith a single switch you can enable/disable curl for your requests, without needing to worry about changing the way you normally work with requests.\r\n<br><br>\r\nThough, if you're looking for async support or websockets, you should definitely checkout the <i>curl_cffi</i> instead, since by default, the requests library is only sync.\r\n</details>\r\n<br>\r\n\r\nAdditionally, you can even use curl adapter with [pycurl](https://github.com/pycurl/pycurl). \r\n\r\n## Installation\r\n`pip install curl_adapter`\r\n\r\n## Usage\r\nBasic example:\r\n```python\r\nimport requests\r\nfrom curl_adapter import CurlCffiAdapter\r\n\r\nsession = requests.Session()\r\nsession.mount(\"http://\", CurlCffiAdapter())\r\nsession.mount(\"https://\", CurlCffiAdapter())\r\n\r\n# just use requests session like you normally would\r\nsession.get(\"https://example.com\")\r\n```\r\n\r\nConfiguring curl impersonate options:\r\n\r\n```python\r\nimport requests\r\nfrom curl_adapter import CurlCffiAdapter\r\n\r\n# you can use 'with ...' for just making a single request\r\nwith requests.Session() as s:\r\n    s.mount(\"http://\", CurlCffiAdapter(impersonate_browser_type=\"chrome\"))\r\n    s.mount(\"https://\", CurlCffiAdapter(impersonate_browser_type=\"chrome\"))\r\n\r\n    s.get(\"https://example.com\")\r\n```\r\n\r\nUsing it with [pycurl](https://github.com/pycurl/pycurl):\r\n\r\n```python\r\nimport requests\r\nfrom curl_adapter import PyCurlAdapter\r\n\r\nwith requests.Session() as s:\r\n    s.mount(\"http://\", PyCurlAdapter())\r\n    s.mount(\"https://\", PyCurlAdapter())\r\n\r\n    s.get(\"https://example.com\")\r\n```\r\n\r\n## More\r\nYou can get extra information from curl response info:\r\n```python\r\nimport requests\r\nfrom curl_adapter import PyCurlAdapter, CurlInfo\r\n\r\nwith requests.Session() as s:\r\n    s.mount(\"http://\", PyCurlAdapter())\r\n    s.mount(\"https://\", PyCurlAdapter())\r\n\r\n    response = s.get(\"https://example.com\")\r\n    curl_info: CurlInfo = response.get_curl_info()\r\n    print(\r\n        curl_info\r\n    )\r\n```\r\n\r\nReturns:\r\n```python\r\n{\r\n    'local_ip': '192.168.1.1', \r\n    'local_port': 40164,\r\n    'primary_ip': '3.210.94.60', \r\n    'primary_port': 443, \r\n    'total_time': 429186, \r\n    'speed_download': 472, \r\n    'speed_upload': 0, \r\n    'size_upload': 0, \r\n    'request_size': 0, \r\n    'response_body_size': 203, \r\n    'response_header_size': 224\r\n}\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2025 Elis K.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "A curl HTTP adapter switch for requests library \u2014 make browser-like requests with custom TLS fingerprints.",
    "version": "1.0.0b2",
    "project_urls": {
        "Homepage": "https://github.com/el1s7/curl-adapter"
    },
    "split_keywords": [
        "curl",
        " requests",
        " adapter",
        " tls fingerprint",
        " pycurl",
        " curl_cffi",
        " curl impersonate"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "085597d3502fddafcdcb3250a6b7b3f9322320b9e8e234e299436204ba035c19",
                "md5": "61de07290a29e3765b78209e30d5e9bc",
                "sha256": "d4b711653416bf0b94bd588f591c5ca0edb7a20aee36eaf75d3c3ae94a115b09"
            },
            "downloads": -1,
            "filename": "curl_adapter-1.0.0b2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "61de07290a29e3765b78209e30d5e9bc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 17356,
            "upload_time": "2025-01-20T21:10:19",
            "upload_time_iso_8601": "2025-01-20T21:10:19.764734Z",
            "url": "https://files.pythonhosted.org/packages/08/55/97d3502fddafcdcb3250a6b7b3f9322320b9e8e234e299436204ba035c19/curl_adapter-1.0.0b2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f847714f81e86a229a8622ea154fe8205ae4fb207d3c688fee78bb51ab0a261f",
                "md5": "c958106c1cf061f421fef4510e32f672",
                "sha256": "dce51bb5257b38af0b5cf974bb760ea7bf56061b8cb351fbd1097ca4a1d81189"
            },
            "downloads": -1,
            "filename": "curl_adapter-1.0.0b2.tar.gz",
            "has_sig": false,
            "md5_digest": "c958106c1cf061f421fef4510e32f672",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 16632,
            "upload_time": "2025-01-20T21:10:23",
            "upload_time_iso_8601": "2025-01-20T21:10:23.538319Z",
            "url": "https://files.pythonhosted.org/packages/f8/47/714f81e86a229a8622ea154fe8205ae4fb207d3c688fee78bb51ab0a261f/curl_adapter-1.0.0b2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-20 21:10:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "el1s7",
    "github_project": "curl-adapter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "curl-adapter"
}
        
Elapsed time: 0.43779s