Skip to main content

lucky_tls

供 Python 调用的 TLS/HTTPS 请求库,支持同步、异步请求及 Chrome153/156/157、Edge157 配置,默认使用 Edge157。

0.36.3 默认让同步和异步 Session 复用 TCP/TLS 连接与代理隧道,并启用 TCP_NODELAY,减少连续请求的连接开销。保留 connection_reuse=False;连续请求使用同一个 Session。模块级 get() 不跨独立调用复用连接。

仅限个人和非商业用途,不允许商用。 采用专有二进制使用许可,不是开源软件;仅授予安装、运行和调用接口的权利,不授予修改、再分发、转售或源码获取权。完整条款随安装包提供,第三方组件适用各自的许可证。

安装

在具有匹配二进制 wheel 的 Python 环境中执行:

python -m pip install -U lucky_tls

PyPI 将下划线与连字符归一化,lucky_tls 和 lucky-tls 指向同一个项目。 仅提供已构建平台的二进制 wheel,不提供源码安装包。没有匹配 wheel 的环境无法直接安装。 提供 Windows x64、Linux x86_64(glibc 2.28+),以及 macOS Intel x86_64 / Apple Silicon arm64 的安装包;对应标准 CPython 3.11、3.12、3.13 和 3.14。macOS wheel 的部署目标为 11.0,运行回归在 macOS 15 上执行。不支持 free-threaded Python、Linux ARM64 或 Alpine/musl。

各平台最新可用版本可能不同:0.36.3 本轮优先发布 Windows x64;Linux 0.36.2、macOS 0.36.1 为既有发行包,不包含这次性能修复。以所安装的 lucky_tls.__version__ 和 PyPI 文件列表为准。

macOS 根据 Python 进程架构选择安装包,Apple Silicon 建议使用原生 arm64 Python。无需自行安装 Rust 或编译器。运行平台不会自动改变 profile:浏览器请求头和 TLS 配置继续采用已经验证的 Windows Chrome/Edge 模板,不表示已验证 macOS 浏览器指纹。

使用

from lucky_tls import Session

with Session() as session:  # 默认 edge157
    response = session.get("https://example.com/", timeout=10)
    print(response)  # <Response [200]>
    print(response.text)

请求支持 params、json、data、cookies 和逐请求 timeout;默认跟随重定向,可通过 allow_redirects=False 关闭。使用 AsyncSession 发起异步请求。默认 profile 为 edge157,可在 Session 或单次请求上显式选择 chrome153、chrome156、chrome157、edge157 或基础配置 default。

接口类型提示随 wheel 提供。浏览器配置的字段匹配不代表完整浏览器等价。

0.36.2:响应耗时

新增 resp.elapsed,类型为 datetime.timedelta,支持同步、异步及流式请求。resp.elapsed.total_seconds() 返回秒,毫秒使用 resp.elapsed.total_seconds() * 1000。计时截至最终响应头接收完成,不含正文下载;重定向各跳分别记录。纯缓存命中为零,304 合并使用本次网络校验耗时。

0.36.2 本轮提供 Windows x64 与 Linux x86_64(glibc 2.28+)/ CPython 3.11~3.14 包;macOS 当前仍为 0.36.1,尚不包含 elapsed。Linux wheel 使用 manylinux_2_28_x86_64 标签,已完成本地构建、审计和 PyPI 下载校验。

0.36.1:更新 Chrome157 / Edge157 采集基准

已对照 Windows Chrome 157.0.8103.80 和 Edge 157.0.4341.60:导航、fetch GET、fetch POST 各重复 3 次,18 次对照全部通过。与原有 157 配置相比,本次补丁构建的 TLS 扩展载荷、JA4、HTTP/2、场景请求头顺序和 HPACK 编码未发现差异,因此保留协议模板及 JA3 扩展顺序随机化。默认仍为 edge157,也可使用 profile="chrome157"。

验证范围是全新 Windows 配置、关闭 field trials 的 TLS 1.3 / HTTP/2 请求,不代表所有浏览器实验、站点或 HTTP/3 的完整等价。

0.36.0:证书验证、流量统计和类型化异常

新增 verify,Session 与模块级请求默认 True。单次请求省略或传 None 继承 Session;False 关闭证书链和主机名验证;字符串指定 PEM CA 文件。请求级 True 可重新开启验证,并保留 Session 的自定义 CA。支持同步、两种异步后端、流式和 HTTP/3,连接与会话票据按验证配置隔离。

from lucky_tls import Session

with Session(verify=True, traffic=True) as session:
    response = session.get("https://example.com/", timeout=10)
    print(response)                # <Response [200]>
    print(response.traffic.total)  # 本次请求流量

traffic 默认关闭;开启后通过 resp.traffic 查看统计。新增 ProtocolError、TooManyRedirects、ConnectionClosed 等异常,保留原有内建异常继承关系。修复 Vary 缓存变体、异常响应头解析、失效连接恢复以及 DNS/上传线程池阻塞问题。默认 profile 继续为 edge157。

0.35.0:Edge157 默认与对应版本请求头

新增 Chrome157 和 Edge157 预设,默认采用 Edge157。自动 User-Agent、Client Hints 等请求头随有效 profile 切换,用户显式 headers 优先,普通请求保留 Accept: */*。导航与 fetch 场景可使用 BrowserContext,或显式使用 chrome157_headers() / edge157_headers()。原始 JA3 继续随浏览器扩展乱序变化。

print(resp) 与 curl_cffi 一样只显示 <Response [状态码]>;详细信息使用 resp.status_code、resp.text、resp.content、resp.json()、resp.headers、resp.cookies.get_dict() 等获取。同步、异步及流式响应均使用简短打印,打印不会消费流式正文。

Chrome 157.0.8103.51 与 Edge 157.0.4341.42 的 Windows 首次 TLS1.3/HTTP2 导航及同源 fetch 样本已完成对照。HTTP3 支持功能请求,但本轮未完成 157 浏览器 QUIC/HTTP3 指纹的完整对照。

0.34.1:默认 Accept 请求头

普通请求默认发送 Accept: */*,支持同步接口和两种异步后端。请求级或 Session 级自定义 Accept 优先;headers={"Accept": None} 可抑制默认值,空字符串保留为空值。修复重定向与异步 worker 间的删除标记传递。显式浏览器上下文仍使用页面策略生成请求头。

from lucky_tls import BrowserContext, Session

context = BrowserContext.fetch("https://example.com/page")
with Session(profile="chrome156", browser_context=context) as session:
    response = session.get("https://example.com/", timeout=10)
    print(response.status_code, response.from_cache)

显式提供上下文后启用分区 HTTP 缓存、ETag/304 验证、SameSite/CHIPS Cookie、Origin/Referer/Sec-Fetch 和 CORS 预检。BrowserContext.fetch 的 credentials 可选 omit、same-origin、include;cache 可选 default、no-store、reload、no-cache、force-cache、only-if-cached,最后一种要求 mode="same-origin"。单次请求可以用 context= 覆盖 Session 默认上下文。

手动设置浏览器 Cookie 使用 session.cookies.set("name", "value", url="https://example.com/", same_site="Lax");上下文模式不接受没有 URL 作用域的 Cookie 字典或手写 Cookie 请求头。fetch 响应隐藏 Set-Cookie,已接受的 Cookie 保存在 session.cookies。跨源 CORS 拒绝会抛 BrowserPolicyError,no-cors 的 opaque 响应不会暴露正文。普通不带上下文的请求保留原有行为。

AsyncSession 的 threaded 与 native 后端支持同样的页面策略。上下文目前要求 stream=False,缓存只覆盖内存中的完整 GET;allow_redirects=False 是 requests 风格停止跳转,不是 Fetch manual redirect。调用者需要提供正确的页面与顶层站点,运行库不会启动或执行浏览器页面。

本版同时完善 QUIC 会话恢复、ECH 扩展压缩和 QPACK。HTTP/3 需显式选择;不实现 QUIC 0-RTT、自动 DNS HTTPS/Alt-Svc 选择、DOM、Service Worker 或完整浏览器行为。

Metadata

Release files for lucky-tls 0.36.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for lucky-tls 0.36.3
File Actions
lucky_tls-0.36.3-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for lucky_tls-0.36.3-cp314-cp314-win_amd64.whl
lucky_tls-0.36.3-cp314-cp314-manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64 Details for lucky_tls-0.36.3-cp314-cp314-manylinux_2_28_x86_64.whl
lucky_tls-0.36.3-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for lucky_tls-0.36.3-cp313-cp313-win_amd64.whl
lucky_tls-0.36.3-cp313-cp313-manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64 Details for lucky_tls-0.36.3-cp313-cp313-manylinux_2_28_x86_64.whl
lucky_tls-0.36.3-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for lucky_tls-0.36.3-cp312-cp312-win_amd64.whl
lucky_tls-0.36.3-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details for lucky_tls-0.36.3-cp312-cp312-manylinux_2_28_x86_64.whl
lucky_tls-0.36.3-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for lucky_tls-0.36.3-cp311-cp311-win_amd64.whl
lucky_tls-0.36.3-cp311-cp311-manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64 Details for lucky_tls-0.36.3-cp311-cp311-manylinux_2_28_x86_64.whl

Total release size: 35.9 MB

Release files / lucky_tls-0.36.3-cp314-cp314-win_amd64.whl

Download URL lucky_tls-0.36.3-cp314-cp314-win_amd64.whl
Size 4.2 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
cae3f6409c7e1aef10edac60ec0861a8dc21120af59ab93e44456fd7f41c64f9
BLAKE2b-256 checksum
How to use checksums
11277593b044f973e0e0a281a73fe4edfcd61716191d7132158716d1e55a626b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Release files / lucky_tls-0.36.3-cp314-cp314-manylinux_2_28_x86_64.whl

Download URL lucky_tls-0.36.3-cp314-cp314-manylinux_2_28_x86_64.whl
Size 4.8 MB
Tags CPython 3.14 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
ee67c7e55dfd2478b91095b6d4750dc4a361526b01fb6fda60ab79f495160fb5
BLAKE2b-256 checksum
How to use checksums
deb9ac562e98aa9ab5e4d6a40b969fdec9a6d7b6509a5b9fc22d33cee3456877
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Release files / lucky_tls-0.36.3-cp313-cp313-win_amd64.whl

Download URL lucky_tls-0.36.3-cp313-cp313-win_amd64.whl
Size 4.1 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
49f64310160b8dd344e9d48dd1a8e431758a98aa5495c4383d95803a97925132
BLAKE2b-256 checksum
How to use checksums
065f98287f9a56eef582908151174dc3ba0e2895ea94592a6a60ff7e5c7f0f3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Release files / lucky_tls-0.36.3-cp313-cp313-manylinux_2_28_x86_64.whl

Download URL lucky_tls-0.36.3-cp313-cp313-manylinux_2_28_x86_64.whl
Size 4.8 MB
Tags CPython 3.13 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
a3ea05e6bfe79f1941fae18c0271947f4dd276edf02285b2e2037af1600d2daa
BLAKE2b-256 checksum
How to use checksums
0ea0a955aecd5693f6b07d29f1c7c438d6363a35ad7a15b72539f121577cfb11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Release files / lucky_tls-0.36.3-cp312-cp312-win_amd64.whl

Download URL lucky_tls-0.36.3-cp312-cp312-win_amd64.whl
Size 4.1 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
e539188b8c26c53e683cb640899b004cb21505c119d3420cf1264e3de7a4d81b
BLAKE2b-256 checksum
How to use checksums
ff21b66ceb4e87ae4c1f7cfb4d55e3c721dca8e51dc0af7d961d26c1d007fb6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Release files / lucky_tls-0.36.3-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL lucky_tls-0.36.3-cp312-cp312-manylinux_2_28_x86_64.whl
Size 4.8 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
bbf86c04412b32ffc6a2318739c8153f9038cb847aefcde74d4462ceed5e645d
BLAKE2b-256 checksum
How to use checksums
09121159eeec0627cded95db29045c9baac546d456a08da84f5fa7be8008d90e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Release files / lucky_tls-0.36.3-cp311-cp311-win_amd64.whl

Download URL lucky_tls-0.36.3-cp311-cp311-win_amd64.whl
Size 4.1 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
0dd6b0e42c85026fb90ba6f5a721c3bfad2ff7868e0da1fb48032b0003cdc388
BLAKE2b-256 checksum
How to use checksums
bdfa7c36f5948a9b2c9df973fff803baa2e06d76222135b7aecd64b28be1bc22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Release files / lucky_tls-0.36.3-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL lucky_tls-0.36.3-cp311-cp311-manylinux_2_28_x86_64.whl
Size 5.0 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
29dba2ebbbce8f35bfbe1b1a691c636709434bb8b1a1a971c30ea6f559d1e92c
BLAKE2b-256 checksum
How to use checksums
d3e9ecabe5a21af076d2b492c1c5fc41a44d33199b2b6fe57969eb0617fd8ad5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Security for lucky-tls 0.36.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page