tls-client-python 1.16.0.1__py3-none-macosx_10_9_universal2.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.
@@ -0,0 +1,620 @@
1
+ Metadata-Version: 2.4
2
+ Name: tls-client-python
3
+ Version: 1.16.0.1
4
+ Summary: High-performance Python binding for bogdanfinn/tls-client via CFFI – zero-copy, panic-proof, full TLS fingerprint control
5
+ Author: komAAmok
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/komAAmok/tls-client-python
8
+ Project-URL: Documentation, https://github.com/komAAmok/tls-client-python#readme
9
+ Project-URL: Repository, https://github.com/komAAmok/tls-client-python
10
+ Project-URL: Issues, https://github.com/komAAmok/tls-client-python/issues
11
+ Keywords: tls,tls-fingerprint,http-client,ja3,http2,http3,quic,cffi,akamai,cloudflare,anti-bot
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: MacOS :: MacOS X
15
+ Classifier: Operating System :: Microsoft :: Windows
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.6
19
+ Classifier: Programming Language :: Python :: 3.7
20
+ Classifier: Programming Language :: Python :: 3.8
21
+ Classifier: Programming Language :: Python :: 3.9
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Programming Language :: Python :: 3.13
26
+ Classifier: Programming Language :: Python :: 3.14
27
+ Classifier: Programming Language :: Python :: Implementation :: CPython
28
+ Classifier: Topic :: Internet :: WWW/HTTP
29
+ Classifier: Topic :: Security
30
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
31
+ Requires-Python: >=3.6,<3.15
32
+ Description-Content-Type: text/markdown
33
+ License-File: LICENSE
34
+ Requires-Dist: cffi>=1.14.0
35
+ Requires-Dist: typing_extensions<4.2,>=4.1; python_version < "3.7"
36
+ Requires-Dist: typing_extensions>=4.1; python_version >= "3.7" and python_version < "3.10"
37
+ Dynamic: license-file
38
+ Dynamic: requires-python
39
+
40
+ # tls-client-python
41
+
42
+ > **维护边界:** Go 引擎同步自上游,本项目的 Python/CFFI 扩展及冲突保留规则见
43
+ > [`UPSTREAM_SYNC.md`](UPSTREAM_SYNC.md)。日常修改请勿直接改动上游归属区域。
44
+
45
+ [![PyPI version](https://img.shields.io/pypi/v/tls-client-python)](https://pypi.org/project/tls-client-python/)
46
+ [![Python](https://img.shields.io/pypi/pyversions/tls-client-python)](https://pypi.org/project/tls-client-python/)
47
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
48
+
49
+ **CFFI-based, high-performance Python binding for [`tls-client`](https://github.com/bogdanfinn/tls-client) — drop-in compatible with [`requests`](https://github.com/psf/requests) and [`Python-Tls-Client`](https://github.com/FlorianREGAZ/Python-Tls-Client).**
50
+ ---
51
+
52
+ ## What is TLS Fingerprinting?
53
+
54
+ Some people think it is enough to change the user-agent header of a request to let the server think that the client
55
+ requesting a resource is a specific browser.
56
+ Nowadays this is not enough, because the server might use a technique to detect the client browser which is called TLS
57
+ Fingerprinting.
58
+
59
+ For a deep dive, see [this excellent article on TLS fingerprinting](https://httptoolkit.tech/blog/tls-fingerprinting-node-js/#how-does-tls-fingerprinting-work).
60
+
61
+ ## ✨ Features
62
+
63
+ | Category | Details |
64
+ |----------|---------|
65
+ | 🔐 **TLS Fingerprinting** | Impersonate Chrome, Firefox, Safari, Brave, Opera, OkHttp & more |
66
+ | 🌐 **Protocol Support** | HTTP/1.1, HTTP/2 (h2), HTTP/3 (QUIC) with automatic negotiation |
67
+ | ⚡ **Protocol Racing** | Chrome-style Happy Eyeballs for HTTP/2 vs HTTP/3 |
68
+ | 📋 **Header Ordering** | Control the exact order of HTTP headers per request |
69
+ | 🔒 **Certificate Pinning** | Pin server certificates for enhanced security |
70
+ | 🍪 **Cookie Jar** | Built-in cookie handling with customisable jar |
71
+ | 🚇 **Proxy Support** | HTTP and SOCKS5 proxies with CONNECT auth |
72
+ | 🔀 **Redirect Control** | Choose whether to follow redirects per request |
73
+ | 📊 **Bandwidth Tracking** | Monitor upload/download bytes in real time |
74
+ | 🔄 **sync/Async** | `Session` + `AsyncSession` |
75
+ | 🛡️ **Panic-proof** | All Go panics caught and surfaced as Python exceptions |
76
+ | ⚙️ **Custom TLS** | Full 26-field custom TLS client configuration |
77
+ | 🔬 **Chrome 99–153 Captures** | Byte-exact profiles for **every** Chrome major 99…153, recovered from live handshakes |
78
+ | 🎲 **Per-Handshake Extension Shuffle** | Chromium's unseeded extension rotation, with GREASE/padding/PSK pinned (`ABI 3`) |
79
+ | 🧭 **Destination-Aware Header Order** | Header order selected by `Sec-Fetch-Dest` — navigation vs sub-resource (`ABI 3`) |
80
+ | 🌐 **Deep TCP Fingerprint** | DF bit, TOS, Nagle, window clamp and IP-ID mode (`ABI 3`) |
81
+ | 🎯 **Fingerprint Presets** | Coherent per-OS bundles: identifier + headers + header order + TCP fingerprint (`tls_client.fingerprints`) |
82
+ | 🧭 **Request Contexts** | Browser-coherent `Sec-Fetch-*`, Client Hints and RFC 9218 `Priority` headers (`RequestContext`) |
83
+ | 🔏 **Trust Anchors / ECH** | Chrome 152 `0xCA34` trust anchors and automatic ECH config resolution over DoH |
84
+ | 🪶 **Full-fidelity build** | A single full build (QUIC/HTTP-3 + the complete profile catalogue) |
85
+
86
+ > **macOS TCP fingerprinting:** macOS derives TCP MSS during `connect` and
87
+ > rejects `TCP_MAXSEG` in the pre-connect socket hook. The MSS hint is therefore
88
+ > skipped on macOS; TTL, receive-window tuning, and TLS/HTTP fingerprints remain
89
+ > active. This avoids `MSS(1460): invalid argument` on macOS 26 and earlier.
90
+
91
+ ---
92
+
93
+ ## 📦 Installation
94
+
95
+ ```bash
96
+ pip install tls-client-python
97
+ ```
98
+
99
+ Pre-compiled binaries are included for **12 platforms** (plus a macOS universal2 wheel) — no Go toolchain required.
100
+
101
+ > **Requirements:** Python 3.6+
102
+
103
+ ---
104
+
105
+ ## 🚀 Quick Start
106
+
107
+ ```python
108
+ from tls_client import Session
109
+
110
+ # Create a session with Chrome 146 fingerprint
111
+ session = Session(client_identifier="chrome_146", verify=False)
112
+
113
+ # GET request
114
+ resp = session.get("https://tls.browserleaks.com/json")
115
+ print(resp.status_code)
116
+ print(resp.text)
117
+
118
+ # POST request
119
+ resp = session.post("https://tools.scrapfly.io/api/fp/ja3")
120
+ data = resp.json()
121
+ print(resp.status_code)
122
+ print(data)
123
+
124
+
125
+ # Context Manager
126
+ with Session(client_identifier="firefox_148") as session:
127
+ resp = session.get("https://tls.browserleaks.com/json")
128
+ print(resp.status_code)
129
+ print(resp.text)
130
+
131
+
132
+ # Async Usage
133
+ import asyncio
134
+ from tls_client import AsyncSession
135
+
136
+ async def main():
137
+ async with AsyncSession(client_identifier="firefox_148") as s:
138
+ resp = await s.get("https://tls.browserleaks.com/json")
139
+ print(resp.status_code)
140
+ print(resp.json())
141
+
142
+ asyncio.run(main())
143
+ ```
144
+
145
+ ### Requests-compatible API
146
+
147
+ The synchronous API implements Requests-style request preparation, session
148
+ state, redirects, cookies, hooks, exceptions, and response objects without
149
+ depending on the Requests package. Network transport remains the native
150
+ tls-client engine:
151
+
152
+ ```python
153
+ import tls_client
154
+
155
+ response = tls_client.get(
156
+ "https://example.com/api",
157
+ params={"page": 1},
158
+ headers={"Accept": "application/json"},
159
+ timeout=(3.05, 30),
160
+ )
161
+ response.raise_for_status()
162
+ print(response.json())
163
+
164
+ with tls_client.Session(client_identifier="chrome_146") as session:
165
+ session.headers.update({"Authorization": "Bearer token"})
166
+ response = session.post(
167
+ "https://example.com/upload",
168
+ files={"file": ("data.txt", b"payload")},
169
+ hooks={"response": lambda r, *args, **kwargs: r},
170
+ )
171
+ ```
172
+
173
+ `Request`, `PreparedRequest`, `Response`, `exceptions`, `codes`, `cookies`,
174
+ `auth`, `adapters`, `structures`, and all top-level HTTP helpers follow the
175
+ commonly used Requests API. The previous low-level objects remain available as `NativeSession`,
176
+ `NativeResponse`, and `TLSRequest`. `stream=True` exposes the normal Requests
177
+ iteration API, but the current native ABI buffers the response before Python
178
+ receives it. A string `verify` value enables verification with system roots;
179
+ passing a custom CA bundle through the C ABI is not yet supported.
180
+
181
+ ---
182
+
183
+ ## 🖥️ Supported Platforms
184
+
185
+ Pre-compiled native libraries are bundled for these platforms:
186
+
187
+ | OS | Architecture | Binary |
188
+ |----|-------------|--------|
189
+ | **Windows** | x86-64 | `tls-client-windows-amd64.dll` |
190
+ | **Windows** | x86 (32-bit) | `tls-client-windows-386.dll` |
191
+ | **Windows** | ARM64 | `tls-client-windows-arm64.dll` |
192
+ | **macOS** | x86-64 | `tls-client-darwin-amd64.dylib` |
193
+ | **macOS** | ARM64 (Apple Silicon) | `tls-client-darwin-arm64.dylib` |
194
+ | **macOS** | Universal (both) | one `universal2` wheel, both binaries |
195
+ | **Linux** | x86-64 (glibc) | `tls-client-linux-amd64.so` |
196
+ | **Linux** | x86 (32-bit, glibc) | `tls-client-linux-386.so` |
197
+ | **Linux** | ARM64 | `tls-client-linux-arm64.so` |
198
+ | **Linux** | ARMv7 | `tls-client-linux-arm.so` |
199
+ | **Linux** | x86-64 (musl) | `tls-client-linux-amd64-musl.so` |
200
+ | **Linux** | ARM64 (musl) | `tls-client-linux-arm64-musl.so` |
201
+ | **Linux** | ARMv7 (musl) | `tls-client-linux-arm-musl.so` |
202
+
203
+ The correct binary is automatically selected at runtime. Override via `TLS_CLIENT_LIB` environment variable.
204
+
205
+ ---
206
+
207
+ ## 🎭 Supported Browser Profiles
208
+
209
+ The complete, runtime-validated list is exported as
210
+ `tls_client.SUPPORTED_CLIENT_IDENTIFIERS`. It is also used for IDE/type
211
+ checking through `ClientIdentifiers`.
212
+
213
+ ### 🌐 Chrome — 79 Profiles (captured 99–153 + hand-written)
214
+
215
+ The full Chrome range **99 through 153** is available, recovered from live
216
+ handshakes rather than hand-transcribed. Every major ships as both
217
+ `chrome_<major>` and `chrome_<major>_PSK`:
218
+
219
+ | Identifier | Notes |
220
+ |-----------|-------|
221
+ | `chrome_99` — `chrome_153` | **Byte-exact captures, every major 99…153** |
222
+ | `chrome_99_PSK` — `chrome_153_PSK` | Same, with PSK key exchange |
223
+
224
+ The captures pin the real per-version cipher list, extension order, supported
225
+ groups, signature algorithms, JA3/JA4 and HTTP/2 Akamai fingerprint — so
226
+ `chrome_111`, `chrome_121`, `chrome_137` etc. reproduce the wire bytes of that
227
+ exact release, including the per-milestone extension-order reshuffles.
228
+
229
+ Hand-written profiles with PSK / Post-Quantum / trust-anchor refinements
230
+ (`chrome_116_PSK_PQ`, `chrome_130_PSK`, `chrome_144`, `chrome_146`,
231
+ `chrome_150`, `chrome_152`, …) remain authoritative where they exist.
232
+
233
+ | Identifier | Notes |
234
+ |-----------|-------|
235
+ | `chrome_116_PSK_PQ` | Chrome 116 with PSK + Post-Quantum |
236
+ | `chrome_130_PSK` · `chrome_131_PSK` · `chrome_133_PSK` | PSK variants |
237
+ | `chrome_144` · `chrome_146` · `chrome_150` · `chrome_152` | standard + PSK |
238
+ | `chrome_146` | **default identifier** (standard & PSK) |
239
+
240
+ ### 🦊 Firefox — 16 Profiles
241
+
242
+ | Identifier | Notes |
243
+ |-----------|-------|
244
+ | `firefox_102` · `firefox_104` · `firefox_105` · `firefox_106` | Firefox 102–106 |
245
+ | `firefox_108` · `firefox_110` | Firefox 108 · 110 |
246
+ | `firefox_117` · `firefox_120` · `firefox_123` | Firefox 117–123 |
247
+ | `firefox_132` · `firefox_133` · `firefox_135` | Firefox 132–135 |
248
+ | `firefox_146_PSK` | Firefox 146 with PSK |
249
+ | `firefox_147` · `firefox_147_PSK` | Firefox 147 (standard & PSK) |
250
+ | `firefox_148` | Firefox 148 |
251
+
252
+ ### 🍏 Safari — 10 Profiles
253
+
254
+ | Identifier | Device |
255
+ |-----------|--------|
256
+ | `safari_15_6_1` | Safari 15.6.1 (macOS) |
257
+ | `safari_16_0` | Safari 16.0 (macOS) |
258
+ | `safari_ipad_15_6` | Safari 15.6 (iPadOS) |
259
+ | `safari_ios_15_5` · `safari_ios_15_6` | Safari iOS 15.5–15.6 |
260
+ | `safari_ios_16_0` · `safari_ios_17_0` | Safari iOS 16 · 17 |
261
+ | `safari_ios_18_0` · `safari_ios_18_5` | Safari iOS 18 · 18.5 |
262
+ | `safari_ios_26_0` | Safari iOS 26 |
263
+
264
+ ### 🦁 Brave — 2 Profiles
265
+
266
+ | Identifier | Notes |
267
+ |-----------|-------|
268
+ | `brave_146` | Brave Browser 146 |
269
+ | `brave_146_PSK` | Brave 146 with PSK |
270
+
271
+ ### 🎭 Opera — 3 Profiles
272
+
273
+ | Identifier |
274
+ |-----------|
275
+ | `opera_89` · `opera_90` · `opera_91` |
276
+
277
+ ### 🤖 OkHttp (Android) — 7 Profiles
278
+
279
+ | Identifier |
280
+ |-----------|
281
+ | `okhttp4_android_7` — `okhttp4_android_13` |
282
+
283
+ ### 📱 Mobile / App SDKs — 16 Profiles
284
+
285
+ | Category | Identifiers |
286
+ |----------|------------|
287
+ | Zalando | `zalando_android_mobile` · `zalando_ios_mobile` |
288
+ | Nike | `nike_ios_mobile` · `nike_android_mobile` |
289
+ | MMS | `mms_ios` · `mms_ios_1` · `mms_ios_2` · `mms_ios_3` |
290
+ | Mesh | `mesh_ios` · `mesh_ios_1` · `mesh_ios_2` · `mesh_android` · `mesh_android_1` · `mesh_android_2` |
291
+ | Confirmed | `confirmed_ios` · `confirmed_android` |
292
+
293
+ ### ☁️ Cloudflare-specific — 1 Profile
294
+
295
+ | Identifier | Notes |
296
+ |-----------|-------|
297
+ | `cloudscraper` | Custom profile tuned for Cloudflare-protected sites |
298
+
299
+ ---
300
+
301
+ ## 🔧 Advanced Usage
302
+
303
+ ### Full TLS controls at the top-level `Session`
304
+
305
+ `tls_client.Session` is Requests-compatible, but its public constructor keeps
306
+ the complete native TLS signature. IDE completion and `inspect.signature()`
307
+ therefore expose fingerprint, protocol, socket, proxy, certificate, cookie,
308
+ pool, and debug controls instead of showing only Requests arguments:
309
+
310
+ ```python
311
+ import inspect
312
+ import tls_client
313
+
314
+ print(inspect.signature(tls_client.Session))
315
+ session = tls_client.Session(
316
+ client_identifier="chrome_152",
317
+ force_http1=True,
318
+ disable_http3=True,
319
+ random_tls_extension_order=False,
320
+ tcp_mss=1460,
321
+ tcp_ttl=64,
322
+ max_connections_per_host=32,
323
+ with_debug=True,
324
+ )
325
+ ```
326
+
327
+ The same TLS keyword names are accepted by Requests-style calls (`get`,
328
+ `post`, `request`, and `execute_request`) for per-request overrides.
329
+
330
+ Unknown browser/fingerprint identifiers fail immediately with `ValueError`.
331
+ Use `SUPPORTED_CLIENT_IDENTIFIERS` to validate user input before creating a
332
+ session.
333
+
334
+ ### Custom TLS Client (Full Control)
335
+
336
+ Set `custom_tls_client` with up to 26 fields to bypass `client_identifier` entirely:
337
+
338
+ ```python
339
+ session = Session(custom_tls_client={
340
+ "ja3_string": "771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,0-23-65281-10-11-35-16-5-13-18-51-45-43-27-17513,29-23-24,0",
341
+ "h2_settings": {"HEADER_TABLE_SIZE": 65536, "MAX_CONCURRENT_STREAMS": 1000},
342
+ "h2_settings_order": ["HEADER_TABLE_SIZE", "MAX_CONCURRENT_STREAMS"],
343
+ "pseudo_header_order": [":method", ":authority", ":scheme", ":path"],
344
+ "connection_flow": 1048576,
345
+ "key_share_curves": ["X25519", "P256"],
346
+ "alpn_protocols": ["h2", "http/1.1"],
347
+ "supported_versions": ["1.3", "1.2"],
348
+ "stream_id": 3,
349
+ })
350
+ ```
351
+
352
+ ### Certificate Pinning
353
+
354
+ ```python
355
+ session = Session(
356
+ certificate_pinning_hosts={
357
+ "example.com": ["sha256/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="]
358
+ }
359
+ )
360
+ ```
361
+
362
+ ### Client Certificates (mTLS)
363
+
364
+ ```python
365
+ session = Session(
366
+ client_certificates=[{
367
+ "cert_pem": open("client.crt", "rb").read(),
368
+ "key_pem": open("client.key", "rb").read(),
369
+ }]
370
+ )
371
+ ```
372
+
373
+ ### Fingerprint Presets (Coherent Browser Bundles)
374
+
375
+ A preset bundles the engine TLS profile, the per-OS coherent header block
376
+ (UA + Client Hints), the destination-aware header orders, the extension-shuffle
377
+ policy and the OS TCP fingerprint in one line:
378
+
379
+ ```python
380
+ from tls_client import Session
381
+ from tls_client.fingerprints import apply, list_presets
382
+
383
+ print(len(list_presets())) # 391 presets
384
+
385
+ session = Session()
386
+ apply(session, "chrome_150_windows") # or chrome_99_linux, chrome_153_ios, ...
387
+ session.get("https://tls.peet.ws/api/all")
388
+ ```
389
+
390
+ All 55 captured Chrome majors (99–153) ship as
391
+ `chrome_<major>_base`, `chrome_<major>_windows`, `_macos`, `_linux`,
392
+ `_android`, `_ios`, plus a bare `chrome_<major>` alias for the Windows
393
+ variant — and each per-OS variant derives a platform-coherent UA and TCP
394
+ fingerprint (Windows `TTL=128/window=64240`, Linux/macOS `TTL=64/window=65535`,
395
+ etc.). `header_order_for_dest(dest)` returns the header template for a
396
+ `Sec-Fetch-Dest` value.
397
+
398
+ Or directly: `Session(fingerprint="chrome_150_windows")`. Custom presets are
399
+ plain JSON with optional `based_on` inheritance:
400
+
401
+ ```python
402
+ from tls_client.fingerprints import load_preset_file
403
+ load_preset_file("my_chrome.json") # {"name": ..., "based_on": "chrome_152_windows", ...}
404
+ ```
405
+
406
+ ### Request Contexts (Sec-Fetch-*, Client Hints, Priority)
407
+
408
+ Describe *how* the request was initiated and the coherent header set is
409
+ derived (opt-in — without `context=` nothing changes):
410
+
411
+ ```python
412
+ from tls_client.context import RequestContext
413
+
414
+ session.get(url, context=RequestContext.navigation(url, referrer=page_url))
415
+ session.post(api, context=RequestContext.xhr(api))
416
+ session.get(img, context=RequestContext.image(img))
417
+ ```
418
+
419
+ ### Trust Anchors (Chrome 152+, ABI 2) and ECH
420
+
421
+ ```python
422
+ session = Session(custom_tls_client={
423
+ "ja3_string": "...",
424
+ "trust_anchors_payload": "0009080102030405060708", # hex of the 0xCA34 payload
425
+ })
426
+
427
+ # Automatic ECH resolution over DoH (RFC 9460), cached per host:
428
+ from tls_client import ech
429
+ payload = ech.resolve("tls.peet.ws")
430
+ session = Session(custom_tls_client={
431
+ "ja3_string": "...",
432
+ "ech_candidate_payloads": ech.to_candidate_payloads(payload),
433
+ })
434
+ ```
435
+
436
+ > `TLS_CLIENT_DOH_ENDPOINT` overrides the DoH server
437
+ > (e.g. `https://dns.alidns.com/resolve`) — useful on networks where
438
+ > `cloudflare-dns.com` is unreachable.
439
+
440
+ ### TLS Debugging (Keylog) and Custom CA (ABI 2)
441
+
442
+ ```python
443
+ session = Session(
444
+ tls_keylog_path="keylog.txt", # Wireshark TLS secrets
445
+ root_ca_pem=open("corp-ca.pem", "rb").read(),
446
+ disable_session_tickets=True,
447
+ )
448
+ ```
449
+
450
+ ### Deep Fingerprint Control (ABI 3)
451
+
452
+ Fine-grained, byte-level control over the handshake and the socket:
453
+
454
+ ```python
455
+ session = Session(
456
+ client_identifier="chrome_150",
457
+
458
+ # Chromium shuffles the ClientHello extension order on *every*
459
+ # handshake (unseeded), pinning GREASE / padding / pre_shared_key.
460
+ # 0 = off (captured order) 1 = chrome
461
+ # 2 = all extensions 3 = prefix (first N stay fixed)
462
+ extension_permute_mode=1,
463
+ extension_permute_prefix=0, # only meaningful when mode=3
464
+
465
+ # Suppress RFC 7540 PRIORITY frames / the HEADERS priority flag.
466
+ h2_disable_priority_frames=False,
467
+
468
+ # Pick the header order from the request's Sec-Fetch-Dest instead of
469
+ # using one fixed order for every request.
470
+ header_order_by_dest=True,
471
+ header_order_dest=None, # None = infer from Sec-Fetch-Dest
472
+
473
+ # Deep TCP fingerprint. -1 (the default) leaves the profile's own
474
+ # value untouched; 0 is a *real* value (DF cleared / TOS 0 / Nagle off).
475
+ tcp_dont_fragment=-1, # -1 unset · 0 clear DF · 1 set DF
476
+ tcp_tos=-1, # -1 unset · 0..255
477
+ tcp_no_delay=-1, # -1 unset · 0 off · 1 on
478
+ tcp_window_clamp=0, # 0 unset · Linux TCP_WINDOW_CLAMP
479
+ tcp_ip_id_mode="", # "" unset · "random" · "zero" · "incremental"
480
+ )
481
+ ```
482
+
483
+ Every parameter can also be set per request. On a shared library older than
484
+ ABI 3 these degrade to their defaults with a one-time `RuntimeWarning`
485
+ instead of failing the request — rebuild the native library to enable them.
486
+
487
+ Presets bundle all of the above automatically:
488
+
489
+ ```python
490
+ from tls_client.fingerprints import apply
491
+
492
+ session = Session()
493
+ apply(session, "chrome_150_linux") # identifier + headers + permute + TCP
494
+ ```
495
+
496
+ ### Build Tiers
497
+
498
+ A single full-fidelity build ships in each wheel — QUIC/HTTP-3 enabled and
499
+ the complete profile catalogue (there are no lite/nano tiers).
500
+
501
+ ```bash
502
+ TLS_CLIENT_LIB=/path/to/tls-client.so # optional: override the library path
503
+ ```
504
+
505
+ `TLS_CLIENT_LIB` overrides the path entirely; by default the loader picks the
506
+ bundled native binary for the current OS/arch.
507
+
508
+ ### Engine-Level HTTP/2 Realism (ABI 2.1)
509
+
510
+ ```python
511
+ session = Session(
512
+ hpack_indexing_policy="chrome", # Chromium HPACK indexing behaviour
513
+ h2_max_data_frame_size=14000, # cap each DATA frame payload
514
+ preface_ping_idle_ms=10000, # PING before reuse after >=10s idle
515
+ cookie_crumb=True, # one Cookie field per cookie-pair
516
+ )
517
+ ```
518
+
519
+ `cookie_crumb` splits the `Cookie` header into one field per cookie-pair on
520
+ the wire (Chromium "crumble") — observable as multiple `cookie:` fields by
521
+ HTTP/2 servers.
522
+
523
+ ### Stream Response to Disk
524
+
525
+ ```python
526
+ resp = session.stream_to_file(
527
+ "GET", "https://tls.browserleaks.com/",
528
+ output_path="/tmp/image.png"
529
+ )
530
+ print(resp.status_code) # response metadata still available
531
+ ```
532
+
533
+ ### Per-Request Overrides
534
+
535
+ All `Session` constructor parameters can be overridden per request:
536
+
537
+ ```python
538
+ s = Session(client_identifier="chrome_146")
539
+ # Override fingerprint for a single request
540
+ resp = s.get("https://tls.browserleaks.com/json", client_identifier="firefox_148")
541
+ ```
542
+
543
+ ---
544
+
545
+ ## 🔬 Architecture
546
+
547
+ | Layer | Technology |
548
+ |-------|-----------|
549
+ | **Go Engine** | `bogdanfinn/tls-client` compiled as C shared library (`-buildmode=c-shared`) |
550
+ | **FFI Boundary** | Raw C structs via CFFI — no JSON serialization overhead |
551
+ | **Memory Safety** | `ffi.gc(resp, FreeResponse)` — Go panics surfaced as `RuntimeError` |
552
+ | **Python API** | `requests`-style `Session`, `Response`, `AsyncSession` |
553
+
554
+ ---
555
+
556
+ ## 📚 API Reference
557
+
558
+ ### Session
559
+
560
+ | Method | Description |
561
+ |--------|-------------|
562
+ | `get(url, **kwargs)` | HTTP GET |
563
+ | `post(url, **kwargs)` | HTTP POST |
564
+ | `put(url, **kwargs)` | HTTP PUT |
565
+ | `delete(url, **kwargs)` | HTTP DELETE |
566
+ | `head(url, **kwargs)` | HTTP HEAD |
567
+ | `patch(url, **kwargs)` | HTTP PATCH |
568
+ | `execute_request(method, url, **kwargs)` | Generic request with full options |
569
+ | `typed_request(Request)` | Strongly-typed request |
570
+ | `stream_to_file(method, url, path)` | Stream response body to disk |
571
+ | `clear_client_pool()` | Close idle connections (static) |
572
+
573
+ ### Response
574
+
575
+ | Property / Method | Description |
576
+ |-------------------|-------------|
577
+ | `status_code` | HTTP status code (int) |
578
+ | `headers` | Case-insensitive response headers |
579
+ | `content` | Raw bytes body |
580
+ | `text` | Decoded text body |
581
+ | `encoding` | Detected charset |
582
+ | `url` | Final URL after redirects |
583
+ | `cookies` | Requests cookie jar |
584
+ | `history` | Redirect response history |
585
+ | `request` | The originating `PreparedRequest` |
586
+ | `raw` | File-like buffered raw response |
587
+ | `used_protocol` | Protocol used (e.g. `HTTP/2.0`) |
588
+ | `ok` | `True` if `status_code < 400` |
589
+ | `reason` | HTTP reason phrase |
590
+ | `json()` | Parse body as JSON |
591
+ | `raise_for_status()` | Raise `tls_client.exceptions.HTTPError` on 4xx/5xx |
592
+ | `iter_content()` / `iter_lines()` | Iterate over buffered response data |
593
+
594
+ ---
595
+
596
+ ## 🔗 Credits
597
+
598
+ This project is a Python binding for **[bogdanfinn/tls-client](https://github.com/bogdanfinn/tls-client)**, which itself is built upon:
599
+
600
+ - [Carcraftz/fhttp](https://github.com/Carcraftz/fhttp)
601
+ - [Carcraftz/utls](https://github.com/Carcraftz/utls)
602
+ - [refraction-networking/utls](https://github.com/refraction-networking/utls)
603
+
604
+ The byte-exact fingerprint layer also draws on two Go fingerprinting projects whose
605
+ captured-clienthello techniques were studied as references:
606
+
607
+ - **[enetx/surf](https://github.com/enetx/surf)** — full `utls.ClientHelloSpec`
608
+ profiles (trust-anchor `0xCA34`, ML-DSA/ML-KEM post-quantum, GREASE) for
609
+ Chrome/Firefox.
610
+ - **[httpcloak](https://github.com/sardanioss/httpcloak)** — raw ClientHello /
611
+ PSK-resumption replay, per-header HPACK representation and the high-entropy
612
+ Client Hints model.
613
+
614
+ Thanks to the authors of all of the above for their open work.
615
+
616
+ ---
617
+
618
+ ## 📄 License
619
+
620
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,23 @@
1
+ tls_client/__init__.py,sha256=uyfXPiXccMwvygYWn3YGFHsSQm7V0gpFzDOnyaYWsLo,1943
2
+ tls_client/_client_hints.py,sha256=ERF_5N-ivpAO66rYKk9hlfefppp8DAwCnyeYOviGmJU,5374
3
+ tls_client/_core.py,sha256=7J8wSyhtZJqWtrawuwxarSxR7VcsGK79-2jPmSTtY_o,194334
4
+ tls_client/_default_headers.py,sha256=pgPAnQ42ZVF2gQfhkmvir6IztQa5iXONPVa4ABtAdtQ,21621
5
+ tls_client/_multipart_boundary.py,sha256=Bsc1UUE46aeVNZYf24ItwDxVM-bu6RTaCR3SPdISvJU,1929
6
+ tls_client/adapters.py,sha256=f6HNcM6ET-MOOsacm1YzzODBBsvXEUuusps4Zv1apsM,198
7
+ tls_client/auth.py,sha256=A74_PKjxFboqEWroimenQR6ImIrgqeewFHAdCg0j9TY,1351
8
+ tls_client/context.py,sha256=GJi3r32PGadzvrjS3gpTd2duvXirPrqZZr8rVBtR6LE,12500
9
+ tls_client/cookies.py,sha256=2651AMo963fKJdYdDeYQxwVwaAAFwJeDZj0hjnH2eUo,5724
10
+ tls_client/ech.py,sha256=-Uv4HJ4djQTk01RF_mOKDMwrn2_Xi_PxmPVokDQ6Gzc,1737
11
+ tls_client/exceptions.py,sha256=UqrF5zjJ7ZXTHXuRWCdylQKX5PSnrNAzsoiDIa-RYq4,1484
12
+ tls_client/hooks.py,sha256=VyFW1qpv-syy8N7s8VGO-LCJkkn1SM_mfDIrEFrsZ34,752
13
+ tls_client/models.py,sha256=cauaeREtRzIl64AeLCNvwF4JQ5tC7rt89LheupNy6xU,172
14
+ tls_client/requests_compat.py,sha256=t4f2_d_AQ4aQzPwYMPMnOdiVzzVja5FHQBHi1im_aI0,26737
15
+ tls_client/status_codes.py,sha256=eT2h4THZpR5nWK02DIxh0fw4000bWBX38UM8W0FsrhM,1301
16
+ tls_client/structures.py,sha256=Lk4TDTJSzJ5GMyLGaGpxNUi56_ieTiHVZKnREHq803M,1639
17
+ tls_client/bin/tls-client-darwin-amd64.dylib,sha256=zIza10epf0kTlWepQ1Gq4Nhdz00e4ryi9Gnz4Vf2E9o,12604272
18
+ tls_client/bin/tls-client-darwin-arm64.dylib,sha256=s3vH0aDUUg1LlU9klGHkgPJ-z1FHBcx2ig0uW62ZPdw,11851872
19
+ tls_client_python-1.16.0.1.dist-info/licenses/LICENSE,sha256=fauaTdZph_vldtU8HuBHwZNyXfb0-sZ94xWhJ0F_0VE,1662
20
+ tls_client_python-1.16.0.1.dist-info/METADATA,sha256=EcP3DgJG_yzENKh9GB5AokzQW4DK27XeGBuF1GMiaWM,23232
21
+ tls_client_python-1.16.0.1.dist-info/WHEEL,sha256=Oi4ovQSVLy6YUtgYO4qDjz9P3qW4ZViAs3lImtjsrJQ,110
22
+ tls_client_python-1.16.0.1.dist-info/top_level.txt,sha256=yLrfQtbTRfECzPN62knWdGNmbhcPRev1grCAMuEsEz0,11
23
+ tls_client_python-1.16.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-macosx_10_9_universal2
5
+
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2023, Bogdan Finn
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ 3. All advertising materials mentioning features or use of this software
12
+ must display the following acknowledgement:
13
+ This product includes software developed by the <organization>.
14
+ 4. Neither the name of the <organization> nor the
15
+ names of its contributors may be used to endorse or promote products
16
+ derived from this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ''AS IS'' AND ANY
19
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
27
+ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1 @@
1
+ tls_client