tls-client-python 1.15.0__tar.gz → 1.15.0.2__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 (25) hide show
  1. {tls_client_python-1.15.0/tls_client_python.egg-info → tls_client_python-1.15.0.2}/PKG-INFO +18 -37
  2. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/Readme.md +16 -34
  3. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/pyproject.toml +1 -2
  4. tls_client_python-1.15.0.2/setup.py +12 -0
  5. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/tls_client/__init__.py +1 -16
  6. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/tls_client/_core.py +55 -122
  7. tls_client_python-1.15.0/tls_client/bin/tls-client-linux-amd64.so → tls_client_python-1.15.0.2/tls_client/bin/tls-client-alpine-amd64.so +0 -0
  8. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/tls_client/bin/tls-client-darwin-amd64.dylib +0 -0
  9. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/tls_client/bin/tls-client-darwin-arm64.dylib +0 -0
  10. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/tls_client/bin/tls-client-linux-386.so +0 -0
  11. tls_client_python-1.15.0/tls_client/bin/tls-client-alpine-amd64.so → tls_client_python-1.15.0.2/tls_client/bin/tls-client-linux-amd64.so +0 -0
  12. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/tls_client/bin/tls-client-linux-arm.so +0 -0
  13. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/tls_client/bin/tls-client-linux-arm64.so +0 -0
  14. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/tls_client/bin/tls-client-windows-386.dll +0 -0
  15. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/tls_client/bin/tls-client-windows-amd64.dll +0 -0
  16. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2/tls_client_python.egg-info}/PKG-INFO +18 -37
  17. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/tls_client_python.egg-info/SOURCES.txt +1 -0
  18. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/LICENSE +0 -0
  19. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/MANIFEST.in +0 -0
  20. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/setup.cfg +0 -0
  21. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/tls_client/_default_headers.py +0 -0
  22. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/tls_client_python.egg-info/dependency_links.txt +0 -0
  23. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/tls_client_python.egg-info/not-zip-safe +0 -0
  24. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/tls_client_python.egg-info/requires.txt +0 -0
  25. {tls_client_python-1.15.0 → tls_client_python-1.15.0.2}/tls_client_python.egg-info/top_level.txt +0 -0
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tls-client-python
3
- Version: 1.15.0
3
+ Version: 1.15.0.2
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
- License: MIT
6
+ License-Expression: MIT
7
7
  Project-URL: Homepage, https://github.com/komAAmok/tls-client-python
8
8
  Project-URL: Documentation, https://github.com/komAAmok/tls-client-python#readme
9
9
  Project-URL: Repository, https://github.com/komAAmok/tls-client-python
@@ -11,7 +11,6 @@ Project-URL: Issues, https://github.com/komAAmok/tls-client-python/issues
11
11
  Keywords: tls,tls-fingerprint,http-client,ja3,http2,http3,quic,cffi,akamai,cloudflare,anti-bot
12
12
  Classifier: Development Status :: 4 - Beta
13
13
  Classifier: Intended Audience :: Developers
14
- Classifier: License :: OSI Approved :: MIT License
15
14
  Classifier: Operating System :: MacOS :: MacOS X
16
15
  Classifier: Operating System :: Microsoft :: Windows
17
16
  Classifier: Operating System :: POSIX :: Linux
@@ -67,7 +66,7 @@ For a deep dive, see [this excellent article on TLS fingerprinting](https://http
67
66
  | 🚇 **Proxy Support** | HTTP and SOCKS5 proxies with CONNECT auth |
68
67
  | 🔀 **Redirect Control** | Choose whether to follow redirects per request |
69
68
  | 📊 **Bandwidth Tracking** | Monitor upload/download bytes in real time |
70
- | 🧵 **Async Support** | `AsyncSession` for asyncio integration |
69
+ | 🔄 **sync/Async** | `Session` + `AsyncSession` |
71
70
  | 🛡️ **Panic-proof** | All Go panics caught and surfaced as Python exceptions |
72
71
  | ⚙️ **Custom TLS** | Full 26-field custom TLS client configuration |
73
72
 
@@ -81,9 +80,7 @@ pip install tls-client-python
81
80
 
82
81
  Pre-compiled binaries are included for **9 platforms** — no Go toolchain required.
83
82
 
84
- ### Requirements
85
-
86
- - Python 3.6+
83
+ > **Requirements:** Python 3.6+
87
84
 
88
85
  ---
89
86
 
@@ -93,41 +90,35 @@ Pre-compiled binaries are included for **9 platforms** — no Go toolchain requi
93
90
  from tls_client import Session
94
91
 
95
92
  # Create a session with Chrome 146 fingerprint
96
- session = Session(client_identifier="chrome_146")
93
+ session = Session(client_identifier="chrome_146", verify=False)
97
94
 
98
95
  # GET request
99
96
  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
- )
97
+ print(resp.status_code)
98
+ print(resp.text)
99
+
100
+ # POST request
101
+ resp = session.post("https://tools.scrapfly.io/api/fp/ja3")
110
102
  data = resp.json()
111
- print(data["json"]) # {"hello": "world"}
112
- ```
103
+ print(resp.status_code)
104
+ print(data)
113
105
 
114
- ### Context Manager
115
106
 
116
- ```python
117
- with Session(client_identifier="safari_ios_18_5") as s:
118
- resp = s.get("https://tls.browserleaks.com/json")
107
+ # Context Manager
108
+ with Session(client_identifier="firefox_148") as session:
109
+ resp = session.get("https://tls.browserleaks.com/json")
119
110
  print(resp.status_code)
120
- ```
111
+ print(resp.text)
121
112
 
122
- ### Async Usage
123
113
 
124
- ```python
114
+ # Async Usage
125
115
  import asyncio
126
116
  from tls_client import AsyncSession
127
117
 
128
118
  async def main():
129
119
  async with AsyncSession(client_identifier="firefox_148") as s:
130
120
  resp = await s.get("https://tls.browserleaks.com/json")
121
+ print(resp.status_code)
131
122
  print(resp.json())
132
123
 
133
124
  asyncio.run(main())
@@ -157,16 +148,6 @@ The correct binary is automatically selected at runtime. Override via `TLS_CLIEN
157
148
 
158
149
  ## 🎭 Supported Browser Profiles — 79 Identifiers
159
150
 
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
151
  ### 🌐 Chrome — 24 Profiles
171
152
 
172
153
  | 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 |
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
  name = "tls-client-python"
7
7
  description = "High-performance Python binding for bogdanfinn/tls-client via CFFI – zero-copy, panic-proof, full TLS fingerprint control"
8
8
  readme = { file = "Readme.md", content-type = "text/markdown" }
9
- license = { text = "MIT" }
9
+ license = "MIT"
10
10
  authors = [
11
11
  { name = "komAAmok" }
12
12
  ]
@@ -26,7 +26,6 @@ keywords = [
26
26
  classifiers = [
27
27
  "Development Status :: 4 - Beta",
28
28
  "Intended Audience :: Developers",
29
- "License :: OSI Approved :: MIT License",
30
29
  "Operating System :: MacOS :: MacOS X",
31
30
  "Operating System :: Microsoft :: Windows",
32
31
  "Operating System :: POSIX :: Linux",
@@ -0,0 +1,12 @@
1
+ # setup.py
2
+
3
+ from setuptools import setup
4
+ from setuptools.dist import Distribution
5
+
6
+ class BinaryDistribution(Distribution):
7
+ def is_pure(foo):
8
+ return False
9
+
10
+ setup(
11
+ distclass=BinaryDistribution,
12
+ )
@@ -6,19 +6,6 @@ The package auto‑detects the host OS and architecture at import time,
6
6
  selecting the correct pre‑compiled binary from the bundled ``bin/``
7
7
  directory. A ``TLS_CLIENT_LIB`` environment variable may be used to
8
8
  override automatic discovery.
9
-
10
- Quick start
11
- -----------
12
- >>> from tls_client import Session
13
- >>> s = Session(client_identifier="chrome_146")
14
- >>> resp = s.get("https://httpbin.org/json")
15
- >>> print(resp.status_code, resp.text[:50])
16
-
17
- Async
18
- -----
19
- >>> from tls_client import AsyncSession
20
- >>> async with AsyncSession() as s:
21
- ... resp = await s.get("https://httpbin.org/json")
22
9
  """
23
10
 
24
11
  from tls_client._core import (
@@ -27,7 +14,6 @@ from tls_client._core import (
27
14
  Request,
28
15
  Response,
29
16
  ClientIdentifiers,
30
- ClientIdentifiers,
31
17
  clear_client_pool,
32
18
  )
33
19
 
@@ -37,7 +23,6 @@ __all__ = [
37
23
  "Request",
38
24
  "Response",
39
25
  "ClientIdentifiers",
40
- "ClientIdentifiers",
41
26
  "clear_client_pool",
42
27
  ]
43
- __version__ = "1.15.0"
28
+ __version__ = "1.15.0.2"
@@ -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
@@ -654,86 +654,17 @@ int RequestAsync(RequestOptions* opts, uintptr_t request_id, async_ca
654
654
  # Platform detection & shared‑library loading
655
655
  # ---------------------------------------------------------------------------
656
656
 
657
- def _detect_libc() -> str:
658
- """Detect the C library flavour on Linux. Returns ``"glibc"``, ``"musl"``, or ``"unknown"``.
659
-
660
- This is important because a shared library compiled against glibc
661
- will not load on a musl-based distribution (Alpine, Void musl, etc.)
662
- and vice versa.
663
- """
664
- if sys.platform != "linux":
665
- return "glibc" # non‑Linux → irrelevant
666
- try:
667
- # musl defines a weak symbol __musl__ that glibc does not.
668
- libc = ctypes.CDLL(None) # the process itself
669
- try:
670
- libc.__musl__ # pylint: disable=pointless-statement
671
- return "musl"
672
- except AttributeError:
673
- return "glibc"
674
- except Exception:
675
- # Fallback: check for /lib/ld-musl-*.so*
676
- for entry in Path("/lib").glob("ld-musl-*"):
677
- if entry.is_file():
678
- return "musl"
679
- return "unknown"
680
-
681
-
682
- def _libc_suffix() -> str:
683
- """Return an optional libc suffix for the library filename.
684
-
685
- Alpine (musl) binaries carry a ``-musl`` suffix so they don't collide
686
- with glibc builds on PyPI.
687
- """
688
- if sys.platform == "linux" and _detect_libc() == "musl":
689
- return "-musl"
690
- return ""
691
-
692
-
693
- def _go_os() -> str:
694
- return {"darwin": "darwin", "linux": "linux", "win32": "windows"}.get(
695
- sys.platform, sys.platform
696
- )
697
-
698
-
699
- def _go_arch() -> str:
700
- m = platform.machine().lower()
701
- return {
702
- "x86_64": "amd64", "amd64": "amd64",
703
- "arm64": "arm64", "aarch64": "arm64",
704
- "armv7l": "arm", "armv6l": "arm",
705
- "i386": "386", "i686": "386",
706
- }.get(m, m)
707
-
708
-
709
- def _shared_lib_ext() -> str:
710
- if sys.platform == "darwin":
711
- return ".dylib"
712
- elif sys.platform == "win32":
713
- return ".dll"
714
- return ".so"
715
-
716
-
717
- def _shared_lib_name() -> str:
718
- ext = _shared_lib_ext()
719
- goos = _go_os()
720
- goarch = _go_arch()
721
- lc = _libc_suffix()
722
- return f"tls-client-{goos}-{goarch}{lc}{ext}"
723
-
724
-
725
657
  def _find_library() -> str:
726
- """Locate the platform‑appropriate shared library.
658
+ """定位平台对应的动态链接库。
727
659
 
728
- Search order:
729
- 1. ``TLS_CLIENT_LIB`` environment variable (explicit user override).
730
- 2. Bundled binary in ``tls_client/bin/`` (the package directory).
731
- 3. System‑level ``dist/`` directory next to this module (dev convenience).
660
+ 搜索顺序:
661
+ 1. 读取 ``TLS_CLIENT_LIB`` 环境变量(显式用户覆盖)。
662
+ 2. 寻找包目录内 ``tls_client/bin/`` 下的平台专属统一命名文件。
663
+ 3. 寻找同级开发目录 ``dist/`` 下的文件。
732
664
 
733
- Raises :exc:`FileNotFoundError` with a detailed diagnostic message if
734
- no binary is found, including hints for Alpine/musl users.
665
+ 若未找到任何匹配文件,抛出 :exc:`FileNotFoundError`。
735
666
  """
736
- # 1. Explicit override
667
+ # 1. 环境变量显式覆盖
737
668
  env_lib = os.environ.get("TLS_CLIENT_LIB")
738
669
  if env_lib:
739
670
  p = Path(env_lib)
@@ -743,56 +674,37 @@ def _find_library() -> str:
743
674
  f"TLS_CLIENT_LIB is set to '{env_lib}' but the file does not exist."
744
675
  )
745
676
 
746
- name = _shared_lib_name()
677
+ # 2. 根据系统平台直接映射标准统一文件名
678
+ if sys.platform == "win32":
679
+ name = "tls-client.dll"
680
+ elif sys.platform == "darwin":
681
+ name = "tls-client.dylib"
682
+ else:
683
+ name = "tls-client.so"
684
+
747
685
  here = Path(__file__).resolve().parent
748
686
 
749
- # 2. Bundled binary in the package
687
+ # 3. 寻找分平台 Wheel 安装后的专属内置路径
750
688
  bundled = here / "bin" / name
751
689
  if bundled.exists():
752
690
  return str(bundled)
753
691
 
754
- # 3. Development convenience – dist/ directory next to this module
692
+ # 4. 本地开发调试路径
755
693
  dev = here / "dist" / name
756
694
  if dev.exists():
757
695
  return str(dev)
758
696
 
759
- # ---- diagnostic error message ----
697
+ # 详细的异常诊断提示
760
698
  parts = [
761
- f"Cannot locate shared library '{name}'.",
699
+ f"Cannot locate shared library '{name}' inside the package.",
762
700
  "",
763
701
  f" Searched: {bundled}",
764
702
  f" {dev}",
703
+ "",
704
+ " If you are developing locally, ensure the shared library is compiled and placed",
705
+ " in either 'tls_client/bin/' or 'tls_client/dist/'.",
706
+ " Alternatively, set the 'TLS_CLIENT_LIB' environment variable to point directly to your binary."
765
707
  ]
766
-
767
- if sys.platform == "linux":
768
- libc = _detect_libc()
769
- parts.append(f" Detected libc: {libc}")
770
- if libc == "musl":
771
- parts.append(
772
- " This is an Alpine / musl-based system. The pre-compiled glibc"
773
- )
774
- parts.append(
775
- " binary cannot be used. Build a musl-compatible library via:"
776
- )
777
- parts.append(
778
- " cd cffi_binding && CGO_ENABLED=1 GOOS=linux GOARCH="
779
- + _go_arch()
780
- + " go build -buildmode=c-shared -o tls-client-linux-"
781
- + _go_arch()
782
- + "-musl.so ."
783
- )
784
- else:
785
- parts.append(
786
- " Make sure the platform matches. Expected: "
787
- + _go_os()
788
- + "/"
789
- + _go_arch()
790
- )
791
-
792
- parts.append(
793
- " Set the TLS_CLIENT_LIB environment variable to point to the correct binary."
794
- )
795
-
796
708
  raise FileNotFoundError("\n".join(parts))
797
709
 
798
710
 
@@ -1117,6 +1029,12 @@ def _compute_cache_key_hash(r: dict) -> str:
1117
1029
 
1118
1030
  The format matches Go's buildCacheKey exactly — same field order,
1119
1031
  same separators, same sort order for maps, same hex encoding.
1032
+
1033
+ FORMAT VERSION: 1
1034
+ If you change the hash format below, increment the version AND update
1035
+ Go's buildCacheKey / buildCacheKeyFromConfig in cffi_binding/main.go
1036
+ and the corresponding test in test_cache_key_parity.py. Format drift
1037
+ causes silent cache poisoning (different keys → duplicate clients).
1120
1038
  """
1121
1039
  h = hashlib.sha256()
1122
1040
 
@@ -1264,7 +1182,7 @@ def _populate_request_options(
1264
1182
  def _val(name: str, as_bool: bool = False) -> Any:
1265
1183
  v = overrides.get(name)
1266
1184
  if v is None:
1267
- v = defaults[name]
1185
+ v = defaults.get(name) # defensive: missing key → None instead of KeyError
1268
1186
  if as_bool:
1269
1187
  return 1 if v else 0
1270
1188
  return v
@@ -2109,7 +2027,7 @@ class Session:
2109
2027
  ffi, lib = _get_ffi()
2110
2028
 
2111
2029
  def _val(name: str, override, as_bool: bool = False):
2112
- v = override if override is not None else self.defaults[name]
2030
+ v = override if override is not None else self.defaults.get(name)
2113
2031
  if as_bool:
2114
2032
  return 1 if v else 0
2115
2033
  return v
@@ -2490,12 +2408,18 @@ _async_callback_lock = threading.Lock()
2490
2408
 
2491
2409
 
2492
2410
  def _get_async_callback(ffi, lib):
2411
+ """Return the singleton CFFI callback, creating it once under lock.
2412
+
2413
+ Always acquires _async_callback_lock — double‑checked locking is unsafe
2414
+ under free‑threaded Python (PEP 703) because _async_callback may be
2415
+ partially visible without a synchronisation edge. Contention is
2416
+ negligible: the callback is created once and cached thereafter.
2417
+ """
2493
2418
  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
2419
+ with _async_callback_lock:
2420
+ if _async_callback is None:
2421
+ _async_callback = _make_async_callback(ffi, lib)
2422
+ return _async_callback
2499
2423
 
2500
2424
 
2501
2425
  class AsyncSession:
@@ -2704,7 +2628,7 @@ class AsyncSession:
2704
2628
  def _val(name: str, as_bool: bool = False):
2705
2629
  v = kwargs.pop(name, None)
2706
2630
  if v is None:
2707
- v = self._session.defaults[name]
2631
+ v = self._session.defaults.get(name)
2708
2632
  if as_bool:
2709
2633
  return 1 if v else 0
2710
2634
  return v
@@ -2794,8 +2718,8 @@ class AsyncSession:
2794
2718
 
2795
2719
  # Pre-compute cache key hash and attach to opts (avoids ~50 CGO calls on hit).
2796
2720
  # 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
2721
+ def _ck(name): return kwargs.get(name, self._session.defaults.get(name))
2722
+ def _ckb(name): v = kwargs.get(name, self._session.defaults.get(name)); return 1 if v else 0
2799
2723
  ck_hash = _compute_cache_key_hash({
2800
2724
  "client_identifier": _ck("client_identifier") or "",
2801
2725
  "proxy": _ck("proxy") or "",
@@ -2860,6 +2784,11 @@ class AsyncSession:
2860
2784
  safe_timeout = max(60.0, min(go_timeout * 2.0 + 10.0, 600.0))
2861
2785
 
2862
2786
  def _on_zombie_timeout(rid: int) -> None:
2787
+ # Safe: by this point the Go goroutine has either completed
2788
+ # (callback fired) or is hung. If completed, _pending_requests
2789
+ # already popped and we return early. If hung, the goroutine
2790
+ # owns its own body copy (deepCopyRequestOptions copies via
2791
+ # C.GoBytes — Bug #5 fix), so releasing keep_alive is safe.
2863
2792
  with _pending_lock:
2864
2793
  entry = _pending_requests.pop(rid, None)
2865
2794
  if entry is None:
@@ -2893,6 +2822,10 @@ class AsyncSession:
2893
2822
  ret = lib.RequestAsync(opts, request_id, callback)
2894
2823
 
2895
2824
  if ret != 0:
2825
+ # RequestAsync returned an error — clean up the pending entry
2826
+ # and cancel the defensive zombie timeout. keep_alive is
2827
+ # already safe to release because RequestAsync deep-copies
2828
+ # before returning.
2896
2829
  with _pending_lock:
2897
2830
  entry = _pending_requests.pop(request_id, None)
2898
2831
  if entry is not None:
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tls-client-python
3
- Version: 1.15.0
3
+ Version: 1.15.0.2
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
- License: MIT
6
+ License-Expression: MIT
7
7
  Project-URL: Homepage, https://github.com/komAAmok/tls-client-python
8
8
  Project-URL: Documentation, https://github.com/komAAmok/tls-client-python#readme
9
9
  Project-URL: Repository, https://github.com/komAAmok/tls-client-python
@@ -11,7 +11,6 @@ Project-URL: Issues, https://github.com/komAAmok/tls-client-python/issues
11
11
  Keywords: tls,tls-fingerprint,http-client,ja3,http2,http3,quic,cffi,akamai,cloudflare,anti-bot
12
12
  Classifier: Development Status :: 4 - Beta
13
13
  Classifier: Intended Audience :: Developers
14
- Classifier: License :: OSI Approved :: MIT License
15
14
  Classifier: Operating System :: MacOS :: MacOS X
16
15
  Classifier: Operating System :: Microsoft :: Windows
17
16
  Classifier: Operating System :: POSIX :: Linux
@@ -67,7 +66,7 @@ For a deep dive, see [this excellent article on TLS fingerprinting](https://http
67
66
  | 🚇 **Proxy Support** | HTTP and SOCKS5 proxies with CONNECT auth |
68
67
  | 🔀 **Redirect Control** | Choose whether to follow redirects per request |
69
68
  | 📊 **Bandwidth Tracking** | Monitor upload/download bytes in real time |
70
- | 🧵 **Async Support** | `AsyncSession` for asyncio integration |
69
+ | 🔄 **sync/Async** | `Session` + `AsyncSession` |
71
70
  | 🛡️ **Panic-proof** | All Go panics caught and surfaced as Python exceptions |
72
71
  | ⚙️ **Custom TLS** | Full 26-field custom TLS client configuration |
73
72
 
@@ -81,9 +80,7 @@ pip install tls-client-python
81
80
 
82
81
  Pre-compiled binaries are included for **9 platforms** — no Go toolchain required.
83
82
 
84
- ### Requirements
85
-
86
- - Python 3.6+
83
+ > **Requirements:** Python 3.6+
87
84
 
88
85
  ---
89
86
 
@@ -93,41 +90,35 @@ Pre-compiled binaries are included for **9 platforms** — no Go toolchain requi
93
90
  from tls_client import Session
94
91
 
95
92
  # Create a session with Chrome 146 fingerprint
96
- session = Session(client_identifier="chrome_146")
93
+ session = Session(client_identifier="chrome_146", verify=False)
97
94
 
98
95
  # GET request
99
96
  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
- )
97
+ print(resp.status_code)
98
+ print(resp.text)
99
+
100
+ # POST request
101
+ resp = session.post("https://tools.scrapfly.io/api/fp/ja3")
110
102
  data = resp.json()
111
- print(data["json"]) # {"hello": "world"}
112
- ```
103
+ print(resp.status_code)
104
+ print(data)
113
105
 
114
- ### Context Manager
115
106
 
116
- ```python
117
- with Session(client_identifier="safari_ios_18_5") as s:
118
- resp = s.get("https://tls.browserleaks.com/json")
107
+ # Context Manager
108
+ with Session(client_identifier="firefox_148") as session:
109
+ resp = session.get("https://tls.browserleaks.com/json")
119
110
  print(resp.status_code)
120
- ```
111
+ print(resp.text)
121
112
 
122
- ### Async Usage
123
113
 
124
- ```python
114
+ # Async Usage
125
115
  import asyncio
126
116
  from tls_client import AsyncSession
127
117
 
128
118
  async def main():
129
119
  async with AsyncSession(client_identifier="firefox_148") as s:
130
120
  resp = await s.get("https://tls.browserleaks.com/json")
121
+ print(resp.status_code)
131
122
  print(resp.json())
132
123
 
133
124
  asyncio.run(main())
@@ -157,16 +148,6 @@ The correct binary is automatically selected at runtime. Override via `TLS_CLIEN
157
148
 
158
149
  ## 🎭 Supported Browser Profiles — 79 Identifiers
159
150
 
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
151
  ### 🌐 Chrome — 24 Profiles
171
152
 
172
153
  | Identifier | Notes |
@@ -2,6 +2,7 @@ LICENSE
2
2
  MANIFEST.in
3
3
  Readme.md
4
4
  pyproject.toml
5
+ setup.py
5
6
  tls_client/__init__.py
6
7
  tls_client/_core.py
7
8
  tls_client/_default_headers.py