tls-client-python 1.15.0.1__tar.gz → 1.15.0.3__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 (27) hide show
  1. {tls_client_python-1.15.0.1/tls_client_python.egg-info → tls_client_python-1.15.0.3}/PKG-INFO +5 -6
  2. {tls_client_python-1.15.0.1 → tls_client_python-1.15.0.3}/Readme.md +0 -2
  3. {tls_client_python-1.15.0.1 → tls_client_python-1.15.0.3}/pyproject.toml +4 -3
  4. tls_client_python-1.15.0.3/setup.py +12 -0
  5. {tls_client_python-1.15.0.1 → tls_client_python-1.15.0.3}/tls_client/__init__.py +1 -16
  6. {tls_client_python-1.15.0.1 → tls_client_python-1.15.0.3}/tls_client/_core.py +210 -104
  7. {tls_client_python-1.15.0.1 → tls_client_python-1.15.0.3}/tls_client/bin/tls-client-darwin-amd64.dylib +0 -0
  8. {tls_client_python-1.15.0.1 → tls_client_python-1.15.0.3}/tls_client/bin/tls-client-darwin-arm64.dylib +0 -0
  9. tls_client_python-1.15.0.1/tls_client/bin/tls-client-linux-amd64.so → tls_client_python-1.15.0.3/tls_client/bin/tls-client-linux-amd64-musl.so +0 -0
  10. tls_client_python-1.15.0.1/tls_client/bin/tls-client-alpine-amd64.so → tls_client_python-1.15.0.3/tls_client/bin/tls-client-linux-amd64.so +0 -0
  11. tls_client_python-1.15.0.3/tls_client/bin/tls-client-windows-386.dll +0 -0
  12. tls_client_python-1.15.0.3/tls_client/bin/tls-client-windows-amd64.dll +0 -0
  13. {tls_client_python-1.15.0.1 → tls_client_python-1.15.0.3/tls_client_python.egg-info}/PKG-INFO +5 -6
  14. {tls_client_python-1.15.0.1 → tls_client_python-1.15.0.3}/tls_client_python.egg-info/SOURCES.txt +2 -4
  15. tls_client_python-1.15.0.1/tls_client/bin/tls-client-linux-386.so +0 -0
  16. tls_client_python-1.15.0.1/tls_client/bin/tls-client-linux-arm.so +0 -0
  17. tls_client_python-1.15.0.1/tls_client/bin/tls-client-linux-arm64.so +0 -0
  18. tls_client_python-1.15.0.1/tls_client/bin/tls-client-windows-386.dll +0 -0
  19. tls_client_python-1.15.0.1/tls_client/bin/tls-client-windows-amd64.dll +0 -0
  20. {tls_client_python-1.15.0.1 → tls_client_python-1.15.0.3}/LICENSE +0 -0
  21. {tls_client_python-1.15.0.1 → tls_client_python-1.15.0.3}/MANIFEST.in +0 -0
  22. {tls_client_python-1.15.0.1 → tls_client_python-1.15.0.3}/setup.cfg +0 -0
  23. {tls_client_python-1.15.0.1 → tls_client_python-1.15.0.3}/tls_client/_default_headers.py +0 -0
  24. {tls_client_python-1.15.0.1 → tls_client_python-1.15.0.3}/tls_client_python.egg-info/dependency_links.txt +0 -0
  25. {tls_client_python-1.15.0.1 → tls_client_python-1.15.0.3}/tls_client_python.egg-info/not-zip-safe +0 -0
  26. {tls_client_python-1.15.0.1 → tls_client_python-1.15.0.3}/tls_client_python.egg-info/requires.txt +0 -0
  27. {tls_client_python-1.15.0.1 → tls_client_python-1.15.0.3}/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.1
3
+ Version: 1.15.0.3
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
@@ -23,11 +22,13 @@ Classifier: Programming Language :: Python :: 3.9
23
22
  Classifier: Programming Language :: Python :: 3.10
24
23
  Classifier: Programming Language :: Python :: 3.11
25
24
  Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Programming Language :: Python :: 3.13
26
+ Classifier: Programming Language :: Python :: 3.14
26
27
  Classifier: Programming Language :: Python :: Implementation :: CPython
27
28
  Classifier: Topic :: Internet :: WWW/HTTP
28
29
  Classifier: Topic :: Security
29
30
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
30
- Requires-Python: <3.13,>=3.6
31
+ Requires-Python: <=3.14,>=3.6
31
32
  Description-Content-Type: text/markdown
32
33
  License-File: LICENSE
33
34
  Requires-Dist: cffi>=1.14.0
@@ -41,8 +42,6 @@ Dynamic: license-file
41
42
 
42
43
  **High-performance Python binding for [bogdanfinn/tls-client](https://github.com/bogdanfinn/tls-client) via CFFI.**
43
44
 
44
- Zero-copy FFI boundary, panic-proof, full TLS fingerprint control — with a familiar `requests`-style API.
45
-
46
45
  ---
47
46
 
48
47
  ## What is TLS Fingerprinting?
@@ -6,8 +6,6 @@
6
6
 
7
7
  **High-performance Python binding for [bogdanfinn/tls-client](https://github.com/bogdanfinn/tls-client) via CFFI.**
8
8
 
9
- Zero-copy FFI boundary, panic-proof, full TLS fingerprint control — with a familiar `requests`-style API.
10
-
11
9
  ---
12
10
 
13
11
  ## What is TLS Fingerprinting?
@@ -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",
@@ -38,6 +37,8 @@ classifiers = [
38
37
  "Programming Language :: Python :: 3.10",
39
38
  "Programming Language :: Python :: 3.11",
40
39
  "Programming Language :: Python :: 3.12",
40
+ "Programming Language :: Python :: 3.13",
41
+ "Programming Language :: Python :: 3.14",
41
42
  "Programming Language :: Python :: Implementation :: CPython",
42
43
  "Topic :: Internet :: WWW/HTTP",
43
44
  "Topic :: Security",
@@ -45,7 +46,7 @@ classifiers = [
45
46
  ]
46
47
 
47
48
 
48
- requires-python = ">=3.6, <3.13"
49
+ requires-python = ">=3.6, <=3.14"
49
50
 
50
51
  dependencies = [
51
52
  "cffi>=1.14.0",
@@ -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.1"
28
+ __version__ = "1.15.0.3"
@@ -278,6 +278,26 @@ class Request(TypedDict, total=False):
278
278
 
279
279
  Whether to disable IPv6.
280
280
  """
281
+ tcp_ttl: Optional[int]
282
+ """IP TTL 覆盖。0=自动从预设推断。
283
+
284
+ IP TTL override. 0=auto from profile.
285
+ """
286
+ tcp_window_size: Optional[int]
287
+ """TCP 窗口大小覆盖。0=自动从预设推断。
288
+
289
+ TCP window size override. 0=auto from profile.
290
+ """
291
+ tcp_window_scale: Optional[int]
292
+ """TCP 窗口缩放因子覆盖。0=自动从预设推断。
293
+
294
+ TCP window scale override. 0=auto from profile.
295
+ """
296
+ tcp_mss: Optional[int]
297
+ """TCP MSS 覆盖。0=自动从预设推断。
298
+
299
+ TCP MSS override. 0=auto from profile.
300
+ """
281
301
  catch_panics: Optional[bool]
282
302
  """是否捕获 Go panic。
283
303
 
@@ -604,6 +624,10 @@ typedef struct {
604
624
  int disable_http3;
605
625
  int disable_ipv4;
606
626
  int disable_ipv6;
627
+ int tcp_ttl;
628
+ int tcp_window_size;
629
+ int tcp_window_scale;
630
+ int tcp_mss;
607
631
  int without_cookie_jar;
608
632
  int catch_panics;
609
633
  int with_debug;
@@ -651,28 +675,21 @@ int RequestAsync(RequestOptions* opts, uintptr_t request_id, async_ca
651
675
  """
652
676
 
653
677
  # ---------------------------------------------------------------------------
654
- # Platform detection & shared‑library loading
678
+ # Platform-native shared library dynamic discovery (Git-Sync & Wheel Optimized)
655
679
  # ---------------------------------------------------------------------------
656
680
 
657
681
  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
- """
682
+ """在 Linux 系统上检测 C 运行库类型(glibc 或 musl)。"""
664
683
  if sys.platform != "linux":
665
- return "glibc" # non‑Linux → irrelevant
684
+ return "glibc"
666
685
  try:
667
- # musl defines a weak symbol __musl__ that glibc does not.
668
- libc = ctypes.CDLL(None) # the process itself
686
+ libc = ctypes.CDLL(None)
669
687
  try:
670
688
  libc.__musl__ # pylint: disable=pointless-statement
671
689
  return "musl"
672
690
  except AttributeError:
673
691
  return "glibc"
674
692
  except Exception:
675
- # Fallback: check for /lib/ld-musl-*.so*
676
693
  for entry in Path("/lib").glob("ld-musl-*"):
677
694
  if entry.is_file():
678
695
  return "musl"
@@ -680,11 +697,7 @@ def _detect_libc() -> str:
680
697
 
681
698
 
682
699
  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
- """
700
+ """如果是 Alpine (musl) 系统,返回 -musl 后缀。"""
688
701
  if sys.platform == "linux" and _detect_libc() == "musl":
689
702
  return "-musl"
690
703
  return ""
@@ -723,17 +736,14 @@ def _shared_lib_name() -> str:
723
736
 
724
737
 
725
738
  def _find_library() -> str:
726
- """Locate the platform‑appropriate shared library.
727
-
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).
739
+ """定位平台对应的动态链接库。
732
740
 
733
- Raises :exc:`FileNotFoundError` with a detailed diagnostic message if
734
- no binary is found, including hints for Alpine/musl users.
741
+ 搜索顺序:
742
+ 1. 读取 ``TLS_CLIENT_LIB`` 环境变量(显式用户覆盖)。
743
+ 2. 寻找包目录内 ``tls_client/bin/`` 下的带架构后缀文件(如 tls-client-windows-amd64.dll)。
744
+ 3. 寻找同级开发目录 ``dist/`` 下的文件。
735
745
  """
736
- # 1. Explicit override
746
+ # 1. 环境变量显式覆盖
737
747
  env_lib = os.environ.get("TLS_CLIENT_LIB")
738
748
  if env_lib:
739
749
  p = Path(env_lib)
@@ -746,53 +756,24 @@ def _find_library() -> str:
746
756
  name = _shared_lib_name()
747
757
  here = Path(__file__).resolve().parent
748
758
 
749
- # 2. Bundled binary in the package
759
+ # 2. 寻找包目录 bin/ 下的多系统共享动态库
750
760
  bundled = here / "bin" / name
751
761
  if bundled.exists():
752
762
  return str(bundled)
753
763
 
754
- # 3. Development convenience – dist/ directory next to this module
764
+ # 3. 本地开发调试路径
755
765
  dev = here / "dist" / name
756
766
  if dev.exists():
757
767
  return str(dev)
758
768
 
759
- # ---- diagnostic error message ----
760
769
  parts = [
761
- f"Cannot locate shared library '{name}'.",
770
+ f"Cannot locate shared library '{name}' inside the package.",
762
771
  "",
763
772
  f" Searched: {bundled}",
764
773
  f" {dev}",
774
+ "",
775
+ " Set the 'TLS_CLIENT_LIB' environment variable to point directly to your binary."
765
776
  ]
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
777
  raise FileNotFoundError("\n".join(parts))
797
778
 
798
779
 
@@ -1118,7 +1099,7 @@ def _compute_cache_key_hash(r: dict) -> str:
1118
1099
  The format matches Go's buildCacheKey exactly — same field order,
1119
1100
  same separators, same sort order for maps, same hex encoding.
1120
1101
 
1121
- FORMAT VERSION: 1
1102
+ FORMAT VERSION: 2
1122
1103
  If you change the hash format below, increment the version AND update
1123
1104
  Go's buildCacheKey / buildCacheKeyFromConfig in cffi_binding/main.go
1124
1105
  and the corresponding test in test_cache_key_parity.py. Format drift
@@ -1144,7 +1125,8 @@ def _compute_cache_key_hash(r: dict) -> str:
1144
1125
  f"{r['disable_ipv4']}|{r['disable_ipv6']}|{r['follow_redirects']}|"
1145
1126
  f"{r['without_cookie_jar']}|{r['allow_empty_cookies']}|"
1146
1127
  f"{r['with_default_bad_pin_handler']}|"
1147
- f"{r['timeout_seconds']}|{r['timeout_milliseconds']}"
1128
+ f"{r['timeout_seconds']}|{r['timeout_milliseconds']}|"
1129
+ f"{r['tcp_ttl']}|{r['tcp_window_size']}|{r['tcp_window_scale']}|{r['tcp_mss']}"
1148
1130
  )
1149
1131
  h.update(main.encode("utf-8"))
1150
1132
 
@@ -1351,6 +1333,10 @@ def _populate_request_options(
1351
1333
  opts.disable_http3 = _val("disable_http3", True)
1352
1334
  opts.disable_ipv4 = _val("disable_ipv4", True)
1353
1335
  opts.disable_ipv6 = _val("disable_ipv6", True)
1336
+ opts.tcp_ttl = _val("tcp_ttl")
1337
+ opts.tcp_window_size = _val("tcp_window_size")
1338
+ opts.tcp_window_scale = _val("tcp_window_scale")
1339
+ opts.tcp_mss = _val("tcp_mss")
1354
1340
  opts.catch_panics = _val("catch_panics", True)
1355
1341
  opts.with_debug = _val("with_debug", True)
1356
1342
 
@@ -1785,9 +1771,41 @@ class Session:
1785
1771
  """是否禁用 IPv6 / Whether to disable IPv6."""
1786
1772
  return bool(self.defaults["disable_ipv6"])
1787
1773
 
1788
- @disable_ipv6.setter
1789
- def disable_ipv6(self, value: bool) -> None:
1790
- self.defaults["disable_ipv6"] = 1 if value else 0
1774
+ @property
1775
+ def tcp_ttl(self) -> int:
1776
+ """IP TTL / IP TTL value. 0 = auto from profile."""
1777
+ return self.defaults["tcp_ttl"]
1778
+
1779
+ @tcp_ttl.setter
1780
+ def tcp_ttl(self, value: int) -> None:
1781
+ self.defaults["tcp_ttl"] = value
1782
+
1783
+ @property
1784
+ def tcp_window_size(self) -> int:
1785
+ """TCP receive window size. 0 = auto from profile."""
1786
+ return self.defaults["tcp_window_size"]
1787
+
1788
+ @tcp_window_size.setter
1789
+ def tcp_window_size(self, value: int) -> None:
1790
+ self.defaults["tcp_window_size"] = value
1791
+
1792
+ @property
1793
+ def tcp_window_scale(self) -> int:
1794
+ """TCP window scale factor. 0 = auto from profile."""
1795
+ return self.defaults["tcp_window_scale"]
1796
+
1797
+ @tcp_window_scale.setter
1798
+ def tcp_window_scale(self, value: int) -> None:
1799
+ self.defaults["tcp_window_scale"] = value
1800
+
1801
+ @property
1802
+ def tcp_mss(self) -> int:
1803
+ """TCP Maximum Segment Size. 0 = auto from profile."""
1804
+ return self.defaults["tcp_mss"]
1805
+
1806
+ @tcp_mss.setter
1807
+ def tcp_mss(self, value: int) -> None:
1808
+ self.defaults["tcp_mss"] = value
1791
1809
 
1792
1810
  @property
1793
1811
  def allow_empty_cookies(self) -> bool:
@@ -1904,6 +1922,15 @@ class Session:
1904
1922
  disable_ipv4: bool = False,
1905
1923
  # 禁用 IPv6 / Disable IPv6
1906
1924
  disable_ipv6: bool = False,
1925
+ # ── TCP/IP Fingerprint ──
1926
+ # IP TTL (Time To Live). Windows=128, Linux/macOS=64. 0=auto from profile
1927
+ tcp_ttl: int = 0,
1928
+ # TCP receive window size. Windows=64240, Linux/macOS=65535. 0=auto
1929
+ tcp_window_size: int = 0,
1930
+ # TCP window scale factor. Windows=8, Linux=7, macOS=6. 0=auto
1931
+ tcp_window_scale: int = 0,
1932
+ # TCP Maximum Segment Size. Standard Ethernet=1460. 0=auto
1933
+ tcp_mss: int = 0,
1907
1934
  # ── Cookie ──
1908
1935
  # 是否允许空 Cookie / Whether to allow empty-value cookies
1909
1936
  allow_empty_cookies: bool = False,
@@ -1959,6 +1986,10 @@ class Session:
1959
1986
  "disable_http3": 1 if disable_http3 else 0,
1960
1987
  "disable_ipv4": 1 if disable_ipv4 else 0,
1961
1988
  "disable_ipv6": 1 if disable_ipv6 else 0,
1989
+ "tcp_ttl": tcp_ttl,
1990
+ "tcp_window_size": tcp_window_size,
1991
+ "tcp_window_scale": tcp_window_scale,
1992
+ "tcp_mss": tcp_mss,
1962
1993
  "catch_panics": 1 if catch_panics else 0,
1963
1994
  "with_debug": 1 if with_debug else 0,
1964
1995
  }
@@ -2102,6 +2133,14 @@ class Session:
2102
2133
  disable_ipv4: Optional[bool] = None,
2103
2134
  # 覆盖 IPv6 禁用 / Override disable IPv6
2104
2135
  disable_ipv6: Optional[bool] = None,
2136
+ # 覆盖 TCP TTL / Override TCP TTL
2137
+ tcp_ttl: Optional[int] = None,
2138
+ # 覆盖 TCP 窗口大小 / Override TCP window size
2139
+ tcp_window_size: Optional[int] = None,
2140
+ # 覆盖 TCP 窗口缩放 / Override TCP window scale
2141
+ tcp_window_scale: Optional[int] = None,
2142
+ # 覆盖 TCP MSS / Override TCP MSS
2143
+ tcp_mss: Optional[int] = None,
2105
2144
  # 覆盖 panic 捕获 / Override catch-panics
2106
2145
  catch_panics: Optional[bool] = None,
2107
2146
  # 覆盖调试日志 / Override debug logging
@@ -2195,6 +2234,10 @@ class Session:
2195
2234
  "disable_http3": _val("disable_http3", disable_http3, True),
2196
2235
  "disable_ipv4": _val("disable_ipv4", disable_ipv4, True),
2197
2236
  "disable_ipv6": _val("disable_ipv6", disable_ipv6, True),
2237
+ "tcp_ttl": _val("tcp_ttl", tcp_ttl),
2238
+ "tcp_window_size": _val("tcp_window_size", tcp_window_size),
2239
+ "tcp_window_scale": _val("tcp_window_scale", tcp_window_scale),
2240
+ "tcp_mss": _val("tcp_mss", tcp_mss),
2198
2241
  "follow_redirects": _val("follow_redirects", follow_redirects, True),
2199
2242
  "without_cookie_jar": _val("without_cookie_jar", without_cookie_jar, True),
2200
2243
  "allow_empty_cookies": _val("allow_empty_cookies", allow_empty_cookies, True),
@@ -2312,6 +2355,10 @@ class Session:
2312
2355
  opts.disable_http3 = _val("disable_http3", disable_http3, True)
2313
2356
  opts.disable_ipv4 = _val("disable_ipv4", disable_ipv4, True)
2314
2357
  opts.disable_ipv6 = _val("disable_ipv6", disable_ipv6, True)
2358
+ opts.tcp_ttl = _val("tcp_ttl", tcp_ttl)
2359
+ opts.tcp_window_size = _val("tcp_window_size", tcp_window_size)
2360
+ opts.tcp_window_scale = _val("tcp_window_scale", tcp_window_scale)
2361
+ opts.tcp_mss = _val("tcp_mss", tcp_mss)
2315
2362
  opts.catch_panics = _val("catch_panics", catch_panics, True)
2316
2363
  opts.with_debug = _val("with_debug", with_debug, True)
2317
2364
 
@@ -2416,6 +2463,31 @@ def _next_request_id() -> int:
2416
2463
  return _request_counter
2417
2464
 
2418
2465
 
2466
+ def _resolve_async_response(ffi, future, raw_gc):
2467
+ """Unpack C response and resolve future ON THE EVENT LOOP THREAD.
2468
+
2469
+ Called via loop.call_soon_threadsafe from the CFFI callback bridge.
2470
+ By deferring all ffi.string / ffi.buffer / .decode() operations to the
2471
+ event loop thread, the Go OS thread callback releases the GIL in
2472
+ microseconds instead of milliseconds — eliminating GIL contention at
2473
+ high concurrency (>10K req/s).
2474
+
2475
+ C memory is kept alive by ffi.gc(raw_res, lib.FreeResponse) until
2476
+ this function completes and the reference to raw_gc is dropped.
2477
+ """
2478
+ try:
2479
+ if not future.done():
2480
+ if raw_gc.err_msg != ffi.NULL:
2481
+ err = ffi.string(raw_gc.err_msg).decode("utf-8", errors="replace")
2482
+ future.set_exception(RuntimeError(err))
2483
+ else:
2484
+ response = _unpack_c_response(ffi, raw_gc)
2485
+ future.set_result(response)
2486
+ except BaseException as exc:
2487
+ if not future.done():
2488
+ future.set_exception(exc)
2489
+
2490
+
2419
2491
  def _make_async_callback(ffi, lib):
2420
2492
  """Create a CFFI callback that Go goroutines invoke with results.
2421
2493
 
@@ -2435,55 +2507,67 @@ def _make_async_callback(ffi, lib):
2435
2507
 
2436
2508
  @ffi.callback("void(uintptr_t, ResponseResult*)")
2437
2509
  def _on_async_response(request_id: int, raw_res: Any) -> None:
2438
- # The ENTIRE callback body MUST be wrapped in try/except Exception.
2439
2510
  # This callback executes on a Go-managed OS thread. If any Python
2440
2511
  # exception escapes uncaught, the Python interpreter crashes with
2441
- # Fatal Python error: Segmentation fault (Constraint 3).
2442
- try:
2443
- # Step 5-6: Unpack response
2444
- if raw_res == ffi.NULL or raw_res.err_msg != ffi.NULL:
2445
- err = "Go engine returned NULL"
2446
- if raw_res != ffi.NULL and raw_res.err_msg != ffi.NULL:
2447
- err = ffi.string(raw_res.err_msg).decode("utf-8", errors="replace")
2448
- response: Any = RuntimeError(err)
2449
- else:
2450
- response = _unpack_c_response(ffi, raw_res)
2451
- except Exception as exc:
2452
- response = exc
2453
- finally:
2454
- # Step 6: Free C memory in all code paths (success, error, panic)
2455
- if raw_res != ffi.NULL:
2456
- lib.FreeResponse(raw_res)
2457
-
2458
- # Step 9: Schedule Future resolution on the event loop thread.
2459
- # Must use call_soon_threadsafe — direct set_result/set_exception
2460
- # from a non-event-loop thread is NOT thread-safe (Constraint 4).
2512
+ # Fatal Python error: Segmentation fault.
2513
+ #
2514
+ # GIL OPTIMIZATION: Instead of doing expensive ffi.string / ffi.buffer
2515
+ # / .decode() work here (which holds the GIL for milliseconds), we
2516
+ # immediately wrap raw_res with ffi.gc (keeping C memory alive) and
2517
+ # defer ALL unpacking to the event loop thread via call_soon_threadsafe.
2518
+ # The callback releases the GIL in microseconds, eliminating GIL
2519
+ # contention at high concurrency (>10K req/s).
2520
+ gc_bound = False # track whether ffi.gc was called — see except handler
2461
2521
  try:
2522
+ # Phase 1: Pop _pending_requests & cancel defensive timeout.
2462
2523
  with _pending_lock:
2463
2524
  future, _keep_alive, timeout_handle = _pending_requests.pop(
2464
2525
  request_id, (None, None, None)
2465
2526
  )
2466
- # _keep_alive is now released — the goroutine has finished,
2467
- # so the C pointers it held via unsafe.Slice are no longer needed.
2527
+ # _keep_alive is now released — the goroutine has finished.
2468
2528
 
2469
- # Cancel the defensive timeout — the Go goroutine completed.
2470
2529
  if timeout_handle is not None:
2471
2530
  timeout_handle.cancel()
2472
2531
 
2473
- if future is None:
2474
- return # request was cancelled or timed out
2475
-
2476
- if not future.done():
2477
- loop = future.get_loop()
2478
- if isinstance(response, Exception):
2479
- loop.call_soon_threadsafe(future.set_exception, response)
2480
- else:
2481
- loop.call_soon_threadsafe(future.set_result, response)
2482
- except Exception:
2483
- # If even Future resolution fails, there is nothing we can do —
2484
- # the event loop may be shut down. Silently swallow to prevent
2485
- # a process crash.
2486
- pass
2532
+ if future is None or future.done():
2533
+ # Already resolved or timed out. Free C memory and exit.
2534
+ if raw_res != ffi.NULL:
2535
+ lib.FreeResponse(raw_res)
2536
+ return
2537
+
2538
+ # Handle NULL result synchronously (no C memory to manage).
2539
+ if raw_res == ffi.NULL:
2540
+ future.get_loop().call_soon_threadsafe(
2541
+ future.set_exception,
2542
+ RuntimeError("Go engine returned NULL")
2543
+ )
2544
+ return
2545
+
2546
+ # Phase 2: Defer unpacking to event loop thread.
2547
+ # ffi.gc binds FreeResponse to the Python GC — the C memory
2548
+ # stays alive until _resolve_async_response drops raw_gc.
2549
+ raw_gc = ffi.gc(raw_res, lib.FreeResponse)
2550
+ gc_bound = True
2551
+ loop = future.get_loop()
2552
+ loop.call_soon_threadsafe(_resolve_async_response, ffi, future, raw_gc)
2553
+
2554
+ except BaseException:
2555
+ # Log swallowed exception for diagnostics before cleaning up.
2556
+ import traceback as _tb
2557
+ print("[tls-client] async callback suppressed exception:", file=sys.stderr)
2558
+ _tb.print_exc(file=sys.stderr)
2559
+ # Absolute last resort: free C memory, then swallow.
2560
+ # If ffi.gc already bound FreeResponse, release the GC binding
2561
+ # via ffi.release() to prevent double-free when raw_gc is
2562
+ # garbage-collected later (call_soon_threadsafe may raise if
2563
+ # the event loop has already been closed).
2564
+ if raw_res != ffi.NULL:
2565
+ try:
2566
+ if gc_bound:
2567
+ ffi.release(raw_gc)
2568
+ lib.FreeResponse(raw_res)
2569
+ except BaseException:
2570
+ pass
2487
2571
 
2488
2572
  return _on_async_response
2489
2573
 
@@ -2601,6 +2685,15 @@ class AsyncSession:
2601
2685
  disable_ipv4: bool = False,
2602
2686
  # 禁用 IPv6 / Disable IPv6
2603
2687
  disable_ipv6: bool = False,
2688
+ # ── TCP/IP Fingerprint ──
2689
+ # IP TTL (Time To Live). Windows=128, Linux/macOS=64. 0=auto from profile
2690
+ tcp_ttl: int = 0,
2691
+ # TCP receive window size. Windows=64240, Linux/macOS=65535. 0=auto
2692
+ tcp_window_size: int = 0,
2693
+ # TCP window scale factor. Windows=8, Linux=7, macOS=6. 0=auto
2694
+ tcp_window_scale: int = 0,
2695
+ # TCP Maximum Segment Size. Standard Ethernet=1460. 0=auto
2696
+ tcp_mss: int = 0,
2604
2697
  # ── Cookie ──
2605
2698
  # 是否允许空 Cookie / Whether to allow empty-value cookies
2606
2699
  allow_empty_cookies: bool = False,
@@ -2646,6 +2739,10 @@ class AsyncSession:
2646
2739
  read_buffer_size=read_buffer_size,
2647
2740
  disable_ipv4=disable_ipv4,
2648
2741
  disable_ipv6=disable_ipv6,
2742
+ tcp_ttl=tcp_ttl,
2743
+ tcp_window_size=tcp_window_size,
2744
+ tcp_window_scale=tcp_window_scale,
2745
+ tcp_mss=tcp_mss,
2649
2746
  allow_empty_cookies=allow_empty_cookies,
2650
2747
  without_cookie_jar=without_cookie_jar,
2651
2748
  catch_panics=catch_panics,
@@ -2829,6 +2926,10 @@ class AsyncSession:
2829
2926
  "disable_http3": _ckb("disable_http3"),
2830
2927
  "disable_ipv4": _ckb("disable_ipv4"),
2831
2928
  "disable_ipv6": _ckb("disable_ipv6"),
2929
+ "tcp_ttl": _ck("tcp_ttl"),
2930
+ "tcp_window_size": _ck("tcp_window_size"),
2931
+ "tcp_window_scale": _ck("tcp_window_scale"),
2932
+ "tcp_mss": _ck("tcp_mss"),
2832
2933
  "follow_redirects": _ckb("follow_redirects"),
2833
2934
  "without_cookie_jar": _ckb("without_cookie_jar"),
2834
2935
  "allow_empty_cookies": _ckb("allow_empty_cookies"),
@@ -2869,7 +2970,7 @@ class AsyncSession:
2869
2970
  go_timeout = float(opts.timeout_seconds) if opts.timeout_seconds > 0 else 30.0
2870
2971
  if opts.timeout_milliseconds > 0:
2871
2972
  go_timeout = float(opts.timeout_milliseconds) / 1000.0
2872
- safe_timeout = max(60.0, min(go_timeout * 2.0 + 10.0, 600.0))
2973
+ safe_timeout = max(60.0, min(go_timeout * 2.0 + 2.0, 600.0))
2873
2974
 
2874
2975
  def _on_zombie_timeout(rid: int) -> None:
2875
2976
  # Safe: by this point the Go goroutine has either completed
@@ -3100,7 +3201,12 @@ class AsyncSession:
3100
3201
  allow_empty_cookies=allow_empty_cookies,
3101
3202
  without_cookie_jar=without_cookie_jar,
3102
3203
  disable_http3=disable_http3, disable_ipv4=disable_ipv4,
3103
- disable_ipv6=disable_ipv6, catch_panics=catch_panics,
3204
+ disable_ipv6=disable_ipv6,
3205
+ tcp_ttl=tcp_ttl,
3206
+ tcp_window_size=tcp_window_size,
3207
+ tcp_window_scale=tcp_window_scale,
3208
+ tcp_mss=tcp_mss,
3209
+ catch_panics=catch_panics,
3104
3210
  with_debug=with_debug,
3105
3211
  **kwargs,
3106
3212
  )
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tls-client-python
3
- Version: 1.15.0.1
3
+ Version: 1.15.0.3
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
@@ -23,11 +22,13 @@ Classifier: Programming Language :: Python :: 3.9
23
22
  Classifier: Programming Language :: Python :: 3.10
24
23
  Classifier: Programming Language :: Python :: 3.11
25
24
  Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Programming Language :: Python :: 3.13
26
+ Classifier: Programming Language :: Python :: 3.14
26
27
  Classifier: Programming Language :: Python :: Implementation :: CPython
27
28
  Classifier: Topic :: Internet :: WWW/HTTP
28
29
  Classifier: Topic :: Security
29
30
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
30
- Requires-Python: <3.13,>=3.6
31
+ Requires-Python: <=3.14,>=3.6
31
32
  Description-Content-Type: text/markdown
32
33
  License-File: LICENSE
33
34
  Requires-Dist: cffi>=1.14.0
@@ -41,8 +42,6 @@ Dynamic: license-file
41
42
 
42
43
  **High-performance Python binding for [bogdanfinn/tls-client](https://github.com/bogdanfinn/tls-client) via CFFI.**
43
44
 
44
- Zero-copy FFI boundary, panic-proof, full TLS fingerprint control — with a familiar `requests`-style API.
45
-
46
45
  ---
47
46
 
48
47
  ## What is TLS Fingerprinting?
@@ -2,16 +2,14 @@ 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
8
- tls_client/bin/tls-client-alpine-amd64.so
9
9
  tls_client/bin/tls-client-darwin-amd64.dylib
10
10
  tls_client/bin/tls-client-darwin-arm64.dylib
11
- tls_client/bin/tls-client-linux-386.so
11
+ tls_client/bin/tls-client-linux-amd64-musl.so
12
12
  tls_client/bin/tls-client-linux-amd64.so
13
- tls_client/bin/tls-client-linux-arm.so
14
- tls_client/bin/tls-client-linux-arm64.so
15
13
  tls_client/bin/tls-client-windows-386.dll
16
14
  tls_client/bin/tls-client-windows-amd64.dll
17
15
  tls_client_python.egg-info/PKG-INFO