never-primp 1.0.0__cp38-abi3-macosx_10_12_x86_64.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.
- never_primp/__init__.py +269 -0
- never_primp/never_primp.abi3.so +0 -0
- never_primp/never_primp.pyi +133 -0
- never_primp/py.typed +0 -0
- never_primp-1.0.0.dist-info/METADATA +358 -0
- never_primp-1.0.0.dist-info/RECORD +8 -0
- never_primp-1.0.0.dist-info/WHEEL +4 -0
- never_primp-1.0.0.dist-info/licenses/LICENSE +21 -0
never_primp/__init__.py
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import sys
|
|
5
|
+
from functools import partial
|
|
6
|
+
from typing import TYPE_CHECKING, TypedDict
|
|
7
|
+
|
|
8
|
+
if sys.version_info <= (3, 11):
|
|
9
|
+
from typing_extensions import Unpack
|
|
10
|
+
else:
|
|
11
|
+
from typing import Unpack
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
from .never_primp import RClient
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from .never_primp import IMPERSONATE, IMPERSONATE_OS, ClientRequestParams, HttpMethod, RequestParams, Response
|
|
18
|
+
else:
|
|
19
|
+
|
|
20
|
+
class _Unpack:
|
|
21
|
+
@staticmethod
|
|
22
|
+
def __getitem__(*args, **kwargs):
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
Unpack = _Unpack()
|
|
26
|
+
RequestParams = ClientRequestParams = TypedDict
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class Client(RClient):
|
|
30
|
+
"""Initializes an HTTP client that can impersonate web browsers."""
|
|
31
|
+
|
|
32
|
+
def __init__(
|
|
33
|
+
self,
|
|
34
|
+
auth: tuple[str, str | None] | None = None,
|
|
35
|
+
auth_bearer: str | None = None,
|
|
36
|
+
params: dict[str, str] | None = None,
|
|
37
|
+
headers: dict[str, str] | None = None,
|
|
38
|
+
cookie_store: bool | None = True,
|
|
39
|
+
referer: bool | None = True,
|
|
40
|
+
proxy: str | None = None,
|
|
41
|
+
timeout: float | None = 30,
|
|
42
|
+
impersonate: IMPERSONATE | None = None,
|
|
43
|
+
impersonate_os: IMPERSONATE_OS | None = None,
|
|
44
|
+
follow_redirects: bool | None = True,
|
|
45
|
+
max_redirects: int | None = 20,
|
|
46
|
+
verify: bool | None = True,
|
|
47
|
+
ca_cert_file: str | None = None,
|
|
48
|
+
https_only: bool | None = False,
|
|
49
|
+
http2_only: bool | None = False,
|
|
50
|
+
# Performance optimization parameters
|
|
51
|
+
pool_idle_timeout: float | None = None,
|
|
52
|
+
pool_max_idle_per_host: int | None = None,
|
|
53
|
+
tcp_nodelay: bool | None = None,
|
|
54
|
+
tcp_keepalive: float | None = None,
|
|
55
|
+
# Retry mechanism
|
|
56
|
+
retry_count: int | None = None,
|
|
57
|
+
retry_backoff: float | None = None,
|
|
58
|
+
):
|
|
59
|
+
"""
|
|
60
|
+
Args:
|
|
61
|
+
auth: a tuple containing the username and an optional password for basic authentication. Default is None.
|
|
62
|
+
auth_bearer: a string representing the bearer token for bearer token authentication. Default is None.
|
|
63
|
+
params: a map of query parameters to append to the URL. Default is None.
|
|
64
|
+
headers: an optional map of HTTP headers to send with requests. Ignored if `impersonate` is set.
|
|
65
|
+
cookie_store: enable a persistent cookie store. Received cookies will be preserved and included
|
|
66
|
+
in additional requests. Default is True.
|
|
67
|
+
referer: automatic setting of the `Referer` header. Default is True.
|
|
68
|
+
proxy: proxy URL for HTTP requests, example: "socks5://127.0.0.1:9150". Default is None.
|
|
69
|
+
timeout: timeout for HTTP requests in seconds. Default is 30.
|
|
70
|
+
impersonate: impersonate browser. Supported browsers:
|
|
71
|
+
"chrome_100", "chrome_101", "chrome_104", "chrome_105", "chrome_106",
|
|
72
|
+
"chrome_107", "chrome_108", "chrome_109", "chrome_114", "chrome_116",
|
|
73
|
+
"chrome_117", "chrome_118", "chrome_119", "chrome_120", "chrome_123",
|
|
74
|
+
"chrome_124", "chrome_126", "chrome_127", "chrome_128", "chrome_129",
|
|
75
|
+
"chrome_130", "chrome_131", "chrome_133"
|
|
76
|
+
"safari_15.3", "safari_15.5", "safari_15.6.1", "safari_16",
|
|
77
|
+
"safari_16.5", "safari_17.0", "safari_17.2.1", "safari_17.4.1",
|
|
78
|
+
"safari_17.5", "safari_18", "safari_18.2",
|
|
79
|
+
"safari_ios_16.5", "safari_ios_17.2", "safari_ios_17.4.1", "safari_ios_18.1.1",
|
|
80
|
+
"safari_ipad_18",
|
|
81
|
+
"okhttp_3.9", "okhttp_3.11", "okhttp_3.13", "okhttp_3.14", "okhttp_4.9",
|
|
82
|
+
"okhttp_4.10", "okhttp_5",
|
|
83
|
+
"edge_101", "edge_122", "edge_127", "edge_131",
|
|
84
|
+
"firefox_109", "firefox_117", "firefox_128", "firefox_133", "firefox_135".
|
|
85
|
+
Default is None.
|
|
86
|
+
impersonate_os: impersonate OS. Supported OS:
|
|
87
|
+
"android", "ios", "linux", "macos", "windows". Default is None.
|
|
88
|
+
follow_redirects: a boolean to enable or disable following redirects. Default is True.
|
|
89
|
+
max_redirects: the maximum number of redirects if `follow_redirects` is True. Default is 20.
|
|
90
|
+
verify: an optional boolean indicating whether to verify SSL certificates. Default is True.
|
|
91
|
+
ca_cert_file: path to CA certificate store. Default is None.
|
|
92
|
+
https_only: restrict the Client to be used with HTTPS only requests. Default is False.
|
|
93
|
+
http2_only: if true - use only HTTP/2, if false - use only HTTP/1. Default is False.
|
|
94
|
+
"""
|
|
95
|
+
super().__init__()
|
|
96
|
+
|
|
97
|
+
def __enter__(self) -> Client:
|
|
98
|
+
return self
|
|
99
|
+
|
|
100
|
+
def __exit__(self, *args):
|
|
101
|
+
del self
|
|
102
|
+
|
|
103
|
+
def request(self, method: HttpMethod, url: str, **kwargs: Unpack[RequestParams]) -> Response:
|
|
104
|
+
return super().request(method=method, url=url, **kwargs)
|
|
105
|
+
|
|
106
|
+
def get(self, url: str, **kwargs: Unpack[RequestParams]) -> Response:
|
|
107
|
+
return self.request(method="GET", url=url, **kwargs)
|
|
108
|
+
|
|
109
|
+
def head(self, url: str, **kwargs: Unpack[RequestParams]) -> Response:
|
|
110
|
+
return self.request(method="HEAD", url=url, **kwargs)
|
|
111
|
+
|
|
112
|
+
def options(self, url: str, **kwargs: Unpack[RequestParams]) -> Response:
|
|
113
|
+
return self.request(method="OPTIONS", url=url, **kwargs)
|
|
114
|
+
|
|
115
|
+
def delete(self, url: str, **kwargs: Unpack[RequestParams]) -> Response:
|
|
116
|
+
return self.request(method="DELETE", url=url, **kwargs)
|
|
117
|
+
|
|
118
|
+
def post(self, url: str, **kwargs: Unpack[RequestParams]) -> Response:
|
|
119
|
+
return self.request(method="POST", url=url, **kwargs)
|
|
120
|
+
|
|
121
|
+
def put(self, url: str, **kwargs: Unpack[RequestParams]) -> Response:
|
|
122
|
+
return self.request(method="PUT", url=url, **kwargs)
|
|
123
|
+
|
|
124
|
+
def patch(self, url: str, **kwargs: Unpack[RequestParams]) -> Response:
|
|
125
|
+
return self.request(method="PATCH", url=url, **kwargs)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class AsyncClient(Client):
|
|
129
|
+
def __init__(self,
|
|
130
|
+
auth: tuple[str, str | None] | None = None,
|
|
131
|
+
auth_bearer: str | None = None,
|
|
132
|
+
params: dict[str, str] | None = None,
|
|
133
|
+
headers: dict[str, str] | None = None,
|
|
134
|
+
cookie_store: bool | None = True,
|
|
135
|
+
referer: bool | None = True,
|
|
136
|
+
proxy: str | None = None,
|
|
137
|
+
timeout: float | None = 30,
|
|
138
|
+
impersonate: IMPERSONATE | None = None,
|
|
139
|
+
impersonate_os: IMPERSONATE_OS | None = None,
|
|
140
|
+
follow_redirects: bool | None = True,
|
|
141
|
+
max_redirects: int | None = 20,
|
|
142
|
+
verify: bool | None = True,
|
|
143
|
+
ca_cert_file: str | None = None,
|
|
144
|
+
https_only: bool | None = False,
|
|
145
|
+
http2_only: bool | None = False,
|
|
146
|
+
# Performance optimization parameters
|
|
147
|
+
pool_idle_timeout: float | None = None,
|
|
148
|
+
pool_max_idle_per_host: int | None = None,
|
|
149
|
+
tcp_nodelay: bool | None = None,
|
|
150
|
+
tcp_keepalive: float | None = None,
|
|
151
|
+
# Retry mechanism
|
|
152
|
+
retry_count: int | None = None,
|
|
153
|
+
retry_backoff: float | None = None):
|
|
154
|
+
super().__init__()
|
|
155
|
+
|
|
156
|
+
async def __aenter__(self) -> AsyncClient:
|
|
157
|
+
return self
|
|
158
|
+
|
|
159
|
+
async def __aexit__(self, *args):
|
|
160
|
+
del self
|
|
161
|
+
|
|
162
|
+
async def _run_sync_asyncio(self, fn, *args, **kwargs):
|
|
163
|
+
loop = asyncio.get_running_loop()
|
|
164
|
+
return await loop.run_in_executor(None, partial(fn, *args, **kwargs))
|
|
165
|
+
|
|
166
|
+
async def request(self, method: HttpMethod, url: str, **kwargs: Unpack[RequestParams]): # type: ignore
|
|
167
|
+
return await self._run_sync_asyncio(super().request, method=method, url=url, **kwargs)
|
|
168
|
+
|
|
169
|
+
async def get(self, url: str, **kwargs: Unpack[RequestParams]): # type: ignore
|
|
170
|
+
return await self.request(method="GET", url=url, **kwargs)
|
|
171
|
+
|
|
172
|
+
async def head(self, url: str, **kwargs: Unpack[RequestParams]): # type: ignore
|
|
173
|
+
return await self.request(method="HEAD", url=url, **kwargs)
|
|
174
|
+
|
|
175
|
+
async def options(self, url: str, **kwargs: Unpack[RequestParams]): # type: ignore
|
|
176
|
+
return await self.request(method="OPTIONS", url=url, **kwargs)
|
|
177
|
+
|
|
178
|
+
async def delete(self, url: str, **kwargs: Unpack[RequestParams]): # type: ignore
|
|
179
|
+
return await self.request(method="DELETE", url=url, **kwargs)
|
|
180
|
+
|
|
181
|
+
async def post(self, url: str, **kwargs: Unpack[RequestParams]): # type: ignore
|
|
182
|
+
return await self.request(method="POST", url=url, **kwargs)
|
|
183
|
+
|
|
184
|
+
async def put(self, url: str, **kwargs: Unpack[RequestParams]): # type: ignore
|
|
185
|
+
return await self.request(method="PUT", url=url, **kwargs)
|
|
186
|
+
|
|
187
|
+
async def patch(self, url: str, **kwargs: Unpack[RequestParams]): # type: ignore
|
|
188
|
+
return await self.request(method="PATCH", url=url, **kwargs)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def request(
|
|
192
|
+
method: HttpMethod,
|
|
193
|
+
url: str,
|
|
194
|
+
impersonate: IMPERSONATE | None = None,
|
|
195
|
+
impersonate_os: IMPERSONATE_OS | None = None,
|
|
196
|
+
verify: bool | None = True,
|
|
197
|
+
ca_cert_file: str | None = None,
|
|
198
|
+
**kwargs: Unpack[RequestParams],
|
|
199
|
+
):
|
|
200
|
+
"""
|
|
201
|
+
Args:
|
|
202
|
+
method: the HTTP method to use (e.g., "GET", "POST").
|
|
203
|
+
url: the URL to which the request will be made.
|
|
204
|
+
impersonate: impersonate browser. Supported browsers:
|
|
205
|
+
"chrome_100", "chrome_101", "chrome_104", "chrome_105", "chrome_106",
|
|
206
|
+
"chrome_107", "chrome_108", "chrome_109", "chrome_114", "chrome_116",
|
|
207
|
+
"chrome_117", "chrome_118", "chrome_119", "chrome_120", "chrome_123",
|
|
208
|
+
"chrome_124", "chrome_126", "chrome_127", "chrome_128", "chrome_129",
|
|
209
|
+
"chrome_130", "chrome_131", "chrome_133",
|
|
210
|
+
"safari_15.3", "safari_15.5", "safari_15.6.1", "safari_16",
|
|
211
|
+
"safari_16.5", "safari_17.0", "safari_17.2.1", "safari_17.4.1",
|
|
212
|
+
"safari_17.5", "safari_18", "safari_18.2",
|
|
213
|
+
"safari_ios_16.5", "safari_ios_17.2", "safari_ios_17.4.1", "safari_ios_18.1.1",
|
|
214
|
+
"safari_ipad_18",
|
|
215
|
+
"okhttp_3.9", "okhttp_3.11", "okhttp_3.13", "okhttp_3.14", "okhttp_4.9",
|
|
216
|
+
"okhttp_4.10", "okhttp_5",
|
|
217
|
+
"edge_101", "edge_122", "edge_127", "edge_131",
|
|
218
|
+
"firefox_109", "firefox_117", "firefox_128", "firefox_133", "firefox_135".
|
|
219
|
+
Default is None.
|
|
220
|
+
impersonate_os: impersonate OS. Supported OS:
|
|
221
|
+
"android", "ios", "linux", "macos", "windows". Default is None.
|
|
222
|
+
verify: an optional boolean indicating whether to verify SSL certificates. Default is True.
|
|
223
|
+
ca_cert_file: path to CA certificate store. Default is None.
|
|
224
|
+
auth: a tuple containing the username and an optional password for basic authentication. Default is None.
|
|
225
|
+
auth_bearer: a string representing the bearer token for bearer token authentication. Default is None.
|
|
226
|
+
params: a map of query parameters to append to the URL. Default is None.
|
|
227
|
+
headers: an optional map of HTTP headers to send with requests. If `impersonate` is set, this will be ignored.
|
|
228
|
+
cookies: an optional map of cookies to send with requests as the `Cookie` header.
|
|
229
|
+
timeout: the timeout for the request in seconds. Default is 30.
|
|
230
|
+
content: the content to send in the request body as bytes. Default is None.
|
|
231
|
+
data: the form data to send in the request body. Default is None.
|
|
232
|
+
json: a JSON serializable object to send in the request body. Default is None.
|
|
233
|
+
files: a map of file fields to file paths to be sent as multipart/form-data. Default is None.
|
|
234
|
+
"""
|
|
235
|
+
with Client(
|
|
236
|
+
impersonate=impersonate,
|
|
237
|
+
impersonate_os=impersonate_os,
|
|
238
|
+
verify=verify,
|
|
239
|
+
ca_cert_file=ca_cert_file,
|
|
240
|
+
) as client:
|
|
241
|
+
return client.request(method, url, **kwargs)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def get(url: str, **kwargs: Unpack[ClientRequestParams]):
|
|
245
|
+
return request(method="GET", url=url, **kwargs)
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def head(url: str, **kwargs: Unpack[ClientRequestParams]):
|
|
249
|
+
return request(method="HEAD", url=url, **kwargs)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def options(url: str, **kwargs: Unpack[ClientRequestParams]):
|
|
253
|
+
return request(method="OPTIONS", url=url, **kwargs)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def delete(url: str, **kwargs: Unpack[ClientRequestParams]):
|
|
257
|
+
return request(method="DELETE", url=url, **kwargs)
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def post(url: str, **kwargs: Unpack[ClientRequestParams]):
|
|
261
|
+
return request(method="POST", url=url, **kwargs)
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def put(url: str, **kwargs: Unpack[ClientRequestParams]):
|
|
265
|
+
return request(method="PUT", url=url, **kwargs)
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def patch(url: str, **kwargs: Unpack[ClientRequestParams]):
|
|
269
|
+
return request(method="PATCH", url=url, **kwargs)
|
|
Binary file
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from typing import Any, Iterator, Literal, TypedDict
|
|
5
|
+
|
|
6
|
+
if sys.version_info <= (3, 11):
|
|
7
|
+
from typing_extensions import Unpack
|
|
8
|
+
else:
|
|
9
|
+
from typing import Unpack
|
|
10
|
+
|
|
11
|
+
HttpMethod = Literal["GET", "HEAD", "OPTIONS", "DELETE", "POST", "PUT", "PATCH"]
|
|
12
|
+
IMPERSONATE = Literal[
|
|
13
|
+
"chrome_100", "chrome_101", "chrome_104", "chrome_105", "chrome_106",
|
|
14
|
+
"chrome_107", "chrome_108", "chrome_109", "chrome_114", "chrome_116",
|
|
15
|
+
"chrome_117", "chrome_118", "chrome_119", "chrome_120", "chrome_123",
|
|
16
|
+
"chrome_124", "chrome_126", "chrome_127", "chrome_128", "chrome_129",
|
|
17
|
+
"chrome_130", "chrome_131", "chrome_133", "chrome_134", "chrome_135",
|
|
18
|
+
"chrome_136", "chrome_137", "chrome_138", "chrome_139",
|
|
19
|
+
"chrome_140","chrome_141",
|
|
20
|
+
"safari_15.3", "safari_15.5", "safari_15.6.1", "safari_16",
|
|
21
|
+
"safari_16.5", "safari_17.0", "safari_17.2.1", "safari_17.4.1",
|
|
22
|
+
"safari_17.5", "safari_18", "safari_18.2","safari_18.3","safari_18.3.1","safari_18.5",
|
|
23
|
+
"safari_ios_16.5", "safari_ios_17.2", "safari_ios_17.4.1", "safari_ios_18.1.1",
|
|
24
|
+
"safari_ipad_18","safari_26","safari_ipad_26","safari_ios_26",
|
|
25
|
+
"okhttp_3.9", "okhttp_3.11", "okhttp_3.13", "okhttp_3.14", "okhttp_4.9",
|
|
26
|
+
"okhttp_4.10", "okhttp_4.12","okhttp_5",
|
|
27
|
+
"edge_101", "edge_122", "edge_127", "edge_131","edge_134",
|
|
28
|
+
"opera_116", "opera_117", "opera_118", "opera_119",
|
|
29
|
+
"firefox_109", "firefox_117", "firefox_128", "firefox_133", "firefox_135",
|
|
30
|
+
"firefox_136", "firefox_139", "firefox_142", "firefox_143", "firefox_android_135",
|
|
31
|
+
"firefox_private_135", "firefox_private_136",
|
|
32
|
+
"random",
|
|
33
|
+
] # fmt: skip
|
|
34
|
+
IMPERSONATE_OS = Literal["android", "ios", "linux", "macos", "windows", "random"]
|
|
35
|
+
|
|
36
|
+
class RequestParams(TypedDict, total=False):
|
|
37
|
+
auth: tuple[str, str | None] | None
|
|
38
|
+
auth_bearer: str | None
|
|
39
|
+
params: dict[str, str] | None
|
|
40
|
+
headers: dict[str, str] | None
|
|
41
|
+
cookies: dict[str, str] | None
|
|
42
|
+
timeout: float | None
|
|
43
|
+
content: bytes | None
|
|
44
|
+
data: dict[str, Any] | None
|
|
45
|
+
json: Any | None
|
|
46
|
+
files: dict[str, str] | None
|
|
47
|
+
|
|
48
|
+
class ClientRequestParams(RequestParams):
|
|
49
|
+
impersonate: IMPERSONATE | None
|
|
50
|
+
impersonate_os: IMPERSONATE_OS | None
|
|
51
|
+
verify: bool | None
|
|
52
|
+
ca_cert_file: str | None
|
|
53
|
+
|
|
54
|
+
class Response:
|
|
55
|
+
@property
|
|
56
|
+
def content(self) -> bytes: ...
|
|
57
|
+
@property
|
|
58
|
+
def cookies(self) -> dict[str, str]: ...
|
|
59
|
+
@property
|
|
60
|
+
def headers(self) -> dict[str, str]: ...
|
|
61
|
+
@property
|
|
62
|
+
def status_code(self) -> int: ...
|
|
63
|
+
@property
|
|
64
|
+
def url(self) -> str: ...
|
|
65
|
+
@property
|
|
66
|
+
def encoding(self) -> str: ...
|
|
67
|
+
@property
|
|
68
|
+
def text(self) -> str: ...
|
|
69
|
+
def json(self) -> Any: ...
|
|
70
|
+
def stream(self) -> Iterator[bytes]: ...
|
|
71
|
+
@property
|
|
72
|
+
def text_markdown(self) -> str: ...
|
|
73
|
+
@property
|
|
74
|
+
def text_plain(self) -> str: ...
|
|
75
|
+
@property
|
|
76
|
+
def text_rich(self) -> str: ...
|
|
77
|
+
|
|
78
|
+
class RClient:
|
|
79
|
+
def __init__(
|
|
80
|
+
self,
|
|
81
|
+
auth: tuple[str, str | None] | None = None,
|
|
82
|
+
auth_bearer: str | None = None,
|
|
83
|
+
params: dict[str, str] | None = None,
|
|
84
|
+
headers: dict[str, str] | None = None,
|
|
85
|
+
timeout: float | None = None,
|
|
86
|
+
cookie_store: bool | None = True,
|
|
87
|
+
referer: bool | None = True,
|
|
88
|
+
proxy: str | None = None,
|
|
89
|
+
impersonate: IMPERSONATE | None = None,
|
|
90
|
+
impersonate_os: IMPERSONATE_OS | None = None,
|
|
91
|
+
follow_redirects: bool | None = True,
|
|
92
|
+
max_redirects: int | None = 20,
|
|
93
|
+
verify: bool | None = True,
|
|
94
|
+
ca_cert_file: str | None = None,
|
|
95
|
+
https_only: bool | None = False,
|
|
96
|
+
http2_only: bool | None = False,
|
|
97
|
+
): ...
|
|
98
|
+
@property
|
|
99
|
+
def headers(self) -> dict[str, str]: ...
|
|
100
|
+
@headers.setter
|
|
101
|
+
def headers(self, headers: dict[str, str]) -> None: ...
|
|
102
|
+
def headers_update(self, headers: dict[str, str]) -> None: ...
|
|
103
|
+
def get_cookies(self, url: str) -> dict[str, str]: ...
|
|
104
|
+
def set_cookies(self, url: str, cookies: dict[str, str]) -> None: ...
|
|
105
|
+
@property
|
|
106
|
+
def proxy(self) -> str | None: ...
|
|
107
|
+
@proxy.setter
|
|
108
|
+
def proxy(self, proxy: str) -> None: ...
|
|
109
|
+
@property
|
|
110
|
+
def impersonate(self) -> str | None: ...
|
|
111
|
+
@impersonate.setter
|
|
112
|
+
def impersonate(self, impersonate: IMPERSONATE) -> None: ...
|
|
113
|
+
@property
|
|
114
|
+
def impersonate_os(self) -> str | None: ...
|
|
115
|
+
@impersonate_os.setter
|
|
116
|
+
def impersonate_os(self, impersonate: IMPERSONATE_OS) -> None: ...
|
|
117
|
+
def request(self, method: HttpMethod, url: str, **kwargs: Unpack[RequestParams]) -> Response: ...
|
|
118
|
+
def get(self, url: str, **kwargs: Unpack[RequestParams]) -> Response: ...
|
|
119
|
+
def head(self, url: str, **kwargs: Unpack[RequestParams]) -> Response: ...
|
|
120
|
+
def options(self, url: str, **kwargs: Unpack[RequestParams]) -> Response: ...
|
|
121
|
+
def delete(self, url: str, **kwargs: Unpack[RequestParams]) -> Response: ...
|
|
122
|
+
def post(self, url: str, **kwargs: Unpack[RequestParams]) -> Response: ...
|
|
123
|
+
def put(self, url: str, **kwargs: Unpack[RequestParams]) -> Response: ...
|
|
124
|
+
def patch(self, url: str, **kwargs: Unpack[RequestParams]) -> Response: ...
|
|
125
|
+
|
|
126
|
+
def request(method: HttpMethod, url: str, **kwargs: Unpack[ClientRequestParams]) -> Response: ...
|
|
127
|
+
def get(url: str, **kwargs: Unpack[ClientRequestParams]) -> Response: ...
|
|
128
|
+
def head(url: str, **kwargs: Unpack[ClientRequestParams]) -> Response: ...
|
|
129
|
+
def options(url: str, **kwargs: Unpack[ClientRequestParams]) -> Response: ...
|
|
130
|
+
def delete(url: str, **kwargs: Unpack[ClientRequestParams]) -> Response: ...
|
|
131
|
+
def post(url: str, **kwargs: Unpack[ClientRequestParams]) -> Response: ...
|
|
132
|
+
def put(url: str, **kwargs: Unpack[ClientRequestParams]) -> Response: ...
|
|
133
|
+
def patch(url: str, **kwargs: Unpack[ClientRequestParams]) -> Response: ...
|
never_primp/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: never_primp
|
|
3
|
+
Version: 1.0.0
|
|
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
|
+
 [](https://github.com/deedy5/pyreqwest-impersonate/releases) [](https://pypi.org/project/primp) [](https://pepy.tech/project/primp) [](https://github.com/deedy5/pyreqwest-impersonate/actions/workflows/CI.yml)
|
|
29
|
+
# 🪞NEVER_PRIMP
|
|
30
|
+
**🪞NEVER_PRIMP** = **P**ython **R**equests **IMP**ersonate
|
|
31
|
+
|
|
32
|
+
The fastest python HTTP client that can impersonate web browsers.</br>
|
|
33
|
+
Provides precompiled wheels:</br>
|
|
34
|
+
* 🐧 linux: `amd64`, `aarch64`, `armv7` (⚠️aarch64 and armv7 builds are `manylinux_2_34` compatible - `ubuntu>=22.04`, `debian>=12`);</br>
|
|
35
|
+
* 🐧 musllinux: `amd64`, `aarch64`;</br>
|
|
36
|
+
* 🪟 windows: `amd64`;</br>
|
|
37
|
+
* 🍏 macos: `amd64`, `aarch64`.</br>
|
|
38
|
+
|
|
39
|
+
## Table of Contents
|
|
40
|
+
|
|
41
|
+
- [Installation](#installation)
|
|
42
|
+
- [Key Features](#key-features)
|
|
43
|
+
- [Benchmark](#benchmark)
|
|
44
|
+
- [Usage](#usage)
|
|
45
|
+
- [I. Client](#i-client)
|
|
46
|
+
- [Client methods](#client-methods)
|
|
47
|
+
- [Response object](#response-object)
|
|
48
|
+
- [Devices](#devices)
|
|
49
|
+
- [Examples](#examples)
|
|
50
|
+
- [II. AsyncClient](#ii-asyncclient)
|
|
51
|
+
- [Disclaimer](#disclaimer)
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
pip install -U never_primp
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Key Features
|
|
60
|
+
|
|
61
|
+
🚀 **Performance Optimized**
|
|
62
|
+
- Connection pooling with configurable idle timeout and max connections per host
|
|
63
|
+
- TCP optimization (TCP_NODELAY, TCP keepalive)
|
|
64
|
+
- ~59% faster for sequential requests with connection reuse
|
|
65
|
+
|
|
66
|
+
🔒 **Advanced Certificate Management**
|
|
67
|
+
- Uses system's native certificate store (auto-updated with OS)
|
|
68
|
+
- No more certificate expiration issues
|
|
69
|
+
- Custom CA bundle support
|
|
70
|
+
|
|
71
|
+
🍪 **Smart Cookie Management**
|
|
72
|
+
- Automatic cookie persistence using wreq's native Jar API
|
|
73
|
+
- Manual cookie control with `get_cookies()` / `set_cookies()`
|
|
74
|
+
- Cookies survive client configuration changes
|
|
75
|
+
|
|
76
|
+
⚙️ **Dynamic Configuration**
|
|
77
|
+
- Modify headers, proxy, and impersonation at runtime
|
|
78
|
+
- No need to recreate the client
|
|
79
|
+
- Thread-safe configuration updates
|
|
80
|
+
|
|
81
|
+
🔄 **Retry Mechanism**
|
|
82
|
+
- Configurable retry count and backoff timing
|
|
83
|
+
- Handle transient failures gracefully
|
|
84
|
+
|
|
85
|
+
🎭 **Browser Impersonation**
|
|
86
|
+
- Impersonate Chrome, Safari, Edge, Firefox, OkHttp
|
|
87
|
+
- Mimic TLS/JA3/JA4/HTTP2 fingerprints
|
|
88
|
+
- Custom OS impersonation (Windows, macOS, Linux, Android, iOS)
|
|
89
|
+
|
|
90
|
+
## Usage
|
|
91
|
+
### I. Client
|
|
92
|
+
|
|
93
|
+
HTTP client that can impersonate web browsers.
|
|
94
|
+
```python
|
|
95
|
+
class Client:
|
|
96
|
+
"""Initializes an HTTP client that can impersonate web browsers.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
auth (tuple[str, str| None] | None): Username and password for basic authentication. Default is None.
|
|
100
|
+
auth_bearer (str | None): Bearer token for authentication. Default is None.
|
|
101
|
+
params (dict[str, str] | None): Default query parameters to include in all requests. Default is None.
|
|
102
|
+
headers (dict[str, str] | None): Default headers to send with requests. If `impersonate` is set, this will be ignored.
|
|
103
|
+
timeout (float | None): HTTP request timeout in seconds. Default is 30.
|
|
104
|
+
cookie_store (bool | None): Enable a persistent cookie store. Received cookies will be preserved and included
|
|
105
|
+
in additional requests. Default is True.
|
|
106
|
+
referer (bool | None): Enable or disable automatic setting of the `Referer` header. Default is True.
|
|
107
|
+
proxy (str | None): Proxy URL for HTTP requests. Example: "socks5://127.0.0.1:9150". Default is None.
|
|
108
|
+
impersonate (str | None): Entity to impersonate. Example: "chrome_124". Default is None.
|
|
109
|
+
Chrome: "chrome_100","chrome_101","chrome_104","chrome_105","chrome_106","chrome_107","chrome_108",
|
|
110
|
+
"chrome_109","chrome_114","chrome_116","chrome_117","chrome_118","chrome_119","chrome_120",
|
|
111
|
+
"chrome_123","chrome_124","chrome_126","chrome_127","chrome_128","chrome_129","chrome_130",
|
|
112
|
+
"chrome_131","chrome_133"
|
|
113
|
+
Safari: "safari_ios_16.5","safari_ios_17.2","safari_ios_17.4.1","safari_ios_18.1.1",
|
|
114
|
+
"safari_15.3","safari_15.5","safari_15.6.1","safari_16","safari_16.5","safari_17.0",
|
|
115
|
+
"safari_17.2.1","safari_17.4.1","safari_17.5","safari_18","safari_18.2","safari_ipad_18"
|
|
116
|
+
OkHttp: "okhttp_3.9","okhttp_3.11","okhttp_3.13","okhttp_3.14","okhttp_4.9","okhttp_4.10","okhttp_5"
|
|
117
|
+
Edge: "edge_101","edge_122","edge_127","edge_131"
|
|
118
|
+
Firefox: "firefox_109","firefox_117","firefox_128","firefox_133","firefox_135"
|
|
119
|
+
Select random: "random"
|
|
120
|
+
impersonate_os (str | None): impersonate OS. Example: "windows". Default is "linux".
|
|
121
|
+
Android: "android", iOS: "ios", Linux: "linux", Mac OS: "macos", Windows: "windows"
|
|
122
|
+
Select random: "random"
|
|
123
|
+
follow_redirects (bool | None): Whether to follow redirects. Default is True.
|
|
124
|
+
max_redirects (int | None): Maximum redirects to follow. Default 20. Applies if `follow_redirects` is True.
|
|
125
|
+
verify (bool | None): Verify SSL certificates. Default is True.
|
|
126
|
+
ca_cert_file (str | None): Path to CA certificate store. Default is None.
|
|
127
|
+
https_only (bool | None): Restrict the Client to be used with HTTPS only requests. Default is False.
|
|
128
|
+
http2_only (bool | None): If true - use only HTTP/2; if false - use only HTTP/1. Default is False.
|
|
129
|
+
pool_idle_timeout (float | None): Connection pool idle timeout in seconds. Default is None.
|
|
130
|
+
pool_max_idle_per_host (int | None): Maximum number of idle connections per host. Default is None.
|
|
131
|
+
tcp_nodelay (bool | None): Enable TCP_NODELAY (disable Nagle's algorithm). Default is None.
|
|
132
|
+
tcp_keepalive (float | None): TCP keepalive interval in seconds. Default is None.
|
|
133
|
+
retry_count (int | None): Maximum number of retry attempts. Default is None.
|
|
134
|
+
retry_backoff (float | None): Backoff time between retries in seconds. Default is None.
|
|
135
|
+
|
|
136
|
+
"""
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
#### Client methods
|
|
140
|
+
|
|
141
|
+
The `Client` class provides a set of methods for making HTTP requests: `get`, `head`, `options`, `delete`, `post`, `put`, `patch`, each of which internally utilizes the `request()` method for execution. The parameters for these methods closely resemble those in `httpx`.
|
|
142
|
+
```python
|
|
143
|
+
def get(
|
|
144
|
+
url: str,
|
|
145
|
+
params: dict[str, str] | None = None,
|
|
146
|
+
headers: dict[str, str] | None = None,
|
|
147
|
+
cookies: dict[str, str] | None = None,
|
|
148
|
+
auth: tuple[str, str| None] | None = None,
|
|
149
|
+
auth_bearer: str | None = None,
|
|
150
|
+
timeout: float | None = 30,
|
|
151
|
+
):
|
|
152
|
+
"""Performs a GET request to the specified URL.
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
url (str): The URL to which the request will be made.
|
|
156
|
+
params (dict[str, str] | None): A map of query parameters to append to the URL. Default is None.
|
|
157
|
+
headers (dict[str, str] | None): A map of HTTP headers to send with the request. Default is None.
|
|
158
|
+
cookies (dict[str, str] | None): - An optional map of cookies to send with requests as the `Cookie` header.
|
|
159
|
+
auth (tuple[str, str| None] | None): A tuple containing the username and an optional password
|
|
160
|
+
for basic authentication. Default is None.
|
|
161
|
+
auth_bearer (str | None): A string representing the bearer token for bearer token authentication. Default is None.
|
|
162
|
+
timeout (float | None): The timeout for the request in seconds. Default is 30.
|
|
163
|
+
|
|
164
|
+
"""
|
|
165
|
+
```
|
|
166
|
+
```python
|
|
167
|
+
def post(
|
|
168
|
+
url: str,
|
|
169
|
+
params: dict[str, str] | None = None,
|
|
170
|
+
headers: dict[str, str] | None = None,
|
|
171
|
+
cookies: dict[str, str] | None = None,
|
|
172
|
+
content: bytes | None = None,
|
|
173
|
+
data: dict[str, Any] | None = None,
|
|
174
|
+
json: Any | None = None,
|
|
175
|
+
files: dict[str, str] | None = None,
|
|
176
|
+
auth: tuple[str, str| None] | None = None,
|
|
177
|
+
auth_bearer: str | None = None,
|
|
178
|
+
timeout: float | None = 30,
|
|
179
|
+
):
|
|
180
|
+
"""Performs a POST request to the specified URL.
|
|
181
|
+
|
|
182
|
+
Args:
|
|
183
|
+
url (str): The URL to which the request will be made.
|
|
184
|
+
params (dict[str, str] | None): A map of query parameters to append to the URL. Default is None.
|
|
185
|
+
headers (dict[str, str] | None): A map of HTTP headers to send with the request. Default is None.
|
|
186
|
+
cookies (dict[str, str] | None): - An optional map of cookies to send with requests as the `Cookie` header.
|
|
187
|
+
content (bytes | None): The content to send in the request body as bytes. Default is None.
|
|
188
|
+
data (dict[str, Any] | None): The form data to send in the request body. Default is None.
|
|
189
|
+
json (Any | None): A JSON serializable object to send in the request body. Default is None.
|
|
190
|
+
files (dict[str, str] | None): A map of file fields to file paths to be sent as multipart/form-data. Default is None.
|
|
191
|
+
auth (tuple[str, str| None] | None): A tuple containing the username and an optional password
|
|
192
|
+
for basic authentication. Default is None.
|
|
193
|
+
auth_bearer (str | None): A string representing the bearer token for bearer token authentication. Default is None.
|
|
194
|
+
timeout (float | None): The timeout for the request in seconds. Default is 30.
|
|
195
|
+
|
|
196
|
+
"""
|
|
197
|
+
```
|
|
198
|
+
#### Response object
|
|
199
|
+
```python
|
|
200
|
+
resp.content
|
|
201
|
+
resp.stream() # stream the response body in chunks of bytes
|
|
202
|
+
resp.cookies
|
|
203
|
+
resp.encoding
|
|
204
|
+
resp.headers
|
|
205
|
+
resp.json()
|
|
206
|
+
resp.status_code
|
|
207
|
+
resp.text
|
|
208
|
+
resp.text_markdown # html is converted to markdown text
|
|
209
|
+
resp.text_plain # html is converted to plain text
|
|
210
|
+
resp.text_rich # html is converted to rich text
|
|
211
|
+
resp.url
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
#### Devices
|
|
215
|
+
|
|
216
|
+
##### Impersonate
|
|
217
|
+
|
|
218
|
+
- Chrome: `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`
|
|
219
|
+
|
|
220
|
+
- Edge: `edge_101`,`edge_122`,`edge_127`, `edge_131`, `edge_134`
|
|
221
|
+
|
|
222
|
+
- Safari: `safari_ios_17.2`,`safari_ios_17.4.1`,`safari_ios_16.5`,`safari_ios_18.1.1`, `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_ipad_18`, `safari_ipad_26`, `safari_ios_26`, `safari_26`
|
|
223
|
+
|
|
224
|
+
- OkHttp: `okhttp_3.9`,`okhttp_3.11`,`okhttp_3.13`,`okhttp_3.14`,`okhttp_4.9`,`okhttp_4.10`,`okhttp_5`
|
|
225
|
+
|
|
226
|
+
- Firefox: `firefox_109`, `firefox_117`, `firefox_128`, `firefox_133`, `firefox_135`, `firefox_136`, `firefox_139`, `firefox_142`, `firefox_143`
|
|
227
|
+
|
|
228
|
+
##### Impersonate OS
|
|
229
|
+
|
|
230
|
+
- `android`, `ios`, `linux`, `macos`, `windows`
|
|
231
|
+
|
|
232
|
+
#### Examples
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
import never_primp as primp
|
|
236
|
+
|
|
237
|
+
# Impersonate
|
|
238
|
+
client = primp.Client(impersonate="chrome_131", impersonate_os="windows")
|
|
239
|
+
|
|
240
|
+
# Performance optimization with connection pooling
|
|
241
|
+
client = primp.Client(
|
|
242
|
+
impersonate="chrome_131",
|
|
243
|
+
pool_idle_timeout=90.0, # Keep connections alive for 90 seconds
|
|
244
|
+
pool_max_idle_per_host=10, # Max 10 idle connections per host
|
|
245
|
+
tcp_nodelay=True, # Disable Nagle's algorithm for lower latency
|
|
246
|
+
tcp_keepalive=60.0, # TCP keepalive every 60 seconds
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
# Retry mechanism
|
|
250
|
+
client = primp.Client(
|
|
251
|
+
retry_count=3, # Retry up to 3 times
|
|
252
|
+
retry_backoff=1.0, # 1 second backoff between retries
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
# Dynamic configuration updates
|
|
256
|
+
client.headers = {"User-Agent": "Custom User Agent"} # Update all headers
|
|
257
|
+
client.headers_update({"Referer": "https://example.com"}) # Merge new headers
|
|
258
|
+
client.proxy = "http://127.0.0.1:8080" # Change proxy
|
|
259
|
+
client.impersonate = "chrome_133" # Change browser impersonation
|
|
260
|
+
client.impersonate_os = "macos" # Change OS impersonation
|
|
261
|
+
|
|
262
|
+
# GET request
|
|
263
|
+
resp = client.get("https://tls.peet.ws/api/all")
|
|
264
|
+
|
|
265
|
+
# GET request with passing params and setting timeout
|
|
266
|
+
params = {"param1": "value1", "param2": "value2"}
|
|
267
|
+
resp = client.post(url="https://httpbin.org/anything", params=params, timeout=10)
|
|
268
|
+
|
|
269
|
+
# Stream response
|
|
270
|
+
resp = client.get("https://nytimes")
|
|
271
|
+
for chunk in resp.stream():
|
|
272
|
+
print(chunk)
|
|
273
|
+
|
|
274
|
+
# Cookie management - Automatic (recommended)
|
|
275
|
+
client = primp.Client(cookie_store=True) # Default: enabled
|
|
276
|
+
resp = client.get("https://httpbin.org/cookies/set?session=abc123")
|
|
277
|
+
# Cookies are automatically stored and sent in subsequent requests
|
|
278
|
+
resp2 = client.get("https://httpbin.org/cookies") # Session cookie automatically included
|
|
279
|
+
|
|
280
|
+
# Cookie management - Manual
|
|
281
|
+
cookies = {"c1_n": "c1_value", "c2_n": "c2_value"}
|
|
282
|
+
client.set_cookies(url="https://nytimes.com", cookies=cookies) # Set cookies for a specific domain
|
|
283
|
+
resp = client.get("https://nytimes.com/", cookies=cookies) # Or pass cookies in request
|
|
284
|
+
|
|
285
|
+
# Get cookies
|
|
286
|
+
all_cookies = client.get_cookies(url="https://nytimes.com") # Get all cookies from jar
|
|
287
|
+
response_cookies = resp.cookies # Get cookies from response
|
|
288
|
+
|
|
289
|
+
# POST Binary Request Data
|
|
290
|
+
content = b"some_data"
|
|
291
|
+
resp = client.post(url="https://httpbin.org/anything", content=content)
|
|
292
|
+
|
|
293
|
+
# POST Form Encoded Data
|
|
294
|
+
data = {"key1": "value1", "key2": "value2"}
|
|
295
|
+
resp = client.post(url="https://httpbin.org/anything", data=data)
|
|
296
|
+
|
|
297
|
+
# POST JSON Encoded Data
|
|
298
|
+
json = {"key1": "value1", "key2": "value2"}
|
|
299
|
+
resp = client.post(url="https://httpbin.org/anything", json=json)
|
|
300
|
+
|
|
301
|
+
# POST Multipart-Encoded Files
|
|
302
|
+
files = {'file1': '/home/root/file1.txt', 'file2': 'home/root/file2.txt'}
|
|
303
|
+
resp = client.post("https://httpbin.org/post", files=files)
|
|
304
|
+
|
|
305
|
+
# Authentication using user/password
|
|
306
|
+
resp = client.post(url="https://httpbin.org/anything", auth=("user", "password"))
|
|
307
|
+
|
|
308
|
+
# Authentication using auth bearer
|
|
309
|
+
resp = client.post(url="https://httpbin.org/anything", auth_bearer="bearerXXXXXXXXXXXXXXXXXXXX")
|
|
310
|
+
|
|
311
|
+
# Using proxy or env var PRIMP_PROXY
|
|
312
|
+
resp = primp.Client(proxy="http://127.0.0.1:8080") # set proxy in Client
|
|
313
|
+
export PRIMP_PROXY="socks5://127.0.0.1:1080" # set proxy as environment variable
|
|
314
|
+
|
|
315
|
+
# SSL/TLS certificate verification
|
|
316
|
+
# Note: Primp uses your system's native certificate store by default (auto-updated with OS)
|
|
317
|
+
resp = primp.Client(verify=True) # Default: uses system certificates
|
|
318
|
+
|
|
319
|
+
# Using custom CA certificate store:
|
|
320
|
+
resp = primp.Client(ca_cert_file="/cert/cacert.pem")
|
|
321
|
+
resp = primp.Client(ca_cert_file=certifi.where())
|
|
322
|
+
export PRIMP_CA_BUNDLE="/home/user/Downloads/cert.pem" # set as environment variable
|
|
323
|
+
|
|
324
|
+
# You can also use convenience functions that use a default Client instance under the hood:
|
|
325
|
+
# primp.get() | primp.head() | primp.options() | primp.delete() | primp.post() | primp.patch() | primp.put()
|
|
326
|
+
# These functions can accept the `impersonate` parameter:
|
|
327
|
+
resp = primp.get("https://httpbin.org/anything", impersonate="chrome_131", impersonate_os="android")
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### II. AsyncClient
|
|
331
|
+
|
|
332
|
+
`primp.AsyncClient()` is an asynchronous wrapper around the `primp.Client` class, offering the same functions, behavior, and input arguments.
|
|
333
|
+
|
|
334
|
+
```python3
|
|
335
|
+
import asyncio
|
|
336
|
+
import logging
|
|
337
|
+
|
|
338
|
+
import never_primp as primp
|
|
339
|
+
|
|
340
|
+
async def aget_text(url):
|
|
341
|
+
async with primp.AsyncClient(impersonate="chrome_131") as client:
|
|
342
|
+
resp = await client.get(url)
|
|
343
|
+
return resp.text
|
|
344
|
+
|
|
345
|
+
async def main():
|
|
346
|
+
urls = ["https://nytimes.com/", "https://cnn.com/", "https://abcnews.go.com/"]
|
|
347
|
+
tasks = [aget_text(u) for u in urls]
|
|
348
|
+
results = await asyncio.gather(*tasks)
|
|
349
|
+
|
|
350
|
+
if __name__ == "__main__":
|
|
351
|
+
logging.basicConfig(level=logging.INFO)
|
|
352
|
+
asyncio.run(main())
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## Disclaimer
|
|
356
|
+
|
|
357
|
+
This tool is for educational purposes only. Use it at your own risk.
|
|
358
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
never_primp-1.0.0.dist-info/METADATA,sha256=zdZwLTtqakrAR7ukQb2kTC1_n-ag04PI3AWGzaEWtkw,16845
|
|
2
|
+
never_primp-1.0.0.dist-info/WHEEL,sha256=GPFYR4mIPdHeeQ1ax6E8LJaGIrcByvaZAJbs3IVoO7M,104
|
|
3
|
+
never_primp-1.0.0.dist-info/licenses/LICENSE,sha256=ZPD9tCar0h91tI4v-TuZdrjDdLqzU4rzPTxtP3x--uc,1063
|
|
4
|
+
never_primp/__init__.py,sha256=St0t0qYotaV3BC4-854NRKEJ0LnUMykXJlY73Em9Sxg,12541
|
|
5
|
+
never_primp/never_primp.abi3.so,sha256=BAnWhGKZJjAO624jRyTAgtFjObWjZEX1pyyenp_iuP8,6981252
|
|
6
|
+
never_primp/never_primp.pyi,sha256=8QRuXaqNfk29qkFZrbtwKKK92Y_wL-O702nys8DCcM0,5731
|
|
7
|
+
never_primp/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
never_primp-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 deedy5
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|