Python bindings for Cronet-Cloak - Authentic Chrome TLS/HTTP2 fingerprints with async support
Project description
chrome_client
基于 Chromium Cronet 和 Rust/PyO3 的 Python HTTP 客户端,提供同步、异步、流式请求、Cookie、代理和可配置 TLS Profile。
Python 导入名和 PyPI 项目名均为
chrome_client。
功能
- 同步 API:
get()、post()、put()、delete()、patch()、head()、options() - 异步 API:
async_get()、async_post()等 - 可复用的
CronetClient/AsyncCronetClient会话 - HTTP、HTTPS、SOCKS5 和 SOCKS5H 代理
- Cookie 自动保存、发送、查询和删除
- 重定向、超时、证书验证和流式响应
- 有序请求头
- 内置及自定义 TLS Profile
- Rust 原生扩展,使用 PyO3
abi3-py36
兼容性
| 平台 | 架构 | 状态 |
|---|---|---|
| Windows | x86_64 | 支持 |
| Windows | x86(32 位) | 支持 |
| Linux | x86_64,glibc >= 2.24 | 支持 |
| macOS | Apple Silicon / arm64 | 支持 |
- Python:
>= 3.6 - Linux Wheel:
manylinux_2_24_x86_64 - Ubuntu:支持 Ubuntu 20.04 及以上的 x86_64 系统
- 当前不支持 Linux ARM64、macOS Intel 和 Alpine Linux(musl)
安装
发布到 PyPI 后:
python -m pip install chrome_client
升级:
python -m pip install --upgrade chrome_client
快速开始
单次同步请求
import chrome_client
response = chrome_client.get("https://example.com")
response.raise_for_status()
print(response.status_code)
print(response.headers)
print(response.text)
同步 Session
import chrome_client
with chrome_client.CronetClient(
verify=True,
timeout_ms=30000,
chrometls="chrome_150",
) as client:
response = client.get(
"https://example.com/api",
params={"page": 1},
headers={"accept": "application/json"},
)
print(response.json())
POST JSON
import chrome_client
response = chrome_client.post(
"https://example.com/api",
json={"name": "chrome_client"},
timeout=30,
)
print(response.status_code)
print(response.json())
异步请求
下面的写法兼容 Python 3.6:
import asyncio
import chrome_client
async def main():
async with chrome_client.AsyncCronetClient() as client:
responses = await asyncio.gather(
client.get("https://example.com/1"),
client.get("https://example.com/2"),
)
for response in responses:
print(response.status_code)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Python 3.7 及以上也可以使用 asyncio.run(main())。
常用配置
代理
代理可以使用字符串或字典:
import chrome_client
client = chrome_client.CronetClient(
proxies="http://127.0.0.1:8080"
)
# 也可以使用:
# proxies={"https": "http://user:password@127.0.0.1:8080"}
# proxies="socks5://127.0.0.1:1080"
# proxies="socks5h://user:password@127.0.0.1:1080"
response = client.get("https://example.com")
client.close()
证书验证
证书验证默认启用:
client = chrome_client.CronetClient(verify=True)
仅在明确需要访问测试环境或自签名服务时关闭:
client = chrome_client.CronetClient(verify=False)
verify 在 Session 创建时确定;请求方法中的同名参数仅用于兼容常见 HTTP 客户端接口。
超时
Session 使用毫秒:
client = chrome_client.CronetClient(timeout_ms=15000)
模块级请求使用秒:
response = chrome_client.get("https://example.com", timeout=15)
有序请求头
需要严格控制顺序时使用元组列表:
headers = [
("user-agent", "Mozilla/5.0"),
("accept", "text/html,application/xhtml+xml"),
("accept-language", "zh-CN,zh;q=0.9"),
]
response = chrome_client.get(
"https://example.com",
headers=headers,
)
Cookie
import chrome_client
with chrome_client.CronetClient(default_domain="example.com") as client:
client.cookies.set("session", "value", domain="example.com")
response = client.get("https://example.com/account")
print(client.cookies.get("session", domain="example.com"))
print(client.cookies.get_dict(domain="example.com"))
client.cookies.delete("session", domain="example.com")
响应中的 Set-Cookie 会自动更新当前 Session 的 CookieJar。
TLS Profile
默认 Profile 是 chrome_150。当前内置配置可通过代码查看:
import chrome_client
print(sorted(chrome_client.get_tls_profiles().keys()))
选择 Profile:
client = chrome_client.CronetClient(chrometls="chrome_150")
增加自定义 Profile:
import chrome_client
profile = chrome_client.get_tls_profiles()["chrome_150"].copy()
profile["tls_curves"] = ["X25519MLKEM768", "X25519", "P-256", "P-384"]
chrome_client.add_tls_profile("chrome_custom", profile)
with chrome_client.CronetClient(chrometls="chrome_custom") as client:
response = client.get("https://example.com")
print(response.status_code)
相关函数:
get_tls_profiles():获取当前配置add_tls_profile(name, profile):新增或更新一个配置set_tls_profiles(profiles):替换当前进程中的全部配置clear_tls_profiles_cache():清除缓存并在下次使用时重新读取文件
add_tls_profile() 和 set_tls_profiles() 只修改当前 Python 进程中的配置。需要持久化时,请修改 python/chrome_client/tls_profiles.json 后重新构建 Wheel。
流式响应
同步
import chrome_client
response = chrome_client.get("https://example.com/file", stream=True)
try:
with open("download.bin", "wb") as output:
for chunk in response.iter_content(64 * 1024):
output.write(chunk)
finally:
response.close()
异步
import asyncio
import chrome_client
async def download():
async with chrome_client.AsyncCronetClient() as client:
response = await client.get("https://example.com/file", stream=True)
try:
with open("download.bin", "wb") as output:
async for chunk in response.aiter_content(64 * 1024):
output.write(chunk)
finally:
response.close()
loop = asyncio.get_event_loop()
loop.run_until_complete(download())
Response
常用属性和方法:
response.status_code
response.headers
response.cookies
response.content
response.text
response.json()
response.ok
response.raise_for_status()
异常类型:
from chrome_client import HTTPStatusError, RequestError
Linux 动态库排查
官方 Wheel 会携带所需的 Cronet 运行库。如果源码安装后出现:
libcronet.144.0.7506.0.so: cannot open shared object file
可以临时将包目录加入动态库搜索路径:
export LD_LIBRARY_PATH="$(python -c 'import os, chrome_client; print(os.path.dirname(chrome_client.__file__))'):$LD_LIBRARY_PATH"
如果使用的是 Alpine Linux,请改用 glibc 系发行版;当前 Wheel 不是 musllinux Wheel。
致谢
感谢 2833844911/cyCronet 项目及其作者为本项目提供的基座,本项目在其基础上二次开发。
版权与免责声明
以下版权声明和许可条款必须完整保留:
MIT License
Copyright (c) 2026 Cronet-Cloak
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.
完整许可内容同时保存在 LICENSE 文件中。
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chrome_client-0.1.1-cp36-abi3-win_amd64.whl.
File metadata
- Download URL: chrome_client-0.1.1-cp36-abi3-win_amd64.whl
- Upload date:
- Size: 8.9 MB
- Tags: CPython 3.6+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c60d8755124f7146fb850802ae862365ae399a415e720361ea8b091966785d30
|
|
| MD5 |
5e6056ee1df3cc81cda9243213b4d7a5
|
|
| BLAKE2b-256 |
1eec3a5b87d5e5f54e5353ffbcd91d84c86b8c275e68ecff13c95527eca583ea
|
Provenance
The following attestation bundles were made for chrome_client-0.1.1-cp36-abi3-win_amd64.whl:
Publisher:
build-wheels.yml on komAAmok/chrome_client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chrome_client-0.1.1-cp36-abi3-win_amd64.whl -
Subject digest:
c60d8755124f7146fb850802ae862365ae399a415e720361ea8b091966785d30 - Sigstore transparency entry: 2281777205
- Sigstore integration time:
-
Permalink:
komAAmok/chrome_client@de867422be84052443e55c6e817416772f516274 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/komAAmok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@de867422be84052443e55c6e817416772f516274 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file chrome_client-0.1.1-cp36-abi3-win32.whl.
File metadata
- Download URL: chrome_client-0.1.1-cp36-abi3-win32.whl
- Upload date:
- Size: 8.2 MB
- Tags: CPython 3.6+, Windows x86
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08e18a9b9c0f92f99a056efe7c572b98f2551a2eae2ffd4befa70912993e2879
|
|
| MD5 |
370074db201de7808d9ea572b806bff6
|
|
| BLAKE2b-256 |
e8ebcf31aa33f7419ed569d3beffee2147c7a01badf876606a900b7bf43ac5b4
|
Provenance
The following attestation bundles were made for chrome_client-0.1.1-cp36-abi3-win32.whl:
Publisher:
build-wheels.yml on komAAmok/chrome_client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chrome_client-0.1.1-cp36-abi3-win32.whl -
Subject digest:
08e18a9b9c0f92f99a056efe7c572b98f2551a2eae2ffd4befa70912993e2879 - Sigstore transparency entry: 2281777208
- Sigstore integration time:
-
Permalink:
komAAmok/chrome_client@de867422be84052443e55c6e817416772f516274 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/komAAmok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@de867422be84052443e55c6e817416772f516274 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file chrome_client-0.1.1-cp36-abi3-manylinux_2_24_x86_64.whl.
File metadata
- Download URL: chrome_client-0.1.1-cp36-abi3-manylinux_2_24_x86_64.whl
- Upload date:
- Size: 22.6 MB
- Tags: CPython 3.6+, manylinux: glibc 2.24+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7789b3e595366b4658bde3a68227ea5804f247d23e4c612facfce284353a584d
|
|
| MD5 |
9ac75ea6b7b2d69546e39a895d44e01f
|
|
| BLAKE2b-256 |
633ac4d585e7b77eca7b92c8828c186911d5dc8945c45303d00ce7d16ca3439d
|
Provenance
The following attestation bundles were made for chrome_client-0.1.1-cp36-abi3-manylinux_2_24_x86_64.whl:
Publisher:
build-wheels.yml on komAAmok/chrome_client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chrome_client-0.1.1-cp36-abi3-manylinux_2_24_x86_64.whl -
Subject digest:
7789b3e595366b4658bde3a68227ea5804f247d23e4c612facfce284353a584d - Sigstore transparency entry: 2281777193
- Sigstore integration time:
-
Permalink:
komAAmok/chrome_client@de867422be84052443e55c6e817416772f516274 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/komAAmok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@de867422be84052443e55c6e817416772f516274 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file chrome_client-0.1.1-cp36-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: chrome_client-0.1.1-cp36-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 7.7 MB
- Tags: CPython 3.6+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2e3e87d7b3dd4c994efc9309be345755fa74e159069f5607e05064f32721901
|
|
| MD5 |
4e054a41f8bdc31eec02b032cd94e654
|
|
| BLAKE2b-256 |
71f541ce253636e7691028ff7b1c76ecea0360c0d6039753b5ed71c3c2c01eba
|
Provenance
The following attestation bundles were made for chrome_client-0.1.1-cp36-abi3-macosx_11_0_arm64.whl:
Publisher:
build-wheels.yml on komAAmok/chrome_client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chrome_client-0.1.1-cp36-abi3-macosx_11_0_arm64.whl -
Subject digest:
e2e3e87d7b3dd4c994efc9309be345755fa74e159069f5607e05064f32721901 - Sigstore transparency entry: 2281777222
- Sigstore integration time:
-
Permalink:
komAAmok/chrome_client@de867422be84052443e55c6e817416772f516274 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/komAAmok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@de867422be84052443e55c6e817416772f516274 -
Trigger Event:
workflow_dispatch
-
Statement type: