<p align="center">
<a href="https://cloudbypass.com/" target="_blank" rel="noopener noreferrer" >
<div align="center">
<img src="https://raw.githubusercontent.com/cloudbypass/example/main/assets/img.png" alt="Cloudbypass" height="50">
</div>
</a>
</p>
## Cloudbypass SDK for Python
### 开始使用
> Cloudbypass Python SDK 仅支持 Python 3.7 及以上版本。
在`psf/requests`基础上封装的穿云SDK,支持穿云API服务的调用。通过内置的会话管理器,可以自动处理会话请求,无需手动管理Cookie等信息。
[![cloudbypass](https://img.shields.io/pypi/pyversions/cloudbypass)](https://pypi.org/project/cloudbypass/)
[![cloudbypass](https://img.shields.io/pypi/v/cloudbypass)](https://pypi.org/project/cloudbypass/)
[![cloudbypass](https://img.shields.io/pypi/dd/cloudbypass)](https://pypi.org/project/cloudbypass/#files)
[![cloudbypass](https://img.shields.io/pypi/wheel/cloudbypass)](https://pypi.org/project/cloudbypass/)
### 安装
```shell
python3 -m pip install cloudbypass -i https://pypi.org/simple
```
### 发起请求
`cloudbypass` 基于 `requests` 库,支持所有 `requests` 的方法。
通过添加初始化参数 `apikey` 和 `proxy`,分别用于设置穿云 API 服务密钥和代理 IP。
定制用户可以通过设置 `api_host` 参数来指定服务地址。
> 以上参数也可以通过环境变量 `CB_APIKEY`、`CB_PROXY` 和 `CB_APIHOST` 进行配置。
```python
from cloudbypass import Session
if __name__ == '__main__':
with Session(apikey="<APIKEY>", proxy="http://proxy:port") as session:
resp = session.get("https://opensea.io/category/memberships")
print(resp.status_code, resp.headers.get("x-cb-status"))
print(resp.text)
```
#### async
```python
import asyncio
from cloudbypass import AsyncSession
async def main():
async with AsyncSession(apikey="<APIKEY>", proxy="http://proxy:port") as session:
resp = await session.get("https://opensea.io/category/memberships")
print("Status:", resp.status)
text = await resp.text()
print("Body:", text)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
```
### 使用V2
穿云API V2适用于需要通过JS质询验证的网站。例如访问https://etherscan.io/accounts/label/lido ,请求示例:
```python
from cloudbypass import SessionV2
if __name__ == '__main__':
# Cookie模式:服务端返回加密Cookie,下次请求时由客户端发送验证Cookie
with SessionV2(apikey="<APIKEY>", proxy="http://proxy:port") as session:
resp = session.get("https://etherscan.io/accounts/label/lido")
print("Status:", resp.status_code, resp.headers.get("x-cb-status"))
print("Cookie:", resp.headers.get("set-cookie"))
print("Body:", resp.text)
# Part模式:由服务端管理验证Cookie,客户端只需要控制part参数
with SessionV2(apikey="<APIKEY>", proxy="http://proxy:port", part="0") as session:
resp = session.get("https://etherscan.io/accounts/label/lido")
print("Status:", resp.status_code, resp.headers.get("x-cb-status"))
print("Body:", resp.text)
```
#### async
```python
import asyncio
from cloudbypass import AsyncSessionV2
async def main():
# Cookie模式:服务端返回加密Cookie,下次请求时由客户端发送验证Cookie
async with AsyncSessionV2(apikey="<APIKEY>", proxy="http://proxy:port") as session:
resp = await session.get("https://etherscan.io/accounts/label/lido")
print("Status:", resp.status)
print("Cookie:", resp.headers.get("set-cookie"))
text = await resp.text()
print("Body:", text)
# Part模式:由服务端管理验证Cookie,客户端只需要控制part参数
async with AsyncSessionV2(apikey="<APIKEY>", proxy="http://proxy:port", part="0") as session:
resp = await session.get("https://etherscan.io/accounts/label/lido")
print("Status:", resp.status)
text = await resp.text()
print("Body:", text)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
```
### 查询余额
使用`get_balance`方法可以查询当前账户余额。
```python
from cloudbypass import get_balance
if __name__ == '__main__':
print(get_balance("<APIKEY>"))
```
#### async
```python
import asyncio
from cloudbypass import async_get_balance
async def main():
print(await async_get_balance("<APIKEY>"))
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
```
### 提取代理
通过`Proxy`类可以提取穿云动态代理IP和时效代理IP。
+ `copy()` 复制当前对象,使原有的对象不会受到影响。
+ `set_dynamic()` 设置为动态代理。
+ `set_expire(int)` 设置为时效代理,参数为IP过期时间,单位为秒。
+ `set_region(str)` 设置代理IP地区。
+ `clear_region()` 清除代理的地区。
+ `format(str)` 格式化代理IP,参数为格式化字符串,例如`{username}:{password}@gateway`。
+ `limit(int, str)` 返回一个代理IP字符串迭代器,参数为提取数量及代理格式化字符串。
+ `loop(int, str)` 返回一个代理IP字符串循环迭代器,参数为实际数量及代理格式化字符串。
```python
from cloudbypass import Proxy
if __name__ == '__main__':
proxy = Proxy("username-res:password")
# 提取动态代理
print("Extract dynamic proxy: ")
print(str(proxy.set_dynamic()))
print(str(proxy.set_region('US')))
# 提取时效代理并指定地区
print("Extract proxy with expire and region: ")
print(str(proxy.copy().set_expire(60 * 30).set_region('US')))
# 批量提取
print("Extract five 10-minute aging proxies: ")
pool = proxy.copy().set_expire(60 * 10).set_region('US').limit(5)
for _ in pool:
print(_)
# 循环提取
print("Loop two 10-minute aging proxies: ")
loop = proxy.copy().set_expire(60 * 10).set_region('US').loop(2)
for _ in range(10):
print(loop.__next__())
```
### 关于重定向问题
使用SDK发起请求时,重定向操作会自动处理,无需手动处理。且重定向响应也会消耗积分。
### 关于服务密钥
请访问[穿云控制台](https://console.cloudbypass.com/#/api/account)获取服务密钥。
Raw data
{
"_id": null,
"home_page": null,
"name": "cloudbypass",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "cloudflare, bypass, turnstile, scraping, cloudbypass, scrapingbypass, waf, captcha, cloudflare-bypass, cloudflare-scraping",
"author": "NULL",
"author_email": "python@cloudbypass.com",
"download_url": "https://files.pythonhosted.org/packages/1b/55/5c080a14a2e89b1e1666eccc0e6cab9aba92158af5900028fcada4d3a258/cloudbypass-0.2.0.tar.gz",
"platform": null,
"description": "<p align=\"center\">\r\n <a href=\"https://cloudbypass.com/\" target=\"_blank\" rel=\"noopener noreferrer\" >\r\n <div align=\"center\">\r\n <img src=\"https://raw.githubusercontent.com/cloudbypass/example/main/assets/img.png\" alt=\"Cloudbypass\" height=\"50\">\r\n </div>\r\n </a>\r\n</p>\r\n\r\n## Cloudbypass SDK for Python\r\n\r\n### \u5f00\u59cb\u4f7f\u7528\r\n\r\n> Cloudbypass Python SDK \u4ec5\u652f\u6301 Python 3.7 \u53ca\u4ee5\u4e0a\u7248\u672c\u3002\r\n\r\n\u5728`psf/requests`\u57fa\u7840\u4e0a\u5c01\u88c5\u7684\u7a7f\u4e91SDK\uff0c\u652f\u6301\u7a7f\u4e91API\u670d\u52a1\u7684\u8c03\u7528\u3002\u901a\u8fc7\u5185\u7f6e\u7684\u4f1a\u8bdd\u7ba1\u7406\u5668\uff0c\u53ef\u4ee5\u81ea\u52a8\u5904\u7406\u4f1a\u8bdd\u8bf7\u6c42\uff0c\u65e0\u9700\u624b\u52a8\u7ba1\u7406Cookie\u7b49\u4fe1\u606f\u3002\r\n\r\n[![cloudbypass](https://img.shields.io/pypi/pyversions/cloudbypass)](https://pypi.org/project/cloudbypass/)\r\n[![cloudbypass](https://img.shields.io/pypi/v/cloudbypass)](https://pypi.org/project/cloudbypass/)\r\n[![cloudbypass](https://img.shields.io/pypi/dd/cloudbypass)](https://pypi.org/project/cloudbypass/#files)\r\n[![cloudbypass](https://img.shields.io/pypi/wheel/cloudbypass)](https://pypi.org/project/cloudbypass/)\r\n\r\n### \u5b89\u88c5\r\n\r\n```shell\r\npython3 -m pip install cloudbypass -i https://pypi.org/simple\r\n```\r\n\r\n### \u53d1\u8d77\u8bf7\u6c42\r\n\r\n`cloudbypass` \u57fa\u4e8e `requests` \u5e93\uff0c\u652f\u6301\u6240\u6709 `requests` \u7684\u65b9\u6cd5\u3002\r\n\r\n\u901a\u8fc7\u6dfb\u52a0\u521d\u59cb\u5316\u53c2\u6570 `apikey` \u548c `proxy`\uff0c\u5206\u522b\u7528\u4e8e\u8bbe\u7f6e\u7a7f\u4e91 API \u670d\u52a1\u5bc6\u94a5\u548c\u4ee3\u7406 IP\u3002\r\n\r\n\u5b9a\u5236\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e `api_host` \u53c2\u6570\u6765\u6307\u5b9a\u670d\u52a1\u5730\u5740\u3002\r\n\r\n> \u4ee5\u4e0a\u53c2\u6570\u4e5f\u53ef\u4ee5\u901a\u8fc7\u73af\u5883\u53d8\u91cf `CB_APIKEY`\u3001`CB_PROXY` \u548c `CB_APIHOST` \u8fdb\u884c\u914d\u7f6e\u3002\r\n\r\n```python\r\nfrom cloudbypass import Session\r\n\r\nif __name__ == '__main__':\r\n with Session(apikey=\"<APIKEY>\", proxy=\"http://proxy:port\") as session:\r\n resp = session.get(\"https://opensea.io/category/memberships\")\r\n print(resp.status_code, resp.headers.get(\"x-cb-status\"))\r\n print(resp.text)\r\n```\r\n\r\n#### async\r\n\r\n```python\r\nimport asyncio\r\nfrom cloudbypass import AsyncSession\r\n\r\n\r\nasync def main():\r\n async with AsyncSession(apikey=\"<APIKEY>\", proxy=\"http://proxy:port\") as session:\r\n resp = await session.get(\"https://opensea.io/category/memberships\")\r\n print(\"Status:\", resp.status)\r\n text = await resp.text()\r\n print(\"Body:\", text)\r\n\r\n\r\nif __name__ == '__main__':\r\n loop = asyncio.get_event_loop()\r\n loop.run_until_complete(main())\r\n```\r\n\r\n### \u4f7f\u7528V2\r\n\r\n\u7a7f\u4e91API V2\u9002\u7528\u4e8e\u9700\u8981\u901a\u8fc7JS\u8d28\u8be2\u9a8c\u8bc1\u7684\u7f51\u7ad9\u3002\u4f8b\u5982\u8bbf\u95eehttps://etherscan.io/accounts/label/lido \uff0c\u8bf7\u6c42\u793a\u4f8b\uff1a\r\n\r\n```python\r\nfrom cloudbypass import SessionV2\r\n\r\nif __name__ == '__main__':\r\n # Cookie\u6a21\u5f0f\uff1a\u670d\u52a1\u7aef\u8fd4\u56de\u52a0\u5bc6Cookie\uff0c\u4e0b\u6b21\u8bf7\u6c42\u65f6\u7531\u5ba2\u6237\u7aef\u53d1\u9001\u9a8c\u8bc1Cookie\r\n with SessionV2(apikey=\"<APIKEY>\", proxy=\"http://proxy:port\") as session:\r\n resp = session.get(\"https://etherscan.io/accounts/label/lido\")\r\n print(\"Status:\", resp.status_code, resp.headers.get(\"x-cb-status\"))\r\n print(\"Cookie:\", resp.headers.get(\"set-cookie\"))\r\n print(\"Body:\", resp.text)\r\n\r\n # Part\u6a21\u5f0f\uff1a\u7531\u670d\u52a1\u7aef\u7ba1\u7406\u9a8c\u8bc1Cookie\uff0c\u5ba2\u6237\u7aef\u53ea\u9700\u8981\u63a7\u5236part\u53c2\u6570\r\n with SessionV2(apikey=\"<APIKEY>\", proxy=\"http://proxy:port\", part=\"0\") as session:\r\n resp = session.get(\"https://etherscan.io/accounts/label/lido\")\r\n print(\"Status:\", resp.status_code, resp.headers.get(\"x-cb-status\"))\r\n print(\"Body:\", resp.text)\r\n\r\n```\r\n\r\n#### async\r\n\r\n```python\r\nimport asyncio\r\nfrom cloudbypass import AsyncSessionV2\r\n\r\n\r\nasync def main():\r\n # Cookie\u6a21\u5f0f\uff1a\u670d\u52a1\u7aef\u8fd4\u56de\u52a0\u5bc6Cookie\uff0c\u4e0b\u6b21\u8bf7\u6c42\u65f6\u7531\u5ba2\u6237\u7aef\u53d1\u9001\u9a8c\u8bc1Cookie\r\n async with AsyncSessionV2(apikey=\"<APIKEY>\", proxy=\"http://proxy:port\") as session:\r\n resp = await session.get(\"https://etherscan.io/accounts/label/lido\")\r\n print(\"Status:\", resp.status)\r\n print(\"Cookie:\", resp.headers.get(\"set-cookie\"))\r\n text = await resp.text()\r\n print(\"Body:\", text)\r\n\r\n # Part\u6a21\u5f0f\uff1a\u7531\u670d\u52a1\u7aef\u7ba1\u7406\u9a8c\u8bc1Cookie\uff0c\u5ba2\u6237\u7aef\u53ea\u9700\u8981\u63a7\u5236part\u53c2\u6570\r\n async with AsyncSessionV2(apikey=\"<APIKEY>\", proxy=\"http://proxy:port\", part=\"0\") as session:\r\n resp = await session.get(\"https://etherscan.io/accounts/label/lido\")\r\n print(\"Status:\", resp.status)\r\n text = await resp.text()\r\n print(\"Body:\", text)\r\n\r\n\r\nif __name__ == '__main__':\r\n loop = asyncio.get_event_loop()\r\n loop.run_until_complete(main())\r\n```\r\n\r\n### \u67e5\u8be2\u4f59\u989d\r\n\r\n\u4f7f\u7528`get_balance`\u65b9\u6cd5\u53ef\u4ee5\u67e5\u8be2\u5f53\u524d\u8d26\u6237\u4f59\u989d\u3002\r\n\r\n```python\r\nfrom cloudbypass import get_balance\r\n\r\nif __name__ == '__main__':\r\n print(get_balance(\"<APIKEY>\"))\r\n\r\n```\r\n\r\n#### async\r\n\r\n```python\r\nimport asyncio\r\nfrom cloudbypass import async_get_balance\r\n\r\n\r\nasync def main():\r\n print(await async_get_balance(\"<APIKEY>\"))\r\n\r\n\r\nif __name__ == '__main__':\r\n loop = asyncio.get_event_loop()\r\n loop.run_until_complete(main())\r\n\r\n```\r\n\r\n### \u63d0\u53d6\u4ee3\u7406\r\n\r\n\u901a\u8fc7`Proxy`\u7c7b\u53ef\u4ee5\u63d0\u53d6\u7a7f\u4e91\u52a8\u6001\u4ee3\u7406IP\u548c\u65f6\u6548\u4ee3\u7406IP\u3002\r\n\r\n+ `copy()` \u590d\u5236\u5f53\u524d\u5bf9\u8c61\uff0c\u4f7f\u539f\u6709\u7684\u5bf9\u8c61\u4e0d\u4f1a\u53d7\u5230\u5f71\u54cd\u3002\r\n+ `set_dynamic()` \u8bbe\u7f6e\u4e3a\u52a8\u6001\u4ee3\u7406\u3002\r\n+ `set_expire(int)` \u8bbe\u7f6e\u4e3a\u65f6\u6548\u4ee3\u7406\uff0c\u53c2\u6570\u4e3aIP\u8fc7\u671f\u65f6\u95f4\uff0c\u5355\u4f4d\u4e3a\u79d2\u3002\r\n+ `set_region(str)` \u8bbe\u7f6e\u4ee3\u7406IP\u5730\u533a\u3002\r\n+ `clear_region()` \u6e05\u9664\u4ee3\u7406\u7684\u5730\u533a\u3002\r\n+ `format(str)` \u683c\u5f0f\u5316\u4ee3\u7406IP\uff0c\u53c2\u6570\u4e3a\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\uff0c\u4f8b\u5982`{username}:{password}@gateway`\u3002\r\n+ `limit(int, str)` \u8fd4\u56de\u4e00\u4e2a\u4ee3\u7406IP\u5b57\u7b26\u4e32\u8fed\u4ee3\u5668\uff0c\u53c2\u6570\u4e3a\u63d0\u53d6\u6570\u91cf\u53ca\u4ee3\u7406\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u3002\r\n+ `loop(int, str)` \u8fd4\u56de\u4e00\u4e2a\u4ee3\u7406IP\u5b57\u7b26\u4e32\u5faa\u73af\u8fed\u4ee3\u5668\uff0c\u53c2\u6570\u4e3a\u5b9e\u9645\u6570\u91cf\u53ca\u4ee3\u7406\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u3002\r\n\r\n```python\r\nfrom cloudbypass import Proxy\r\n\r\nif __name__ == '__main__':\r\n proxy = Proxy(\"username-res:password\")\r\n\r\n # \u63d0\u53d6\u52a8\u6001\u4ee3\u7406\r\n print(\"Extract dynamic proxy: \")\r\n print(str(proxy.set_dynamic()))\r\n print(str(proxy.set_region('US')))\r\n\r\n # \u63d0\u53d6\u65f6\u6548\u4ee3\u7406\u5e76\u6307\u5b9a\u5730\u533a\r\n print(\"Extract proxy with expire and region: \")\r\n print(str(proxy.copy().set_expire(60 * 30).set_region('US')))\r\n\r\n # \u6279\u91cf\u63d0\u53d6\r\n print(\"Extract five 10-minute aging proxies: \")\r\n pool = proxy.copy().set_expire(60 * 10).set_region('US').limit(5)\r\n for _ in pool:\r\n print(_)\r\n\r\n # \u5faa\u73af\u63d0\u53d6\r\n print(\"Loop two 10-minute aging proxies: \")\r\n loop = proxy.copy().set_expire(60 * 10).set_region('US').loop(2)\r\n for _ in range(10):\r\n print(loop.__next__())\r\n```\r\n\r\n### \u5173\u4e8e\u91cd\u5b9a\u5411\u95ee\u9898\r\n\r\n\u4f7f\u7528SDK\u53d1\u8d77\u8bf7\u6c42\u65f6\uff0c\u91cd\u5b9a\u5411\u64cd\u4f5c\u4f1a\u81ea\u52a8\u5904\u7406\uff0c\u65e0\u9700\u624b\u52a8\u5904\u7406\u3002\u4e14\u91cd\u5b9a\u5411\u54cd\u5e94\u4e5f\u4f1a\u6d88\u8017\u79ef\u5206\u3002\r\n\r\n### \u5173\u4e8e\u670d\u52a1\u5bc6\u94a5\r\n\r\n\u8bf7\u8bbf\u95ee[\u7a7f\u4e91\u63a7\u5236\u53f0](https://console.cloudbypass.com/#/api/account)\u83b7\u53d6\u670d\u52a1\u5bc6\u94a5\u3002\r\n",
"bugtrack_url": null,
"license": null,
"summary": "Cloudbypass SDK for Python.",
"version": "0.2.0",
"project_urls": null,
"split_keywords": [
"cloudflare",
" bypass",
" turnstile",
" scraping",
" cloudbypass",
" scrapingbypass",
" waf",
" captcha",
" cloudflare-bypass",
" cloudflare-scraping"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b4586109e85dff0e273ba843909a56f27a49f0987448b9b2a5f715edbfff5526",
"md5": "1fcb2cbfe4ccabce14f61b5936a259ca",
"sha256": "9d6fa52b050ccac2b783ba55c56fc4d2d08cf3084c1aaa9743e7c1c95c160d57"
},
"downloads": -1,
"filename": "cloudbypass-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1fcb2cbfe4ccabce14f61b5936a259ca",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 8837,
"upload_time": "2025-01-16T00:44:46",
"upload_time_iso_8601": "2025-01-16T00:44:46.534512Z",
"url": "https://files.pythonhosted.org/packages/b4/58/6109e85dff0e273ba843909a56f27a49f0987448b9b2a5f715edbfff5526/cloudbypass-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1b555c080a14a2e89b1e1666eccc0e6cab9aba92158af5900028fcada4d3a258",
"md5": "3e930359797cba2efc001bed55bde9ed",
"sha256": "5e1e987f9c6287a2b7e3b55052a6f289c0b035525ffe86de1c16361f0f12d858"
},
"downloads": -1,
"filename": "cloudbypass-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "3e930359797cba2efc001bed55bde9ed",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 10051,
"upload_time": "2025-01-16T00:44:50",
"upload_time_iso_8601": "2025-01-16T00:44:50.794532Z",
"url": "https://files.pythonhosted.org/packages/1b/55/5c080a14a2e89b1e1666eccc0e6cab9aba92158af5900028fcada4d3a258/cloudbypass-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-16 00:44:50",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "cloudbypass"
}