never-primp 1.0.2__cp38-abi3-macosx_11_0_arm64.whl → 1.1.1__cp38-abi3-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of never-primp might be problematic. Click here for more details.

@@ -0,0 +1,813 @@
1
+ Metadata-Version: 2.4
2
+ Name: never_primp
3
+ Version: 1.1.1
4
+ Classifier: Development Status :: 5 - Production/Stable
5
+ Classifier: Intended Audience :: Developers
6
+ Classifier: License :: OSI Approved :: MIT License
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3.8
9
+ Classifier: Programming Language :: Python :: 3.9
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: Implementation :: CPython
15
+ Classifier: Programming Language :: Rust
16
+ Classifier: Topic :: Internet :: WWW/HTTP
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ License-File: LICENSE
19
+ Summary: 基于原primp 重新优化调整的请求库 - The fastest python HTTP client that can impersonate web browsers
20
+ Keywords: requests,httpx,http,http-client,tls-fingerprint,ja3,ja4,impersonate,browser-impersonation,web-scraping,crawler,reverse-engineering
21
+ Author: Neverland
22
+ Requires-Python: >=3.8
23
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
24
+ Project-URL: Homepage, https://github.com/Neverland/never_primp
25
+ Project-URL: Repository, https://github.com/Neverland/never_primp
26
+ Project-URL: Bug Tracker, https://github.com/Neverland/never_primp/issues
27
+
28
+ <div align="center">
29
+
30
+ # 🪞 NEVER_PRIMP
31
+
32
+ **由于原primp项目作者长时间不维护更新,所以自己基于primp项目进行重构维护**
33
+
34
+ **终极 Python HTTP 客户端 - 专为网络爬虫与浏览器伪装设计**
35
+
36
+ ![Python >= 3.8](https://img.shields.io/badge/python->=3.8-blue.svg)
37
+ [![PyPI version](https://badge.fury.io/py/never-primp.svg)](https://pypi.org/project/never-primp)
38
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
39
+ [![Rust](https://img.shields.io/badge/rust-1.70+-orange.svg)](https://www.rust-lang.org)
40
+
41
+ *基于 Rust 构建的闪电般快速的 HTTP 客户端,专为网络爬虫、反爬虫绕过和完美浏览器伪装而设计*
42
+
43
+ [简体中文](README_CN.md) | [English](README.md)
44
+
45
+ [安装](#-安装) •
46
+ [核心特性](#-核心特性) •
47
+ [快速开始](#-快速开始) •
48
+ [文档](#-文档) •
49
+ [示例](#-示例)
50
+
51
+ </div>
52
+
53
+ ---
54
+
55
+ ## 🎯 什么是 NEVER_PRIMP?
56
+
57
+ **NEVER_PRIMP** (**P**ython **R**equests **IMP**ersonate) 是一个前沿的 HTTP 客户端库,它结合了:
58
+
59
+ - ⚡ **极致速度**:基于 Rust 的 `wreq` 构建,零拷贝解析
60
+ - 🎭 **完美浏览器伪装**:模拟 Chrome、Firefox、Safari、Edge 的 TLS/JA3/JA4 指纹
61
+ - 🛡️ **反爬虫绕过**:先进的功能绕过 WAF、Cloudflare 和机器人检测
62
+ - 🔧 **生产就绪**:连接池、重试、Cookie、流式传输等完整功能
63
+
64
+ ### 为什么选择 NEVER_PRIMP?
65
+
66
+ | 功能 | NEVER_PRIMP | requests | httpx | curl-cffi |
67
+ |------|-------------|----------|-------|-----------|
68
+ | **速度** | ⚡⚡⚡ | ⚡ | ⚡⚡ | ⚡⚡ |
69
+ | **浏览器伪装** | ✅ 完整 | ❌ | ❌ | ✅ 有限 |
70
+ | **请求头顺序控制** | ✅ | ❌ | ❌ | ❌ |
71
+ | **Cookie 分割 (HTTP/2)** | ✅ | ❌ | ❌ | ❌ |
72
+ | **连接池** | ✅ | ✅ | ✅ | ❌ |
73
+ | **异步支持** | ✅ | ❌ | ✅ | ❌ |
74
+ | **原生 TLS** | ✅ | ❌ | ❌ | ✅ |
75
+
76
+ ---
77
+
78
+ ## 📦 安装
79
+
80
+ ```bash
81
+ pip install -U never-primp
82
+ ```
83
+
84
+ ### 平台支持
85
+
86
+ 提供预编译的二进制包:
87
+ - 🐧 **Linux**: x86_64, aarch64, armv7 (manylinux_2_34+)
88
+ - 🐧 **Linux (musl)**: x86_64, aarch64
89
+ - 🪟 **Windows**: x86_64
90
+ - 🍏 **macOS**: x86_64, ARM64 (Apple Silicon)
91
+
92
+ ---
93
+
94
+ ## ✨ 核心特性
95
+
96
+ ### 🚀 性能优化
97
+
98
+ <details>
99
+ <summary><b>点击展开</b></summary>
100
+
101
+ - **连接池**:可配置空闲超时的连接重用
102
+ - **TCP 优化**:TCP_NODELAY + TCP keepalive 降低延迟
103
+ - **零拷贝解析**:Rust 的高效内存处理
104
+ - **HTTP/2 多路复用**:单个连接处理多个请求
105
+
106
+ ```python
107
+ client = primp.Client(
108
+ pool_idle_timeout=90.0, # 保持连接 90 秒
109
+ pool_max_idle_per_host=10, # 每个主机最多 10 个空闲连接
110
+ tcp_nodelay=True, # 禁用 Nagle 算法
111
+ tcp_keepalive=60.0, # TCP keepalive 每 60 秒
112
+ )
113
+ ```
114
+
115
+ **基准测试**:连接复用的顺序请求比 `requests` 快约 59%。
116
+
117
+ </details>
118
+
119
+ ### 🎭 高级浏览器伪装
120
+
121
+ <details>
122
+ <summary><b>点击展开</b></summary>
123
+
124
+ 完美的指纹模拟:
125
+
126
+ - **Chrome** (100-141):最新版本的完整 TLS/HTTP2 指纹
127
+ - **Safari** (15.3-26):iOS、iPadOS、macOS 变体
128
+ - **Firefox** (109-143):桌面版本
129
+ - **Edge** (101-134):基于 Chromium
130
+ - **OkHttp** (3.9-5.0):Android 应用库
131
+
132
+ ```python
133
+ client = primp.Client(
134
+ impersonate="chrome_141", # 浏览器版本
135
+ impersonate_os="windows" # 操作系统: windows, macos, linux, android, ios
136
+ )
137
+ ```
138
+
139
+ 模拟内容:
140
+ - ✅ TLS 指纹 (JA3/JA4)
141
+ - ✅ HTTP/2 指纹 (AKAMAI)
142
+ - ✅ 请求头顺序和大小写
143
+ - ✅ 加密套件
144
+ - ✅ 扩展顺序
145
+
146
+ </details>
147
+
148
+ ### 🛡️ 反爬虫绕过功能
149
+
150
+ <details>
151
+ <summary><b>点击展开</b></summary>
152
+
153
+ #### 1. **有序请求头** 🆕
154
+ 维持精确的请求头顺序以绕过检测请求头序列的检测系统:
155
+
156
+ ```python
157
+ client = primp.Client(
158
+ headers={
159
+ "user-agent": "Mozilla/5.0...",
160
+ "accept": "text/html,application/xhtml+xml",
161
+ "accept-language": "en-US,en;q=0.9",
162
+ "accept-encoding": "gzip, deflate, br",
163
+ "sec-fetch-dest": "document",
164
+ "sec-fetch-mode": "navigate",
165
+ }
166
+ )
167
+ ```
168
+
169
+ **使用场景**:检查请求头顺序的网站(Cloudflare、Akamai 等)
170
+
171
+ #### 2. **Cookie 分割 (HTTP/2)** 🆕
172
+ 像真实浏览器一样将 Cookie 作为独立的请求头发送:
173
+
174
+ ```python
175
+ client = primp.Client(
176
+ split_cookies=True, # 使用 HTTP/2 风格发送 Cookie
177
+ http2_only=True
178
+ )
179
+
180
+ # 发送格式:
181
+ # cookie: session_id=abc123
182
+ # cookie: user_token=xyz789
183
+ # cookie: preference=dark_mode
184
+
185
+ # 而不是:
186
+ # Cookie: session_id=abc123; user_token=xyz789; preference=dark_mode
187
+ ```
188
+
189
+ **使用场景**:精确的 HTTP/2 浏览器模拟以绕过反爬虫
190
+
191
+ 📖 [完整文档](SPLIT_COOKIES.md)
192
+
193
+ #### 3. **动态配置**
194
+ 无需重新创建即可更改客户端行为:
195
+
196
+ ```python
197
+ client = primp.Client(impersonate="chrome_140")
198
+
199
+ # 动态切换伪装
200
+ client.impersonate = "safari_18"
201
+ client.impersonate_os = "macos"
202
+
203
+ # 更新请求头
204
+ client.headers = {...}
205
+ client.headers_update({"Referer": "https://example.com"})
206
+
207
+ # 更改代理
208
+ client.proxy = "socks5://127.0.0.1:1080"
209
+ ```
210
+
211
+ </details>
212
+
213
+ ### 🍪 智能 Cookie 管理
214
+
215
+ <details>
216
+ <summary><b>点击展开</b></summary>
217
+
218
+ #### 自动 Cookie 持久化
219
+ ```python
220
+ client = primp.Client(cookie_store=True) # 默认开启
221
+
222
+ # Cookie 自动存储和发送
223
+ resp1 = client.get("https://example.com/login")
224
+ resp2 = client.get("https://example.com/dashboard") # 自动包含 Cookie
225
+ ```
226
+
227
+ #### 类字典 Cookie 接口 (requests 风格)
228
+ ```python
229
+ # 访问 cookie jar
230
+ cookies = client.cookies
231
+
232
+ # 设置 Cookie (类字典方式)
233
+ cookies["session_id"] = "abc123"
234
+ cookies.update({"user_token": "xyz789"})
235
+
236
+ # 获取 Cookie
237
+ session_id = cookies.get("session_id")
238
+ all_cookies = dict(cookies) # 获取所有 Cookie 为字典
239
+
240
+ # 删除 Cookie
241
+ del cookies["session_id"]
242
+ cookies.clear() # 清空所有
243
+ ```
244
+
245
+ #### 手动 Cookie 控制
246
+ ```python
247
+ # 为特定 URL 设置 Cookie
248
+ client.set_cookies(
249
+ url="https://example.com",
250
+ cookies={"session": "abc123", "user_id": "456"}
251
+ )
252
+
253
+ # 获取特定 URL 的所有 Cookie
254
+ cookies = client.get_cookies(url="https://example.com")
255
+
256
+ # 单次请求 Cookie (临时,不存储)
257
+ resp = client.get(url, cookies={"temp": "value"})
258
+ ```
259
+
260
+ </details>
261
+
262
+ ### 🔒 证书管理
263
+
264
+ <details>
265
+ <summary><b>点击展开</b></summary>
266
+
267
+ - **系统证书库**:随操作系统自动更新(不再有证书过期问题!)
268
+ - **自定义 CA 包**:支持企业代理
269
+
270
+ ```python
271
+ # 使用系统证书(默认)
272
+ client = primp.Client(verify=True)
273
+
274
+ # 自定义 CA 包
275
+ client = primp.Client(ca_cert_file="/path/to/cacert.pem")
276
+
277
+ # 环境变量
278
+ export PRIMP_CA_BUNDLE="/path/to/cert.pem"
279
+ ```
280
+
281
+ </details>
282
+
283
+ ### 🔄 HTTP 版本控制
284
+
285
+ <details>
286
+ <parameter name="summary"><b>点击展开</b></summary>
287
+
288
+ 控制使用哪个 HTTP 协议版本:
289
+
290
+ ```python
291
+ # 强制使用 HTTP/1.1
292
+ client = primp.Client(http1_only=True)
293
+
294
+ # 强制使用 HTTP/2
295
+ client = primp.Client(http2_only=True)
296
+
297
+ # 自动协商(默认)
298
+ client = primp.Client() # 选择最佳可用版本
299
+
300
+ # 优先级: http1_only > http2_only > 自动
301
+ ```
302
+
303
+ **使用场景**:
304
+ - `http1_only=True`: 旧版服务器、调试、特定兼容性需求
305
+ - `http2_only=True`: 现代 API、性能优化
306
+ - 默认: 最佳兼容性
307
+
308
+ </details>
309
+
310
+ ### 🌊 流式响应
311
+
312
+ <details>
313
+ <summary><b>点击展开</b></summary>
314
+
315
+ 高效地流式传输大型响应:
316
+
317
+ ```python
318
+ resp = client.get("https://example.com/large-file.zip")
319
+
320
+ for chunk in resp.stream():
321
+ process_chunk(chunk)
322
+ ```
323
+
324
+ </details>
325
+
326
+ ### ⚡ 异步支持
327
+
328
+ <details>
329
+ <summary><b>点击展开</b></summary>
330
+
331
+ 完整的 async/await 支持,使用 `AsyncClient`:
332
+
333
+ ```python
334
+ import asyncio
335
+ import never_primp as primp
336
+
337
+ async def fetch(url):
338
+ async with primp.AsyncClient(impersonate="chrome_141") as client:
339
+ return await client.get(url)
340
+
341
+ async def main():
342
+ urls = ["https://site1.com", "https://site2.com", "https://site3.com"]
343
+ tasks = [fetch(url) for url in urls]
344
+ results = await asyncio.gather(*tasks)
345
+
346
+ asyncio.run(main())
347
+ ```
348
+
349
+ </details>
350
+
351
+ ---
352
+
353
+ ## 🚀 快速开始
354
+
355
+ ### 基础用法
356
+
357
+ ```python
358
+ import never_primp as primp
359
+
360
+ # 简单的 GET 请求
361
+ client = primp.Client()
362
+ response = client.get("https://httpbin.org/get")
363
+ print(response.text)
364
+
365
+ # 带浏览器伪装
366
+ client = primp.Client(impersonate="chrome_141", impersonate_os="windows")
367
+ response = client.get("https://tls.peet.ws/api/all")
368
+ print(response.json())
369
+ ```
370
+
371
+ ### 完美的浏览器模拟
372
+
373
+ ```python
374
+ # 完整的浏览器模拟用于反爬虫绕过
375
+ client = primp.Client(
376
+ # 浏览器伪装
377
+ impersonate="chrome_141",
378
+ impersonate_os="windows",
379
+
380
+ # 高级反检测
381
+ headers={
382
+ "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
383
+ "sec-ch-ua": '"Chromium";v="141", "Not?A_Brand";v="8"',
384
+ "sec-ch-ua-mobile": "?0",
385
+ "sec-ch-ua-platform": '"Windows"',
386
+ "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
387
+ "sec-fetch-site": "none",
388
+ "sec-fetch-mode": "navigate",
389
+ "sec-fetch-user": "?1",
390
+ "sec-fetch-dest": "document",
391
+ "accept-encoding": "gzip, deflate, br",
392
+ "accept-language": "en-US,en;q=0.9",
393
+ },
394
+ split_cookies=True, # HTTP/2 风格的 Cookie
395
+
396
+ # 性能优化
397
+ pool_idle_timeout=90.0,
398
+ pool_max_idle_per_host=10,
399
+ tcp_nodelay=True,
400
+
401
+ # HTTP 版本控制
402
+ http2_only=True, # 强制 HTTP/2 以获得更好性能
403
+ timeout=30,
404
+ )
405
+
406
+ # 像任何 HTTP 客户端一样使用
407
+ response = client.get("https://difficult-site.com")
408
+ ```
409
+
410
+ ---
411
+
412
+ ## 📚 文档
413
+
414
+ ### 核心文档
415
+
416
+ - [**Cookie 分割指南**](SPLIT_COOKIES.md) - 像真实浏览器一样处理 HTTP/2 Cookie
417
+
418
+ ### 快速参考
419
+
420
+ <details>
421
+ <summary><b>Client 参数</b></summary>
422
+
423
+ ```python
424
+ Client(
425
+ # 认证
426
+ auth: tuple[str, str | None] | None = None,
427
+ auth_bearer: str | None = None,
428
+
429
+ # 请求头和 Cookie
430
+ headers: dict[str, str] | None = None, # 🆕 有序请求头
431
+ cookie_store: bool = True,
432
+ split_cookies: bool = False, # 🆕 HTTP/2 Cookie 分割
433
+
434
+ # 浏览器伪装
435
+ impersonate: str | None = None, # chrome_141, safari_18 等
436
+ impersonate_os: str | None = None, # windows, macos, linux 等
437
+
438
+ # 网络设置
439
+ proxy: str | None = None,
440
+ timeout: float = 30,
441
+ verify: bool = True,
442
+ ca_cert_file: str | None = None,
443
+
444
+ # HTTP 配置
445
+ http1_only: bool = False, # 🆕 强制 HTTP/1.1
446
+ http2_only: bool = False, # 强制 HTTP/2
447
+ https_only: bool = False,
448
+ follow_redirects: bool = True,
449
+ max_redirects: int = 20,
450
+ referer: bool = True,
451
+
452
+ # 性能优化
453
+ pool_idle_timeout: float | None = None,
454
+ pool_max_idle_per_host: int | None = None,
455
+ tcp_nodelay: bool | None = None,
456
+ tcp_keepalive: float | None = None,
457
+
458
+ # 查询参数
459
+ params: dict[str, str] | None = None,
460
+ )
461
+ ```
462
+
463
+ </details>
464
+
465
+ <details>
466
+ <summary><b>请求方法</b></summary>
467
+
468
+ ```python
469
+ # HTTP 方法
470
+ client.get(url, **kwargs)
471
+ client.post(url, **kwargs)
472
+ client.put(url, **kwargs)
473
+ client.patch(url, **kwargs)
474
+ client.delete(url, **kwargs)
475
+ client.head(url, **kwargs)
476
+ client.options(url, **kwargs)
477
+
478
+ # 通用参数
479
+ params: dict[str, str] | None = None,
480
+ headers: dict[str, str] | None = None, # 🆕
481
+ cookies: dict[str, str] | None = None,
482
+ auth: tuple[str, str | None] | None = None,
483
+ auth_bearer: str | None = None,
484
+ timeout: float | None = None,
485
+
486
+ # POST/PUT/PATCH 特定参数
487
+ content: bytes | None = None,
488
+ data: dict[str, Any] | None = None,
489
+ json: Any | None = None,
490
+ files: dict[str, str] | None = None,
491
+ ```
492
+
493
+ </details>
494
+
495
+ <details>
496
+ <summary><b>响应对象</b></summary>
497
+
498
+ ```python
499
+ response.status_code # HTTP 状态码
500
+ response.headers # 响应头
501
+ response.cookies # 响应 Cookie
502
+ response.url # 最终 URL(重定向后)
503
+ response.encoding # 内容编码
504
+
505
+ # 正文访问
506
+ response.text # 文本内容
507
+ response.content # 二进制内容
508
+ response.json() # 解析 JSON
509
+ response.stream() # 流式传输响应正文
510
+
511
+ # HTML 转换
512
+ response.text_markdown # HTML → Markdown
513
+ response.text_plain # HTML → 纯文本
514
+ response.text_rich # HTML → 富文本
515
+ ```
516
+
517
+ </details>
518
+
519
+ <details>
520
+ <summary><b>支持的浏览器</b></summary>
521
+
522
+ #### Chrome (100-141)
523
+ `chrome_100`, `chrome_101`, `chrome_104`, `chrome_105`, `chrome_106`, `chrome_107`, `chrome_108`, `chrome_109`, `chrome_114`, `chrome_116`, `chrome_117`, `chrome_118`, `chrome_119`, `chrome_120`, `chrome_123`, `chrome_124`, `chrome_126`, `chrome_127`, `chrome_128`, `chrome_129`, `chrome_130`, `chrome_131`, `chrome_133`, `chrome_134`, `chrome_135`, `chrome_136`, `chrome_137`, `chrome_138`, `chrome_139`, `chrome_140`, `chrome_141`
524
+
525
+ #### Safari (15.3-26)
526
+ `safari_15.3`, `safari_15.5`, `safari_15.6.1`, `safari_16`, `safari_16.5`, `safari_17.0`, `safari_17.2.1`, `safari_17.4.1`, `safari_17.5`, `safari_18`, `safari_18.2`, `safari_26`, `safari_ios_16.5`, `safari_ios_17.2`, `safari_ios_17.4.1`, `safari_ios_18.1.1`, `safari_ios_26`, `safari_ipad_18`, `safari_ipad_26`
527
+
528
+ #### Firefox (109-143)
529
+ `firefox_109`, `firefox_117`, `firefox_128`, `firefox_133`, `firefox_135`, `firefox_136`, `firefox_139`, `firefox_142`, `firefox_143`
530
+
531
+ #### Edge (101-134)
532
+ `edge_101`, `edge_122`, `edge_127`, `edge_131`, `edge_134`
533
+
534
+ #### OkHttp (3.9-5.0)
535
+ `okhttp_3.9`, `okhttp_3.11`, `okhttp_3.13`, `okhttp_3.14`, `okhttp_4.9`, `okhttp_4.10`, `okhttp_5`
536
+
537
+ #### 操作系统支持
538
+ `windows`, `macos`, `linux`, `android`, `ios`
539
+
540
+ </details>
541
+
542
+ ---
543
+
544
+ ## 💡 示例
545
+
546
+ ### 示例 1:网络爬虫与反爬虫绕过
547
+
548
+ ```python
549
+ import never_primp as primp
550
+
551
+ # 完美的浏览器模拟
552
+ client = primp.Client(
553
+ impersonate="chrome_141",
554
+ impersonate_os="windows",
555
+ headers={
556
+ "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
557
+ "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
558
+ "accept-language": "en-US,en;q=0.9",
559
+ "accept-encoding": "gzip, deflate, br",
560
+ },
561
+ split_cookies=True,
562
+ )
563
+
564
+ response = client.get("https://difficult-site.com")
565
+ print(response.status_code)
566
+ ```
567
+
568
+ ### 示例 2:带认证的 API 集成
569
+
570
+ ```python
571
+ client = primp.Client(
572
+ headers={
573
+ "Content-Type": "application/json",
574
+ "X-API-Version": "v1",
575
+ },
576
+ auth_bearer="your-api-token",
577
+ timeout=30,
578
+ )
579
+
580
+ # GET 请求
581
+ data = client.get("https://api.example.com/users").json()
582
+
583
+ # POST 请求
584
+ response = client.post(
585
+ "https://api.example.com/users",
586
+ json={"name": "John", "email": "john@example.com"}
587
+ )
588
+ ```
589
+
590
+ ### 示例 3:文件上传
591
+
592
+ ```python
593
+ client = primp.Client()
594
+
595
+ files = {
596
+ 'document': '/path/to/document.pdf',
597
+ 'image': '/path/to/image.png'
598
+ }
599
+
600
+ response = client.post(
601
+ "https://example.com/upload",
602
+ files=files,
603
+ data={"description": "My files"}
604
+ )
605
+ ```
606
+
607
+ ### 示例 4:会话管理
608
+
609
+ ```python
610
+ # 自动 Cookie 持久化
611
+ client = primp.Client(cookie_store=True)
612
+
613
+ # 登录
614
+ client.post(
615
+ "https://example.com/login",
616
+ data={"username": "user", "password": "pass"}
617
+ )
618
+
619
+ # 后续请求自动包含会话 Cookie
620
+ profile = client.get("https://example.com/profile")
621
+ ```
622
+
623
+ ### 示例 5:代理使用
624
+
625
+ ```python
626
+ # SOCKS5 代理
627
+ client = primp.Client(proxy="socks5://127.0.0.1:1080")
628
+
629
+ # 带认证的 HTTP 代理
630
+ client = primp.Client(proxy="http://user:pass@proxy.example.com:8080")
631
+
632
+ # 环境变量
633
+ import os
634
+ os.environ['PRIMP_PROXY'] = 'http://127.0.0.1:8080'
635
+ ```
636
+
637
+ ### 示例 6:异步并发请求
638
+
639
+ ```python
640
+ import asyncio
641
+ import never_primp as primp
642
+
643
+ async def fetch_all(urls):
644
+ async with primp.AsyncClient(impersonate="chrome_141") as client:
645
+ tasks = [client.get(url) for url in urls]
646
+ responses = await asyncio.gather(*tasks)
647
+ return [r.text for r in responses]
648
+
649
+ urls = ["https://site1.com", "https://site2.com", "https://site3.com"]
650
+ results = asyncio.run(fetch_all(urls))
651
+ ```
652
+
653
+ ### 示例 7:流式传输大文件
654
+
655
+ ```python
656
+ client = primp.Client()
657
+
658
+ response = client.get("https://example.com/large-file.zip")
659
+
660
+ with open("output.zip", "wb") as f:
661
+ for chunk in response.stream():
662
+ f.write(chunk)
663
+ ```
664
+
665
+ ---
666
+
667
+ ## 🎯 使用场景
668
+
669
+ ### ✅ 完美适用于
670
+
671
+ - **网络爬虫**:绕过反爬虫系统(Cloudflare、Akamai、PerimeterX)
672
+ - **API 测试**:带重试的高性能 API 客户端
673
+ - **数据采集**:带连接池的并发请求
674
+ - **安全研究**:TLS 指纹分析和测试
675
+ - **浏览器自动化替代**:比 Selenium/Playwright 更轻量
676
+
677
+ ### ⚠️ 不适用于
678
+
679
+ - **JavaScript 渲染**:使用 Playwright/Selenium 处理动态内容
680
+ - **浏览器自动化**:无 DOM 操作或 JavaScript 执行
681
+ - **视觉测试**:无截图或渲染功能
682
+
683
+ ---
684
+
685
+ ## 🔬 基准测试
686
+
687
+ ### 顺序请求(连接复用)
688
+
689
+ | 库 | 时间(10 个请求) | 相对速度 |
690
+ |---------|-------------------|----------------|
691
+ | **never_primp** | 1.24s | **1.00x**(基准) |
692
+ | httpx | 1.89s | 0.66x 更慢 |
693
+ | requests | 3.05s | 0.41x 更慢 |
694
+
695
+ ### 并发请求(AsyncClient)
696
+
697
+ | 库 | 时间(100 个请求) | 相对速度 |
698
+ |---------|---------------------|----------------|
699
+ | **never_primp** | 2.15s | **1.00x**(基准) |
700
+ | httpx | 2.83s | 0.76x 更慢 |
701
+ | aiohttp | 2.45s | 0.88x 更慢 |
702
+
703
+ *基准测试环境:Python 3.11, Ubuntu 22.04, AMD Ryzen 9 5900X*
704
+
705
+ ---
706
+
707
+ ## 🛠️ 开发
708
+
709
+ ### 从源码构建
710
+
711
+ ```bash
712
+ # 克隆仓库
713
+ git clone https://github.com/yourusername/never-primp.git
714
+ cd never-primp
715
+
716
+ # 创建虚拟环境
717
+ python -m venv venv
718
+ source venv/bin/activate # Linux/macOS
719
+ # 或
720
+ venv\Scripts\activate # Windows
721
+
722
+ # 安装 maturin(Rust-Python 构建工具)
723
+ pip install maturin
724
+
725
+ # 以开发模式构建和安装
726
+ maturin develop --release
727
+
728
+ # 运行示例
729
+ python examples/example_headers.py
730
+ ```
731
+
732
+ ### 项目结构
733
+
734
+ ```
735
+ never-primp/
736
+ ├── src/
737
+ │ ├── lib.rs # 主要 Rust 实现
738
+ │ ├── traits.rs # 请求头转换 traits
739
+ │ ├── response.rs # 响应处理
740
+ │ ├── impersonate.rs # 浏览器伪装
741
+ │ └── utils.rs # 证书工具
742
+ ├── never_primp/
743
+ │ ├── __init__.py # Python API 包装器
744
+ │ └── never_primp.pyi # 类型提示
745
+ ├── examples/
746
+ │ ├── example_headers.py
747
+ │ └── example_split_cookies.py
748
+ ├── Cargo.toml # Rust 依赖
749
+ └── pyproject.toml # Python 包配置
750
+ ```
751
+
752
+ ---
753
+
754
+ ## 🤝 贡献
755
+
756
+ 欢迎贡献!请随时提交 Pull Request。
757
+
758
+ ### 开发指南
759
+
760
+ 1. 遵循 Rust 最佳实践(src/ 文件)
761
+ 2. 保持 Python 3.8+ 兼容性
762
+ 3. 为新功能添加测试
763
+ 4. 更新文档
764
+
765
+ ---
766
+
767
+ ## 📄 许可证
768
+
769
+ 本项目基于 MIT 许可证 - 详见 [LICENSE](LICENSE) 文件。
770
+
771
+ ---
772
+
773
+ ## ⚠️ 免责声明
774
+
775
+ 本工具仅用于**教育目的**和**合法用例**,例如:
776
+ - 测试您自己的应用程序
777
+ - 学术研究
778
+ - 安全审计(需获得许可)
779
+ - 从公共 API 收集数据
780
+
781
+ **重要提示**:
782
+ - 尊重网站的 `robots.txt` 和服务条款
783
+ - 不要用于恶意目的或未经授权的访问
784
+ - 注意速率限制和服务器资源
785
+ - 作者不对滥用此工具负责
786
+
787
+ 请负责任和道德地使用。🙏
788
+
789
+ ---
790
+
791
+ ## 🙏 致谢
792
+
793
+ 构建基于:
794
+ - [wreq](https://github.com/0x676e67/wreq) - 带浏览器伪装的 Rust HTTP 客户端
795
+ - [PyO3](https://github.com/PyO3/pyo3) - Python 的 Rust 绑定
796
+ - [tokio](https://tokio.rs/) - Rust 异步运行时
797
+
798
+ 灵感来源:
799
+ - [curl-impersonate](https://github.com/lwthiker/curl-impersonate)
800
+ - [httpx](https://github.com/encode/httpx)
801
+ - [requests](https://github.com/psf/requests)
802
+ - [primp](https://github.com/deedy5/primp)
803
+
804
+ ---
805
+
806
+ <div align="center">
807
+
808
+ **用 ❤️ 和 ⚙️ Rust 制作**
809
+
810
+ 如果觉得这个项目有帮助,请给它一个 ⭐!
811
+
812
+ </div>
813
+