tls-client-python 1.14.1__tar.gz → 1.15.0.1__tar.gz

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.
Files changed (24) hide show
  1. {tls_client_python-1.14.1/tls_client_python.egg-info → tls_client_python-1.15.0.1}/PKG-INFO +17 -35
  2. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/Readme.md +16 -34
  3. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/tls_client/__init__.py +1 -1
  4. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/tls_client/_core.py +32 -11
  5. tls_client_python-1.14.1/tls_client/bin/tls-client-linux-amd64.so → tls_client_python-1.15.0.1/tls_client/bin/tls-client-alpine-amd64.so +0 -0
  6. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/tls_client/bin/tls-client-darwin-amd64.dylib +0 -0
  7. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/tls_client/bin/tls-client-darwin-arm64.dylib +0 -0
  8. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/tls_client/bin/tls-client-linux-386.so +0 -0
  9. tls_client_python-1.14.1/tls_client/bin/tls-client-alpine-amd64.so → tls_client_python-1.15.0.1/tls_client/bin/tls-client-linux-amd64.so +0 -0
  10. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/tls_client/bin/tls-client-linux-arm.so +0 -0
  11. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/tls_client/bin/tls-client-linux-arm64.so +0 -0
  12. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/tls_client/bin/tls-client-windows-386.dll +0 -0
  13. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/tls_client/bin/tls-client-windows-amd64.dll +0 -0
  14. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1/tls_client_python.egg-info}/PKG-INFO +17 -35
  15. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/LICENSE +0 -0
  16. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/MANIFEST.in +0 -0
  17. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/pyproject.toml +0 -0
  18. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/setup.cfg +0 -0
  19. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/tls_client/_default_headers.py +0 -0
  20. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/tls_client_python.egg-info/SOURCES.txt +0 -0
  21. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/tls_client_python.egg-info/dependency_links.txt +0 -0
  22. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/tls_client_python.egg-info/not-zip-safe +0 -0
  23. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/tls_client_python.egg-info/requires.txt +0 -0
  24. {tls_client_python-1.14.1 → tls_client_python-1.15.0.1}/tls_client_python.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tls-client-python
3
- Version: 1.14.1
3
+ Version: 1.15.0.1
4
4
  Summary: High-performance Python binding for bogdanfinn/tls-client via CFFI – zero-copy, panic-proof, full TLS fingerprint control
5
5
  Author: komAAmok
6
6
  License: MIT
@@ -67,7 +67,7 @@ For a deep dive, see [this excellent article on TLS fingerprinting](https://http
67
67
  | 🚇 **Proxy Support** | HTTP and SOCKS5 proxies with CONNECT auth |
68
68
  | 🔀 **Redirect Control** | Choose whether to follow redirects per request |
69
69
  | 📊 **Bandwidth Tracking** | Monitor upload/download bytes in real time |
70
- | 🧵 **Async Support** | `AsyncSession` for asyncio integration |
70
+ | 🔄 **sync/Async** | `Session` + `AsyncSession` |
71
71
  | 🛡️ **Panic-proof** | All Go panics caught and surfaced as Python exceptions |
72
72
  | ⚙️ **Custom TLS** | Full 26-field custom TLS client configuration |
73
73
 
@@ -81,9 +81,7 @@ pip install tls-client-python
81
81
 
82
82
  Pre-compiled binaries are included for **9 platforms** — no Go toolchain required.
83
83
 
84
- ### Requirements
85
-
86
- - Python 3.6+
84
+ > **Requirements:** Python 3.6+
87
85
 
88
86
  ---
89
87
 
@@ -93,41 +91,35 @@ Pre-compiled binaries are included for **9 platforms** — no Go toolchain requi
93
91
  from tls_client import Session
94
92
 
95
93
  # Create a session with Chrome 146 fingerprint
96
- session = Session(client_identifier="chrome_146")
94
+ session = Session(client_identifier="chrome_146", verify=False)
97
95
 
98
96
  # GET request
99
97
  resp = session.get("https://tls.browserleaks.com/json")
100
- print(resp.status_code) # 200
101
- print(resp.text) # JSON body
102
- print(resp.used_protocol) # "HTTP/2.0"
103
-
104
- # POST with JSON
105
- resp = session.post(
106
- "https://tls.browserleaks.com/json",
107
- body=b'{"hello":"world"}',
108
- headers={"Content-Type": "application/json"}
109
- )
98
+ print(resp.status_code)
99
+ print(resp.text)
100
+
101
+ # POST request
102
+ resp = session.post("https://tools.scrapfly.io/api/fp/ja3")
110
103
  data = resp.json()
111
- print(data["json"]) # {"hello": "world"}
112
- ```
104
+ print(resp.status_code)
105
+ print(data)
113
106
 
114
- ### Context Manager
115
107
 
116
- ```python
117
- with Session(client_identifier="safari_ios_18_5") as s:
118
- resp = s.get("https://tls.browserleaks.com/json")
108
+ # Context Manager
109
+ with Session(client_identifier="firefox_148") as session:
110
+ resp = session.get("https://tls.browserleaks.com/json")
119
111
  print(resp.status_code)
120
- ```
112
+ print(resp.text)
121
113
 
122
- ### Async Usage
123
114
 
124
- ```python
115
+ # Async Usage
125
116
  import asyncio
126
117
  from tls_client import AsyncSession
127
118
 
128
119
  async def main():
129
120
  async with AsyncSession(client_identifier="firefox_148") as s:
130
121
  resp = await s.get("https://tls.browserleaks.com/json")
122
+ print(resp.status_code)
131
123
  print(resp.json())
132
124
 
133
125
  asyncio.run(main())
@@ -157,16 +149,6 @@ The correct binary is automatically selected at runtime. Override via `TLS_CLIEN
157
149
 
158
150
  ## 🎭 Supported Browser Profiles — 79 Identifiers
159
151
 
160
- Set `client_identifier` in `Session()` to impersonate any of these browsers. Inspect the full list at runtime:
161
-
162
- ```python
163
- from tls_client import list_client_identifiers, SUPPORTED_CLIENT_IDENTIFIERS
164
-
165
- print(len(list_client_identifiers())) # 79
166
- for browser, ids in SUPPORTED_CLIENT_IDENTIFIERS.items():
167
- print(f"{browser}: {len(ids)} profiles")
168
- ```
169
-
170
152
  ### 🌐 Chrome — 24 Profiles
171
153
 
172
154
  | Identifier | Notes |
@@ -32,7 +32,7 @@ For a deep dive, see [this excellent article on TLS fingerprinting](https://http
32
32
  | 🚇 **Proxy Support** | HTTP and SOCKS5 proxies with CONNECT auth |
33
33
  | 🔀 **Redirect Control** | Choose whether to follow redirects per request |
34
34
  | 📊 **Bandwidth Tracking** | Monitor upload/download bytes in real time |
35
- | 🧵 **Async Support** | `AsyncSession` for asyncio integration |
35
+ | 🔄 **sync/Async** | `Session` + `AsyncSession` |
36
36
  | 🛡️ **Panic-proof** | All Go panics caught and surfaced as Python exceptions |
37
37
  | ⚙️ **Custom TLS** | Full 26-field custom TLS client configuration |
38
38
 
@@ -46,9 +46,7 @@ pip install tls-client-python
46
46
 
47
47
  Pre-compiled binaries are included for **9 platforms** — no Go toolchain required.
48
48
 
49
- ### Requirements
50
-
51
- - Python 3.6+
49
+ > **Requirements:** Python 3.6+
52
50
 
53
51
  ---
54
52
 
@@ -58,41 +56,35 @@ Pre-compiled binaries are included for **9 platforms** — no Go toolchain requi
58
56
  from tls_client import Session
59
57
 
60
58
  # Create a session with Chrome 146 fingerprint
61
- session = Session(client_identifier="chrome_146")
59
+ session = Session(client_identifier="chrome_146", verify=False)
62
60
 
63
61
  # GET request
64
62
  resp = session.get("https://tls.browserleaks.com/json")
65
- print(resp.status_code) # 200
66
- print(resp.text) # JSON body
67
- print(resp.used_protocol) # "HTTP/2.0"
68
-
69
- # POST with JSON
70
- resp = session.post(
71
- "https://tls.browserleaks.com/json",
72
- body=b'{"hello":"world"}',
73
- headers={"Content-Type": "application/json"}
74
- )
63
+ print(resp.status_code)
64
+ print(resp.text)
65
+
66
+ # POST request
67
+ resp = session.post("https://tools.scrapfly.io/api/fp/ja3")
75
68
  data = resp.json()
76
- print(data["json"]) # {"hello": "world"}
77
- ```
69
+ print(resp.status_code)
70
+ print(data)
78
71
 
79
- ### Context Manager
80
72
 
81
- ```python
82
- with Session(client_identifier="safari_ios_18_5") as s:
83
- resp = s.get("https://tls.browserleaks.com/json")
73
+ # Context Manager
74
+ with Session(client_identifier="firefox_148") as session:
75
+ resp = session.get("https://tls.browserleaks.com/json")
84
76
  print(resp.status_code)
85
- ```
77
+ print(resp.text)
86
78
 
87
- ### Async Usage
88
79
 
89
- ```python
80
+ # Async Usage
90
81
  import asyncio
91
82
  from tls_client import AsyncSession
92
83
 
93
84
  async def main():
94
85
  async with AsyncSession(client_identifier="firefox_148") as s:
95
86
  resp = await s.get("https://tls.browserleaks.com/json")
87
+ print(resp.status_code)
96
88
  print(resp.json())
97
89
 
98
90
  asyncio.run(main())
@@ -122,16 +114,6 @@ The correct binary is automatically selected at runtime. Override via `TLS_CLIEN
122
114
 
123
115
  ## 🎭 Supported Browser Profiles — 79 Identifiers
124
116
 
125
- Set `client_identifier` in `Session()` to impersonate any of these browsers. Inspect the full list at runtime:
126
-
127
- ```python
128
- from tls_client import list_client_identifiers, SUPPORTED_CLIENT_IDENTIFIERS
129
-
130
- print(len(list_client_identifiers())) # 79
131
- for browser, ids in SUPPORTED_CLIENT_IDENTIFIERS.items():
132
- print(f"{browser}: {len(ids)} profiles")
133
- ```
134
-
135
117
  ### 🌐 Chrome — 24 Profiles
136
118
 
137
119
  | Identifier | Notes |
@@ -40,4 +40,4 @@ __all__ = [
40
40
  "ClientIdentifiers",
41
41
  "clear_client_pool",
42
42
  ]
43
- __version__ = "1.14.1"
43
+ __version__ = "1.15.0.1"
@@ -35,6 +35,7 @@ import sys
35
35
  import threading
36
36
  from pathlib import Path
37
37
  from typing import Any, Dict, List, Literal, Optional
38
+ import hashlib
38
39
 
39
40
  from tls_client._default_headers import DEFAULT_HEADERS
40
41
 
@@ -45,7 +46,6 @@ except ImportError:
45
46
 
46
47
  from typing_extensions import TypeAlias # Python <3.10
47
48
 
48
- from typing_extensions import TypeAlias # Python <3.10
49
49
 
50
50
  # ---------------------------------------------------------------------------
51
51
  # Supported TLS client identifiers — literal type for IDE autocompletion
@@ -1117,6 +1117,12 @@ def _compute_cache_key_hash(r: dict) -> str:
1117
1117
 
1118
1118
  The format matches Go's buildCacheKey exactly — same field order,
1119
1119
  same separators, same sort order for maps, same hex encoding.
1120
+
1121
+ FORMAT VERSION: 1
1122
+ If you change the hash format below, increment the version AND update
1123
+ Go's buildCacheKey / buildCacheKeyFromConfig in cffi_binding/main.go
1124
+ and the corresponding test in test_cache_key_parity.py. Format drift
1125
+ causes silent cache poisoning (different keys → duplicate clients).
1120
1126
  """
1121
1127
  h = hashlib.sha256()
1122
1128
 
@@ -1264,7 +1270,7 @@ def _populate_request_options(
1264
1270
  def _val(name: str, as_bool: bool = False) -> Any:
1265
1271
  v = overrides.get(name)
1266
1272
  if v is None:
1267
- v = defaults[name]
1273
+ v = defaults.get(name) # defensive: missing key → None instead of KeyError
1268
1274
  if as_bool:
1269
1275
  return 1 if v else 0
1270
1276
  return v
@@ -2109,7 +2115,7 @@ class Session:
2109
2115
  ffi, lib = _get_ffi()
2110
2116
 
2111
2117
  def _val(name: str, override, as_bool: bool = False):
2112
- v = override if override is not None else self.defaults[name]
2118
+ v = override if override is not None else self.defaults.get(name)
2113
2119
  if as_bool:
2114
2120
  return 1 if v else 0
2115
2121
  return v
@@ -2490,12 +2496,18 @@ _async_callback_lock = threading.Lock()
2490
2496
 
2491
2497
 
2492
2498
  def _get_async_callback(ffi, lib):
2499
+ """Return the singleton CFFI callback, creating it once under lock.
2500
+
2501
+ Always acquires _async_callback_lock — double‑checked locking is unsafe
2502
+ under free‑threaded Python (PEP 703) because _async_callback may be
2503
+ partially visible without a synchronisation edge. Contention is
2504
+ negligible: the callback is created once and cached thereafter.
2505
+ """
2493
2506
  global _async_callback
2494
- if _async_callback is None:
2495
- with _async_callback_lock:
2496
- if _async_callback is None:
2497
- _async_callback = _make_async_callback(ffi, lib)
2498
- return _async_callback
2507
+ with _async_callback_lock:
2508
+ if _async_callback is None:
2509
+ _async_callback = _make_async_callback(ffi, lib)
2510
+ return _async_callback
2499
2511
 
2500
2512
 
2501
2513
  class AsyncSession:
@@ -2704,7 +2716,7 @@ class AsyncSession:
2704
2716
  def _val(name: str, as_bool: bool = False):
2705
2717
  v = kwargs.pop(name, None)
2706
2718
  if v is None:
2707
- v = self._session.defaults[name]
2719
+ v = self._session.defaults.get(name)
2708
2720
  if as_bool:
2709
2721
  return 1 if v else 0
2710
2722
  return v
@@ -2794,8 +2806,8 @@ class AsyncSession:
2794
2806
 
2795
2807
  # Pre-compute cache key hash and attach to opts (avoids ~50 CGO calls on hit).
2796
2808
  # Use kwargs.get() (non-destructive) so later _val() calls still find overrides.
2797
- def _ck(name): return kwargs.get(name, self._session.defaults[name])
2798
- def _ckb(name): v = kwargs.get(name, self._session.defaults[name]); return 1 if v else 0
2809
+ def _ck(name): return kwargs.get(name, self._session.defaults.get(name))
2810
+ def _ckb(name): v = kwargs.get(name, self._session.defaults.get(name)); return 1 if v else 0
2799
2811
  ck_hash = _compute_cache_key_hash({
2800
2812
  "client_identifier": _ck("client_identifier") or "",
2801
2813
  "proxy": _ck("proxy") or "",
@@ -2860,6 +2872,11 @@ class AsyncSession:
2860
2872
  safe_timeout = max(60.0, min(go_timeout * 2.0 + 10.0, 600.0))
2861
2873
 
2862
2874
  def _on_zombie_timeout(rid: int) -> None:
2875
+ # Safe: by this point the Go goroutine has either completed
2876
+ # (callback fired) or is hung. If completed, _pending_requests
2877
+ # already popped and we return early. If hung, the goroutine
2878
+ # owns its own body copy (deepCopyRequestOptions copies via
2879
+ # C.GoBytes — Bug #5 fix), so releasing keep_alive is safe.
2863
2880
  with _pending_lock:
2864
2881
  entry = _pending_requests.pop(rid, None)
2865
2882
  if entry is None:
@@ -2893,6 +2910,10 @@ class AsyncSession:
2893
2910
  ret = lib.RequestAsync(opts, request_id, callback)
2894
2911
 
2895
2912
  if ret != 0:
2913
+ # RequestAsync returned an error — clean up the pending entry
2914
+ # and cancel the defensive zombie timeout. keep_alive is
2915
+ # already safe to release because RequestAsync deep-copies
2916
+ # before returning.
2896
2917
  with _pending_lock:
2897
2918
  entry = _pending_requests.pop(request_id, None)
2898
2919
  if entry is not None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tls-client-python
3
- Version: 1.14.1
3
+ Version: 1.15.0.1
4
4
  Summary: High-performance Python binding for bogdanfinn/tls-client via CFFI – zero-copy, panic-proof, full TLS fingerprint control
5
5
  Author: komAAmok
6
6
  License: MIT
@@ -67,7 +67,7 @@ For a deep dive, see [this excellent article on TLS fingerprinting](https://http
67
67
  | 🚇 **Proxy Support** | HTTP and SOCKS5 proxies with CONNECT auth |
68
68
  | 🔀 **Redirect Control** | Choose whether to follow redirects per request |
69
69
  | 📊 **Bandwidth Tracking** | Monitor upload/download bytes in real time |
70
- | 🧵 **Async Support** | `AsyncSession` for asyncio integration |
70
+ | 🔄 **sync/Async** | `Session` + `AsyncSession` |
71
71
  | 🛡️ **Panic-proof** | All Go panics caught and surfaced as Python exceptions |
72
72
  | ⚙️ **Custom TLS** | Full 26-field custom TLS client configuration |
73
73
 
@@ -81,9 +81,7 @@ pip install tls-client-python
81
81
 
82
82
  Pre-compiled binaries are included for **9 platforms** — no Go toolchain required.
83
83
 
84
- ### Requirements
85
-
86
- - Python 3.6+
84
+ > **Requirements:** Python 3.6+
87
85
 
88
86
  ---
89
87
 
@@ -93,41 +91,35 @@ Pre-compiled binaries are included for **9 platforms** — no Go toolchain requi
93
91
  from tls_client import Session
94
92
 
95
93
  # Create a session with Chrome 146 fingerprint
96
- session = Session(client_identifier="chrome_146")
94
+ session = Session(client_identifier="chrome_146", verify=False)
97
95
 
98
96
  # GET request
99
97
  resp = session.get("https://tls.browserleaks.com/json")
100
- print(resp.status_code) # 200
101
- print(resp.text) # JSON body
102
- print(resp.used_protocol) # "HTTP/2.0"
103
-
104
- # POST with JSON
105
- resp = session.post(
106
- "https://tls.browserleaks.com/json",
107
- body=b'{"hello":"world"}',
108
- headers={"Content-Type": "application/json"}
109
- )
98
+ print(resp.status_code)
99
+ print(resp.text)
100
+
101
+ # POST request
102
+ resp = session.post("https://tools.scrapfly.io/api/fp/ja3")
110
103
  data = resp.json()
111
- print(data["json"]) # {"hello": "world"}
112
- ```
104
+ print(resp.status_code)
105
+ print(data)
113
106
 
114
- ### Context Manager
115
107
 
116
- ```python
117
- with Session(client_identifier="safari_ios_18_5") as s:
118
- resp = s.get("https://tls.browserleaks.com/json")
108
+ # Context Manager
109
+ with Session(client_identifier="firefox_148") as session:
110
+ resp = session.get("https://tls.browserleaks.com/json")
119
111
  print(resp.status_code)
120
- ```
112
+ print(resp.text)
121
113
 
122
- ### Async Usage
123
114
 
124
- ```python
115
+ # Async Usage
125
116
  import asyncio
126
117
  from tls_client import AsyncSession
127
118
 
128
119
  async def main():
129
120
  async with AsyncSession(client_identifier="firefox_148") as s:
130
121
  resp = await s.get("https://tls.browserleaks.com/json")
122
+ print(resp.status_code)
131
123
  print(resp.json())
132
124
 
133
125
  asyncio.run(main())
@@ -157,16 +149,6 @@ The correct binary is automatically selected at runtime. Override via `TLS_CLIEN
157
149
 
158
150
  ## 🎭 Supported Browser Profiles — 79 Identifiers
159
151
 
160
- Set `client_identifier` in `Session()` to impersonate any of these browsers. Inspect the full list at runtime:
161
-
162
- ```python
163
- from tls_client import list_client_identifiers, SUPPORTED_CLIENT_IDENTIFIERS
164
-
165
- print(len(list_client_identifiers())) # 79
166
- for browser, ids in SUPPORTED_CLIENT_IDENTIFIERS.items():
167
- print(f"{browser}: {len(ids)} profiles")
168
- ```
169
-
170
152
  ### 🌐 Chrome — 24 Profiles
171
153
 
172
154
  | Identifier | Notes |