Skip to main content

lucky_tls

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

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

安装

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

python -m pip install -U lucky_tls

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

使用

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.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.0

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.0
File Actions
lucky_tls-0.36.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for lucky_tls-0.36.0-cp314-cp314-win_amd64.whl
lucky_tls-0.36.0-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.0-cp314-cp314-manylinux_2_28_x86_64.whl
lucky_tls-0.36.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for lucky_tls-0.36.0-cp313-cp313-win_amd64.whl
lucky_tls-0.36.0-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.0-cp313-cp313-manylinux_2_28_x86_64.whl
lucky_tls-0.36.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for lucky_tls-0.36.0-cp312-cp312-win_amd64.whl
lucky_tls-0.36.0-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.0-cp312-cp312-manylinux_2_28_x86_64.whl
lucky_tls-0.36.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for lucky_tls-0.36.0-cp311-cp311-win_amd64.whl
lucky_tls-0.36.0-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.0-cp311-cp311-manylinux_2_28_x86_64.whl

Total release size: 36.0 MB

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

Download URL lucky_tls-0.36.0-cp314-cp314-win_amd64.whl
Size 4.2 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
2dbe0c7d42358c33fe990a436a5a15ccd316df9d15654fd15023a51736b6e258
BLAKE2b-256 checksum
How to use checksums
071235614e4d43c457fbe887e9877d756668140079c0278ebdc512696b272d29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL lucky_tls-0.36.0-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
7ab28ec0f3f986ee9acd368e3adf8ead765c99d98aa44710e8e08a59e45ee66c
BLAKE2b-256 checksum
How to use checksums
a41f40ba28301220983711a3738d2ce61cde2cb569de4805dd5f6f6e3ddc7e15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL lucky_tls-0.36.0-cp313-cp313-win_amd64.whl
Size 4.1 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
7b25522c7c647bebfd41a724475b7d9dfe638e11defe9467ef6b4a8a67f62acf
BLAKE2b-256 checksum
How to use checksums
6a0423b051fad06a25f556c68694c4a85bbbacf93401ccdc784c350e26b17c7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL lucky_tls-0.36.0-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
e29e83a6ea9e17655aa99a13cc402e6c059af0d55b34d9f85df15da5b41b23b8
BLAKE2b-256 checksum
How to use checksums
11447cdf030572744536c1a26fca4ddf886dc1b00aba88ec5ffd259366d72298
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL lucky_tls-0.36.0-cp312-cp312-win_amd64.whl
Size 4.1 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
76a41c4cedbc89053137990e423871288a3d7c402a5ab2abb83b73423f13d86d
BLAKE2b-256 checksum
How to use checksums
ec2f8967c0daf67effe1d58e6e19097587283ddbfa87ab3a4f3c190ad00f8f92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL lucky_tls-0.36.0-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
462912c26f902dd2d750d13992ff6aecf4698c6a842b0d78cf241251c5cf653b
BLAKE2b-256 checksum
How to use checksums
c0807a8f709e851117a3db3afa319b42cdd93a1af80ec5fe77b437b14059ae00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL lucky_tls-0.36.0-cp311-cp311-win_amd64.whl
Size 4.2 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
823f8716d4cf26ef453c975a6935778cda185b6ee5356960bcbaec4c134ead54
BLAKE2b-256 checksum
How to use checksums
d34125dc98dc6be63468206085a5a4f9e5f7d6fbf410e9702bab045236d4838a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL lucky_tls-0.36.0-cp311-cp311-manylinux_2_28_x86_64.whl
Size 4.9 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
058706776ebc83b6228a0b904c9d145519ddddf0df63fc9c7aa2239f4876ac1a
BLAKE2b-256 checksum
How to use checksums
c524cc7efe6c3bbfcfd085d9f346b440b3b0efac3c87d5a20a3678513779de30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Security for lucky-tls 0.36.0

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