Skip to main content
Loss of provenance

A previous release had provenance metadata, but this release does not. View details.

ruyihttp

基于真实 Firefox 159 原生网络组件的 Python 请求库,提供 Requests 风格接口,可模拟 Firefox 100–159 任一版本。 一条 pip install 即可安装,支持 HTTP/1.1、HTTP/2、HTTP/3、会话、代理和流式请求,无需启动浏览器。

Python Platform Stars

保留你熟悉的 get()、post()、Session 和 Response 用法,通过 Python 接口调用随包附带的原生库(Windows DLL / Linux .so)。

pip install -U ruyihttp
import ruyihttp as requests

response = requests.get("https://example.com", timeout=30)
response.raise_for_status()
print(response.text)

快速开始 · 常用功能 · 更多用法 · 赞助商 · 问题反馈

快速开始

支持 Windows x64 和 Linux x86_64,需要 64 位 Python 3.10–3.14。 Linux 需要 glibc 2.31 或更高版本,例如 Ubuntu 20.04+、Debian 11+。 PyPI 上的 0.9.0 目前只提供 Windows x64 wheel,Linux wheel 会在之后的版本补上。 原生库随 wheel 自动安装,Python 依赖由 pip 解析。

python -m pip install -U ruyihttp
python -c "import ruyihttp; print(ruyihttp.__version__)"

也可以从 GitHub Releases 下载 wheel 后用 pip 安装。 Windows 系统如果提示缺少 VCRUNTIME 或 MSVCP,请安装 Microsoft Visual C++ x64 Redistributable。

使用 Session

Session 可复用连接、Cookie 和默认请求头:

import ruyihttp

with ruyihttp.Session() as session:
    session.headers.update({"User-Agent": "my-client/1.0"})
    response = session.get(
        "https://httpbin.org/get",
        params={"page": 1, "keyword": "ruyihttp"},
        timeout=(5, 30),
    )
    response.raise_for_status()
    print(response.json())

常用功能

功能 用法
HTTP 请求 get、post、put、patch、delete、head、options
会话管理 Session、连接复用、Cookie、默认请求头
请求数据 URL 参数、表单、JSON、文件上传、生成器请求体
响应处理 text、content、json()、状态码、响应头
流式下载 stream=True、iter_content()、iter_lines()
代理 HTTP、HTTPS、SOCKS4/5、代理认证
认证与跳转 Basic / Digest 认证、重定向、响应钩子
连接控制 超时、重试、CA 证书、自定义适配器
协议 HTTP/1.1、HTTP/2、通过 HTTPS Alt-Svc 选择 HTTP/3
TLS 信息 response.tls 查看协商协议、版本及会话信息
模拟 Firefox 版本 firefox="100" 到 "159",TLS、请求头、HTTP/2、HTTP/3 全部按该版本发送

更多用法

发送 JSON

import ruyihttp

response = ruyihttp.post(
    "https://httpbin.org/post",
    json={"name": "ruyihttp", "enabled": True},
    timeout=30,
)
response.raise_for_status()
print(response.json())

使用代理

import ruyihttp

response = ruyihttp.get(
    "https://example.com",
    proxies={"https": "http://127.0.0.1:8080"},
    timeout=30,
)

SOCKS 代理先安装可选依赖,再使用 socks5h://127.0.0.1:1080 等代理地址:

pip install "ruyihttp[socks]"

流式下载

import ruyihttp

with ruyihttp.get("https://example.com", stream=True, timeout=30) as response:
    response.raise_for_status()
    with open("page.html", "wb") as output:
        for chunk in response.iter_content(chunk_size=65536):
            output.write(chunk)

配置重试

from ruyihttp import Session
from ruyihttp.adapters import HTTPAdapter
from urllib3.util import Retry

with Session() as session:
    session.mount("https://", HTTPAdapter(max_retries=Retry(total=3)))
    response = session.get("https://example.com", timeout=(5, 30))
    response.raise_for_status()

查看 TLS 信息

import ruyihttp

response = ruyihttp.get("https://example.com", timeout=30)
print(response.tls)

模拟指定 Firefox 版本

默认模拟 Firefox 159。Session 和 get() 等函数都可以用 firefox= 指定 100 到 159 之间的任一正式版,也可以用环境变量 NECKO_FIREFOX 设置默认值:

import ruyihttp

with ruyihttp.Session(firefox="115") as session:
    response = session.get("https://example.com", timeout=30)
    print(response.tls["profile"])   # firefox-115

ruyihttp.get("https://example.com", firefox="128", timeout=30)
print(ruyihttp.FIREFOX_VERSIONS)     # ('100', ..., '159')

选定版本后,网络上发出的内容都按该版本来:

  • TLS 握手(JA3 / JA4 指纹);
  • 请求头:User-Agent(110–119 为 rv:109.0)、Accept、Accept-Language、 Accept-Encoding、Priority;
  • HTTP/2:SETTINGS、PRIORITY 帧和流依赖(Akamai HTTP/2 指纹);
  • HTTP/3:QUIC 握手、传输参数、首包大小、HTTP/3 SETTINGS 和请求头顺序。

同一进程中可以同时使用不同版本的会话。以上各项都和对应版本的官方 Firefox 实测比对过。唯一已知差别:119–154 的 GREASE ECH 扩展比真实浏览器长 1 字节, 不影响 JA3 / JA4。

反馈与交流

欢迎通过 Issues 反馈问题或提出功能建议。 反馈时请附上 Python 版本、ruyihttp 版本、最小复现代码和错误信息,分享前移除 Cookie、Token 等私密数据。 微信联系Charleval。

相关项目:ruyiPage 提供 Firefox 浏览器自动化能力,适合需要页面操作的场景。

Metadata

Release files for ruyihttp 0.9.0

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

Loss of provenance

This file belongs to a release without provenance metadata, despite a prior release including this data.

We recommend further investigation before installing this file. View details.

Built distribution (wheel)

Table of built distributions (wheels) for ruyihttp 0.9.0
File Interpreter ABI Platform Actions
ruyihttp-0.9.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for ruyihttp-0.9.0-py3-none-win_amd64.whl

Release files / ruyihttp-0.9.0-py3-none-win_amd64.whl

Loss of provenance

This file belongs to a release without provenance metadata, despite a prior release including this data.

We recommend further investigation before installing this file. View details.

Download URL ruyihttp-0.9.0-py3-none-win_amd64.whl
Size 4.0 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
95b67581b2538194b9fc9b41b7f7077f1cb2767dbc5c776d404e78cd11d42f48
BLAKE2b-256 checksum
How to use checksums
1da0282d771e7311f8c3e166f5ccd67533a37033ecddd7c6ad31ac8dbc31f597
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Security for ruyihttp 0.9.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.

Loss of provenance

A previous release of these files had provenance metadata, but this release does not.

While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.

Release comparison

  • Removed 0.8.1 2 files With provenance
  • Added 0.9.0 1 file Without provenance

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