3dd1eacfde296b6f0a10af77a1da7d02aa1c0490
Fixes found by the suite:
- timeout error mapping: 'operation timed out' did not match 'timeout' -> exit 7 instead of 28
- invalid --impersonate value now exits 2 (usage error), was falling into connect-error 7
- -F multipart: primp files expects {field: path}; plain form fields via data=
- -j/--json implies POST even with empty body (curl modern semantics)
- -I/--head implies -i (headers shown), matching curl
tests/pcurl-regression.sh: 35 checks covering GET/POST/form/JSON/multipart,
headers, redirects, methods, --fail, TLS, fingerprint UA, env proxy,
error exit codes, flag combining.
primp-patch
One line to route all of your Python HTTP traffic through primp — the rnet-based client with real browser TLS/JA3/JA4 fingerprinting.
import primp_patch
primp_patch.patch()
import requests # unchanged code, primp transport
requests.get("https://example.com")
Why
Libraries and SDKs hard-code requests, urllib3, http.client or urllib. Swapping the HTTP
backend means forking each one. primp-patch instead replaces the transport at runtime, so
existing code — including third-party packages — inherits browser-grade impersonation with zero
source changes.
What gets patched
| Layer | Entry point | Covers |
|---|---|---|
requests |
requests.Session.request |
every requests.get/post/... |
urllib3 |
urllib3.PoolManager.urlopen |
anything built on urllib3 pools |
http.client |
HTTPConnection.request / HTTPSConnection.request |
stdlib HTTPConnection users |
urllib |
urllib.request.urlopen |
urllib.request users |
httpx |
Client._send_single_request (+ async) |
httpx sync & async, openai/anthropic SDKs |
aiohttp |
ClientSession._request |
async clients & scrapers |
Install
pip install primp-patch
# with extras
pip install "primp-patch[all]"
Usage
import primp_patch
primp_patch.patch(proxy="http://host:port") # explicit proxy
# or via environment
# PRIMP_PATCH_PROXY=http://host:port
# or HTTPS_PROXY / HTTP_PROXY
# selective patching
primp_patch.patch(urllib3_=False)
# inspect / revert
primp_patch.is_patched()
primp_patch.unpatch()
Auto-patch on import
export PRIMP_PATCH_AUTO=1
python -c "import primp_patch, requests; print(requests.get('https://example.com').status_code)"
Notes & limitations
stream=True,files=,auth=, customverify/certare not translated (primp has no equivalent); they are silently dropped rather than raising.- Cookie jars are tracked in-process but not persisted.
- Redirect handling is delegated to primp;
allow_redirects=Falseis not honored. - Intended for clients that need anti-bot robustness, not as a drop-in for every edge case.
License
MIT
pcurl — curl 平替(内置 CLI)
v0.2.0 起内置 pcurl:primp 内核的 curl 风格命令行,默认 Chrome TLS/JA3 指纹。
pip install primp-patch # 安装后自带 pcurl 命令
python -m primp_patch.curl ... # 或不经 PATH 直接调用
pcurl https://api.github.com/zen # GET,Chrome 指纹
pcurl -s https://httpbin.org/get # -s 静默(状态行不打 stderr)
pcurl -si https://example.com # -i 含响应头
pcurl -X POST https://httpbin.org/post -d 'a=1&b=2'
pcurl -j https://httpbin.org/post <<< '{"k":"v"}' # JSON 快捷(stdin)
pcurl -o page.html https://example.com # 落盘
pcurl -L -k --max-time 10 --proxy http://127.0.0.1:7890 https://target
pcurl --impersonate firefox https://example.com # 换指纹档位
pcurl --no-fingerprint https://example.com # 不做 TLS 伪装
- 代理默认取
$PRIMP_PATCH_PROXY/$HTTPS_PROXY - 档位(primp 2.x):
chrome_146(默认)、chrome_145、firefox、safari、edge - 退出码对齐 curl:6 解析失败 / 7 连接失败 / 22
--fail时 4xx/5xx / 28 超时
Description
One-line monkeypatch routing Python HTTP stacks (requests/urllib3/http.client/urllib/httpx/aiohttp) through primp - browser TLS/JA3 fingerprint, zero source modification
61 KiB
0 Stars
3 Watchers
0 Forks
Languages
Python
86.7%
Shell
13.3%