tlsmask 1.16.0__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 (50) hide show
  1. tlsmask-1.16.0/.gitignore +10 -0
  2. tlsmask-1.16.0/CHANGELOG.md +5 -0
  3. tlsmask-1.16.0/LICENSE +21 -0
  4. tlsmask-1.16.0/LICENSE-tls-client +27 -0
  5. tlsmask-1.16.0/PKG-INFO +266 -0
  6. tlsmask-1.16.0/README.md +230 -0
  7. tlsmask-1.16.0/docs/guide.md +342 -0
  8. tlsmask-1.16.0/hatch_build.py +50 -0
  9. tlsmask-1.16.0/pyproject.toml +70 -0
  10. tlsmask-1.16.0/scripts/build_wheels.py +60 -0
  11. tlsmask-1.16.0/scripts/bump.py +214 -0
  12. tlsmask-1.16.0/scripts/fetch_binaries.py +84 -0
  13. tlsmask-1.16.0/scripts/render.py +359 -0
  14. tlsmask-1.16.0/scripts/upstream.py +263 -0
  15. tlsmask-1.16.0/tests/conftest.py +17 -0
  16. tlsmask-1.16.0/tests/contract/types-1.16.0.json +146 -0
  17. tlsmask-1.16.0/tests/fake_library.py +79 -0
  18. tlsmask-1.16.0/tests/live/test_fingerprints.py +74 -0
  19. tlsmask-1.16.0/tests/real/conftest.py +29 -0
  20. tlsmask-1.16.0/tests/real/server.py +68 -0
  21. tlsmask-1.16.0/tests/real/test_real_library.py +148 -0
  22. tlsmask-1.16.0/tests/test_asyncio.py +78 -0
  23. tlsmask-1.16.0/tests/test_build.py +91 -0
  24. tlsmask-1.16.0/tests/test_bump.py +204 -0
  25. tlsmask-1.16.0/tests/test_cli.py +28 -0
  26. tlsmask-1.16.0/tests/test_contract.py +142 -0
  27. tlsmask-1.16.0/tests/test_cookies.py +114 -0
  28. tlsmask-1.16.0/tests/test_fetch.py +37 -0
  29. tlsmask-1.16.0/tests/test_library.py +139 -0
  30. tlsmask-1.16.0/tests/test_payload.py +241 -0
  31. tlsmask-1.16.0/tests/test_pins.py +45 -0
  32. tlsmask-1.16.0/tests/test_render.py +127 -0
  33. tlsmask-1.16.0/tests/test_response.py +98 -0
  34. tlsmask-1.16.0/tests/test_sessions.py +576 -0
  35. tlsmask-1.16.0/tests/test_structures.py +30 -0
  36. tlsmask-1.16.0/tests/test_upstream.py +138 -0
  37. tlsmask-1.16.0/tlsmask/__init__.py +38 -0
  38. tlsmask-1.16.0/tlsmask/__main__.py +31 -0
  39. tlsmask-1.16.0/tlsmask/_library.py +212 -0
  40. tlsmask-1.16.0/tlsmask/_payload.py +352 -0
  41. tlsmask-1.16.0/tlsmask/_pins.py +135 -0
  42. tlsmask-1.16.0/tlsmask/_version.py +4 -0
  43. tlsmask-1.16.0/tlsmask/asyncio.py +103 -0
  44. tlsmask-1.16.0/tlsmask/cookies.py +231 -0
  45. tlsmask-1.16.0/tlsmask/exceptions.py +21 -0
  46. tlsmask-1.16.0/tlsmask/profiles.py +97 -0
  47. tlsmask-1.16.0/tlsmask/py.typed +0 -0
  48. tlsmask-1.16.0/tlsmask/response.py +118 -0
  49. tlsmask-1.16.0/tlsmask/sessions.py +446 -0
  50. tlsmask-1.16.0/tlsmask/structures.py +48 -0
@@ -0,0 +1,10 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ build/
5
+ dist/
6
+ *.egg-info/
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+ # bogdanfinn's library: fetched and hash-checked by scripts/fetch_binaries.py, shipped only inside wheels
10
+ tlsmask/bin/
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 1.16.0 - 2026-09-26
4
+
5
+ First release. Bundles bogdanfinn/tls-client [v1.16.0](https://github.com/bogdanfinn/tls-client/releases/tag/v1.16.0) with the `tls-client` package's API. It fixes that package's bugs, listed in the README under "Coming from tls-client".
tlsmask-1.16.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ubaidullah71
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -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,266 @@
1
+ Metadata-Version: 2.5
2
+ Name: tlsmask
3
+ Version: 1.16.0
4
+ Summary: A drop-in, always-current Python wrapper for bogdanfinn's tls-client: look like a real browser at the TLS and HTTP/2 layer.
5
+ Project-URL: Homepage, https://github.com/Ubaidullah71/tlsmask
6
+ Project-URL: Source, https://github.com/Ubaidullah71/tlsmask
7
+ Project-URL: Issues, https://github.com/Ubaidullah71/tlsmask/issues
8
+ Project-URL: Changelog, https://github.com/Ubaidullah71/tlsmask/blob/main/CHANGELOG.md
9
+ Author: Ubaidullah71
10
+ License-Expression: MIT AND BSD-4-Clause
11
+ License-File: LICENSE
12
+ License-File: LICENSE-tls-client
13
+ Keywords: browser,fingerprint,http2,impersonate,ja3,ja4,scraping,tls,tls-client
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Operating System :: Microsoft :: Windows
18
+ Classifier: Operating System :: POSIX :: Linux
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3 :: Only
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: Topic :: Internet :: WWW/HTTP
28
+ Classifier: Typing :: Typed
29
+ Requires-Python: >=3.9
30
+ Provides-Extra: dev
31
+ Requires-Dist: hatchling>=1.27; extra == 'dev'
32
+ Requires-Dist: pytest>=8; extra == 'dev'
33
+ Requires-Dist: ruff==0.16.9; extra == 'dev'
34
+ Requires-Dist: twine>=6.1; extra == 'dev'
35
+ Description-Content-Type: text/markdown
36
+
37
+ <div align="center">
38
+
39
+ # tlsmask
40
+
41
+ **Python HTTP requests with a real browser's TLS and HTTP/2 fingerprint.**
42
+
43
+ <a href="https://pypi.org/project/tlsmask/"><img src="https://img.shields.io/pypi/v/tlsmask?color=0a7cff" alt="PyPI"></a>
44
+ <a href="https://pypi.org/project/tlsmask/"><img src="https://img.shields.io/pypi/pyversions/tlsmask" alt="Python"></a>
45
+ <a href="https://pypistats.org/packages/tlsmask"><img src="https://img.shields.io/pypi/dm/tlsmask" alt="Downloads"></a>
46
+ <a href="https://github.com/Ubaidullah71/tlsmask/actions/workflows/ci.yml"><img src="https://github.com/Ubaidullah71/tlsmask/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
47
+ <a href="https://github.com/Ubaidullah71/tlsmask/blob/main/LICENSE"><img src="https://img.shields.io/pypi/l/tlsmask" alt="License"></a>
48
+ <!-- badge:start --><a href="https://github.com/bogdanfinn/tls-client/releases/tag/v1.16.0"><img src="https://img.shields.io/badge/bundles_tls--client-v1.16.0-0a7cff" alt="bundles tls-client v1.16.0"></a><!-- badge:end -->
49
+
50
+ </div>
51
+
52
+ tlsmask makes HTTP requests from Python that look like they come from Chrome, Firefox or Safari. Not just the headers: the TLS handshake and the HTTP/2 settings match the browser too. It runs [bogdanfinn's tls-client](https://github.com/bogdanfinn/tls-client), a Go library, and ships its latest official build inside the package.
53
+
54
+ It is also a drop-in replacement for the [`tls-client`](https://pypi.org/project/tls-client/) package, which hasn't had a release since February 2024.
55
+
56
+ ```python
57
+ import tlsmask
58
+
59
+ with tlsmask.Session("chrome_150") as session:
60
+ r = session.get("https://tls.peet.ws/api/all")
61
+ print(r.status_code, r.protocol) # 200 HTTP/2.0
62
+ print(r.json()["tls"]["ja4"]) # Chrome's fingerprint, not Python's
63
+ ```
64
+
65
+ ## Why
66
+
67
+ Every HTTPS connection starts with a TLS "ClientHello": a list of the ciphers, extensions and curves the client supports, in a particular order. Each browser sends its own recognisable version (often summarised as a JA3 or JA4 fingerprint), and so does Python. A server can tell them apart before it reads a single header, which is why `requests` with a Chrome User-Agent still doesn't look like Chrome.
68
+
69
+ bogdanfinn's tls-client reproduces real browsers' handshakes and HTTP/2 behaviour. The `tls-client` package made it usable from Python, but it stopped at version 1.0.1. It still bundles tls-client v1.7.2, so its newest browser is Chrome 120, and a number of its bugs were never fixed.
70
+
71
+ tlsmask carries on from there: the current library, the same API, those bugs fixed, and a weekly check for new tls-client releases.
72
+
73
+ ## tlsmask compared with tls-client
74
+ <!-- stats:start -->
75
+ | | `tls-client` (the old wrapper) | **tlsmask** |
76
+ |---|:---:|:---:|
77
+ | bogdanfinn/tls-client inside | v1.7.2 | **v1.16.0** |
78
+ | Browser & app profiles | 51 | **83** |
79
+ | Newest Chrome | 120 | **152** |
80
+ | Newest Firefox | 120 | **148** |
81
+ | Newest iOS Safari | 16.0 | **26.0** |
82
+ | Brave | none | **146** |
83
+ | Last updated | Feb 2024 | **Sep 2026** |
84
+ | Native library checked against a pinned SHA-256 | no | **yes, at build and at load** |
85
+ | Keeps itself current | no | **yes, a weekly bot** |
86
+ <!-- stats:end -->
87
+
88
+ ## Installation
89
+
90
+ ```bash
91
+ pip install tlsmask
92
+ ```
93
+
94
+ Prebuilt wheels are available for:
95
+
96
+ - Windows, 64-bit and 32-bit
97
+ - macOS 13 or newer, Apple Silicon and Intel
98
+ - Linux x86-64, ARM64 and ARMv7 (glibc 2.17 or newer)
99
+
100
+ Each wheel already contains the tls-client library for its platform, so nothing is downloaded when your code runs. tlsmask needs Python 3.9 or newer and has no other dependencies.
101
+
102
+ ## Usage
103
+
104
+ ```python
105
+ import tlsmask
106
+
107
+ session = tlsmask.Session("chrome_150")
108
+ session.headers.update(
109
+ {
110
+ "User-Agent": (
111
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
112
+ "(KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36"
113
+ ),
114
+ "Accept-Language": "en-US,en;q=0.9",
115
+ }
116
+ )
117
+
118
+ r = session.get("https://example.com", params={"q": "tls"})
119
+ print(r.status_code, r.headers["content-type"])
120
+
121
+ r = session.post("https://httpbin.org/post", json={"hello": "world"})
122
+ print(r.json())
123
+
124
+ session.close()
125
+ ```
126
+
127
+ With asyncio:
128
+
129
+ ```python
130
+ import asyncio
131
+
132
+ import tlsmask
133
+
134
+
135
+ async def main():
136
+ async with tlsmask.AsyncSession("firefox_148") as session:
137
+ pages = await asyncio.gather(
138
+ *(session.get(f"https://example.com/?page={i}") for i in range(10))
139
+ )
140
+ print([page.status_code for page in pages])
141
+
142
+
143
+ asyncio.run(main())
144
+ ```
145
+
146
+ The **[guide](https://github.com/Ubaidullah71/tlsmask/blob/main/docs/guide.md)** covers the rest: header order, cookies, proxies, redirects, timeouts, errors, threads, custom TLS fingerprints and how to check your install.
147
+
148
+ ## Switching from tls-client
149
+
150
+ ```diff
151
+ - import tls_client
152
+ + import tlsmask as tls_client
153
+ ```
154
+
155
+ For most code that's the only change. The constructor arguments, the request methods, `response.json()` and the `session.cookies` helpers work the same way. A few things behave differently on purpose, mostly because the old behaviour was a bug:
156
+
157
+ | | `tls-client` | tlsmask |
158
+ |---|---|---|
159
+ | Unknown `client_identifier` (including typos like `chrome112`) | silently sends a different browser | raises `ValueError` and suggests the closest names |
160
+ | A panic inside the Go library | kills the whole Python process | raises `TLSClientException` (`catch_panics` is on by default) |
161
+ | `proxies={"https": ...}` | ignored, so the request goes out **without** the proxy | used |
162
+ | `post(json=...)` | adds `Content-Type` to every later request | adds it to that request only |
163
+ | Binary responses (images, PDFs) | corrupted | returned byte for byte |
164
+ | Header order | tls-client's own order | the order you wrote them in (or `header_order=`) |
165
+ | `cert_compression_algo` | silently ignored by current tls-client | translated to the new setting |
166
+ | `params` on a URL that already has `?` | `url?a=1?b=2` | `url?a=1&b=2` |
167
+ | Deleting a cookie | still sent, because a second copy lives inside Go | gone from the next request |
168
+ | Different `timeout_seconds` or `insecure_skip_verify` per request | ignored after the first request | honoured every time |
169
+ | Default profile | `chrome_120` | tls-client's current default (`tlsmask.DEFAULT_PROFILE`) |
170
+ | `get(url, cookies={...})` | also stored those cookies in `session.cookies` | sends them with that request only, and only to that site, even across redirects |
171
+ | A proxy written as `host:port` | failed | treated as `http://host:port`, like `requests` |
172
+ | `Authorization` on a redirect | kept whenever the host name matches | kept only on the same origin, or on an upgrade from http to https |
173
+ | `client_identifier=None` | built a client from whatever was set, failing later if something was missing | checks up front that `ja3_string` and the settings its extensions need are there, and raises `ValueError` naming what's missing; ALPN defaults to what browsers send |
174
+ | `additional_decode=` | decoded one extra encoding | not needed any more (tls-client decodes everything); it warns and is ignored |
175
+
176
+ The old misspelled `TLSClientExeption` still works. If your code imports `tls_client.settings.ClientIdentifiers`, use `tlsmask.ClientIdentifiers` instead. `response.headers` is case-insensitive now, so use `dict(response.headers)` where you need a plain dict (for `json.dumps`, say).
177
+
178
+ ## Choosing a profile
179
+
180
+ For most uses, pick a current browser, such as the default (`tlsmask.DEFAULT_PROFILE`), `firefox_148` or `safari_ios_26_0`. Send a User-Agent that matches the profile, because a Firefox User-Agent over a Chrome handshake stands out on its own. The `_PSK` variants resume TLS sessions the way a returning visitor's browser does.
181
+
182
+ `tlsmask.PROFILES` holds every name, and editors autocomplete them through the `tlsmask.ClientIdentifier` type.
183
+ <!-- profiles:start -->
184
+ <details>
185
+ <summary><b>All 83 profiles in tls-client v1.16.0</b></summary>
186
+
187
+ | Family | Profiles |
188
+ |---|---|
189
+ | Chrome | `chrome_103` `chrome_104` `chrome_105` `chrome_106` `chrome_107` `chrome_108` `chrome_109` `chrome_110` `chrome_111` `chrome_112` `chrome_116_PSK` `chrome_116_PSK_PQ` `chrome_117` `chrome_120` `chrome_124` `chrome_130_PSK` `chrome_131` `chrome_131_PSK` `chrome_133` `chrome_133_PSK` `chrome_144` `chrome_144_PSK` `chrome_146` `chrome_146_PSK` `chrome_150` `chrome_150_PSK` `chrome_152` `chrome_152_PSK` |
190
+ | Firefox | `firefox_102` `firefox_104` `firefox_105` `firefox_106` `firefox_108` `firefox_110` `firefox_117` `firefox_120` `firefox_123` `firefox_132` `firefox_133` `firefox_135` `firefox_146_PSK` `firefox_147` `firefox_147_PSK` `firefox_148` |
191
+ | Safari (iOS & iPadOS) | `safari_ios_15_5` `safari_ios_15_6` `safari_ios_16_0` `safari_ios_17_0` `safari_ios_18_0` `safari_ios_18_5` `safari_ios_26_0` `safari_ipad_15_6` |
192
+ | Safari (macOS) | `safari_15_6_1` `safari_16_0` |
193
+ | Opera | `opera_89` `opera_90` `opera_91` |
194
+ | Brave | `brave_146` `brave_146_PSK` |
195
+ | Mobile apps & others | `cloudscraper` `confirmed_android` `confirmed_ios` `mesh_android` `mesh_android_1` `mesh_android_2` `mesh_ios` `mesh_ios_1` `mesh_ios_2` `mms_ios` `mms_ios_1` `mms_ios_2` `mms_ios_3` `nike_android_mobile` `nike_ios_mobile` `okhttp4_android_7` `okhttp4_android_8` `okhttp4_android_9` `okhttp4_android_10` `okhttp4_android_11` `okhttp4_android_12` `okhttp4_android_13` `zalando_android_mobile` `zalando_ios_mobile` |
196
+
197
+ </details>
198
+ <!-- profiles:end -->
199
+
200
+ ## Where the library comes from
201
+
202
+ The native part of tlsmask is bogdanfinn's own release file, byte for byte. It isn't rebuilt or modified.
203
+
204
+ 1. When a wheel is built, the file is downloaded from [tls-client's GitHub releases](https://github.com/bogdanfinn/tls-client/releases). The build refuses it unless its SHA-256 matches both the hash pinned in [`tlsmask/_pins.py`](https://github.com/Ubaidullah71/tlsmask/blob/main/tlsmask/_pins.py) and the digest GitHub publishes for the release.
205
+ 2. The first time your program makes a request, tlsmask hashes the file again and won't load it if it doesn't match.
206
+ 3. Releases are published to PyPI from GitHub Actions with trusted publishing and signed attestations, and every GitHub release includes a `SHA256SUMS` file.
207
+
208
+ To check your own installation:
209
+
210
+ ```console
211
+ $ python -m tlsmask
212
+ tlsmask 1.16.0
213
+ tls-client 1.16.0 (github.com/bogdanfinn/tls-client)
214
+ platform win32/AMD64 (64-bit Python) -> windows-amd64
215
+ library OK: ...\tlsmask\bin\tls-client-windows-64-1.16.0.dll (sha256 53dca636..., as pinned)
216
+ ```
217
+
218
+ ## Staying up to date
219
+
220
+ Every Monday a scheduled job looks for a new tls-client release. When there is one, it downloads and verifies every file, reads the new list of profiles, compares the library's API with the previous version, and runs the full test suite on Windows, macOS and Linux, on both Intel and ARM machines.
221
+
222
+ If nothing important changed and the release is at least a week old, a new tlsmask version is published automatically. Anything unusual, like a removed profile or a changed API, waits for a person to look at it first.
223
+
224
+ ## FAQ
225
+
226
+ **Is this an official bogdanfinn project?**
227
+ No. tlsmask is an independent project and isn't affiliated with or endorsed by Bogdan Finn. It bundles his library unmodified. Please report tlsmask problems [here](https://github.com/Ubaidullah71/tlsmask/issues) rather than to him.
228
+
229
+ **Does it work on Alpine Linux?**
230
+ Not at the moment. tls-client's Alpine (musl) build can't be loaded into Python, so there is no Alpine wheel. In Docker, use a glibc-based image such as `python:3.12-slim` instead.
231
+
232
+ **My platform has no wheel.**
233
+ Get a build of tls-client for it (from its releases, or build it yourself) and point tlsmask at the file with the `TLSMASK_LIBRARY_PATH` environment variable. On such a platform `pip install tlsmask` installs from the source distribution, which has no library of its own.
234
+
235
+ **Does it work with multiprocessing?**
236
+ Yes. The library is only loaded when the first request is made, so child processes are fine as long as the parent hadn't made a request before it forked. If in doubt, use the `spawn` start method (the default on Windows and macOS).
237
+
238
+ **Why aren't redirects followed by default?**
239
+ `tls-client` didn't follow them by default, so existing code keeps working. Pass `allow_redirects=True`.
240
+
241
+ **What is it for?**
242
+ Making requests that look like a real browser: testing your own site's bot protection, research, or talking to APIs that turn away non-browser clients. Please respect the terms of the sites you use it with.
243
+
244
+ ## Contributing
245
+
246
+ Bug reports and pull requests are welcome. To set up a development copy:
247
+
248
+ ```bash
249
+ git clone https://github.com/Ubaidullah71/tlsmask && cd tlsmask
250
+ python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
251
+ pip install -e ".[dev]"
252
+ python scripts/fetch_binaries.py # downloads and verifies this machine's library into tlsmask/bin/
253
+ pytest # unit tests, plus tests against the real library and a local server
254
+ pytest -m live # fingerprint checks against a public echo service
255
+ ```
256
+
257
+ `tlsmask/_pins.py`, `tlsmask/profiles.py`, `tlsmask/_version.py` and the tables in this README are generated by `scripts/render.py`, so please don't edit them by hand.
258
+
259
+ ## Credits
260
+
261
+ - [bogdanfinn/tls-client](https://github.com/bogdanfinn/tls-client) does the real work. *This product includes software developed by Bogdan Finn*, distributed under the BSD 4-Clause license (see [LICENSE-tls-client](https://github.com/Ubaidullah71/tlsmask/blob/main/LICENSE-tls-client)).
262
+ - [FlorianREGAZ/Python-Tls-Client](https://github.com/FlorianREGAZ/Python-Tls-Client) designed the Python API that tlsmask keeps compatible.
263
+
264
+ ## License
265
+
266
+ tlsmask's own code is under the [MIT license](https://github.com/Ubaidullah71/tlsmask/blob/main/LICENSE). The bundled tls-client library is under the BSD 4-Clause license ([LICENSE-tls-client](https://github.com/Ubaidullah71/tlsmask/blob/main/LICENSE-tls-client)).
@@ -0,0 +1,230 @@
1
+ <div align="center">
2
+
3
+ # tlsmask
4
+
5
+ **Python HTTP requests with a real browser's TLS and HTTP/2 fingerprint.**
6
+
7
+ <a href="https://pypi.org/project/tlsmask/"><img src="https://img.shields.io/pypi/v/tlsmask?color=0a7cff" alt="PyPI"></a>
8
+ <a href="https://pypi.org/project/tlsmask/"><img src="https://img.shields.io/pypi/pyversions/tlsmask" alt="Python"></a>
9
+ <a href="https://pypistats.org/packages/tlsmask"><img src="https://img.shields.io/pypi/dm/tlsmask" alt="Downloads"></a>
10
+ <a href="https://github.com/Ubaidullah71/tlsmask/actions/workflows/ci.yml"><img src="https://github.com/Ubaidullah71/tlsmask/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
11
+ <a href="https://github.com/Ubaidullah71/tlsmask/blob/main/LICENSE"><img src="https://img.shields.io/pypi/l/tlsmask" alt="License"></a>
12
+ <!-- badge:start --><a href="https://github.com/bogdanfinn/tls-client/releases/tag/v1.16.0"><img src="https://img.shields.io/badge/bundles_tls--client-v1.16.0-0a7cff" alt="bundles tls-client v1.16.0"></a><!-- badge:end -->
13
+
14
+ </div>
15
+
16
+ tlsmask makes HTTP requests from Python that look like they come from Chrome, Firefox or Safari. Not just the headers: the TLS handshake and the HTTP/2 settings match the browser too. It runs [bogdanfinn's tls-client](https://github.com/bogdanfinn/tls-client), a Go library, and ships its latest official build inside the package.
17
+
18
+ It is also a drop-in replacement for the [`tls-client`](https://pypi.org/project/tls-client/) package, which hasn't had a release since February 2024.
19
+
20
+ ```python
21
+ import tlsmask
22
+
23
+ with tlsmask.Session("chrome_150") as session:
24
+ r = session.get("https://tls.peet.ws/api/all")
25
+ print(r.status_code, r.protocol) # 200 HTTP/2.0
26
+ print(r.json()["tls"]["ja4"]) # Chrome's fingerprint, not Python's
27
+ ```
28
+
29
+ ## Why
30
+
31
+ Every HTTPS connection starts with a TLS "ClientHello": a list of the ciphers, extensions and curves the client supports, in a particular order. Each browser sends its own recognisable version (often summarised as a JA3 or JA4 fingerprint), and so does Python. A server can tell them apart before it reads a single header, which is why `requests` with a Chrome User-Agent still doesn't look like Chrome.
32
+
33
+ bogdanfinn's tls-client reproduces real browsers' handshakes and HTTP/2 behaviour. The `tls-client` package made it usable from Python, but it stopped at version 1.0.1. It still bundles tls-client v1.7.2, so its newest browser is Chrome 120, and a number of its bugs were never fixed.
34
+
35
+ tlsmask carries on from there: the current library, the same API, those bugs fixed, and a weekly check for new tls-client releases.
36
+
37
+ ## tlsmask compared with tls-client
38
+ <!-- stats:start -->
39
+ | | `tls-client` (the old wrapper) | **tlsmask** |
40
+ |---|:---:|:---:|
41
+ | bogdanfinn/tls-client inside | v1.7.2 | **v1.16.0** |
42
+ | Browser & app profiles | 51 | **83** |
43
+ | Newest Chrome | 120 | **152** |
44
+ | Newest Firefox | 120 | **148** |
45
+ | Newest iOS Safari | 16.0 | **26.0** |
46
+ | Brave | none | **146** |
47
+ | Last updated | Feb 2024 | **Sep 2026** |
48
+ | Native library checked against a pinned SHA-256 | no | **yes, at build and at load** |
49
+ | Keeps itself current | no | **yes, a weekly bot** |
50
+ <!-- stats:end -->
51
+
52
+ ## Installation
53
+
54
+ ```bash
55
+ pip install tlsmask
56
+ ```
57
+
58
+ Prebuilt wheels are available for:
59
+
60
+ - Windows, 64-bit and 32-bit
61
+ - macOS 13 or newer, Apple Silicon and Intel
62
+ - Linux x86-64, ARM64 and ARMv7 (glibc 2.17 or newer)
63
+
64
+ Each wheel already contains the tls-client library for its platform, so nothing is downloaded when your code runs. tlsmask needs Python 3.9 or newer and has no other dependencies.
65
+
66
+ ## Usage
67
+
68
+ ```python
69
+ import tlsmask
70
+
71
+ session = tlsmask.Session("chrome_150")
72
+ session.headers.update(
73
+ {
74
+ "User-Agent": (
75
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
76
+ "(KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36"
77
+ ),
78
+ "Accept-Language": "en-US,en;q=0.9",
79
+ }
80
+ )
81
+
82
+ r = session.get("https://example.com", params={"q": "tls"})
83
+ print(r.status_code, r.headers["content-type"])
84
+
85
+ r = session.post("https://httpbin.org/post", json={"hello": "world"})
86
+ print(r.json())
87
+
88
+ session.close()
89
+ ```
90
+
91
+ With asyncio:
92
+
93
+ ```python
94
+ import asyncio
95
+
96
+ import tlsmask
97
+
98
+
99
+ async def main():
100
+ async with tlsmask.AsyncSession("firefox_148") as session:
101
+ pages = await asyncio.gather(
102
+ *(session.get(f"https://example.com/?page={i}") for i in range(10))
103
+ )
104
+ print([page.status_code for page in pages])
105
+
106
+
107
+ asyncio.run(main())
108
+ ```
109
+
110
+ The **[guide](https://github.com/Ubaidullah71/tlsmask/blob/main/docs/guide.md)** covers the rest: header order, cookies, proxies, redirects, timeouts, errors, threads, custom TLS fingerprints and how to check your install.
111
+
112
+ ## Switching from tls-client
113
+
114
+ ```diff
115
+ - import tls_client
116
+ + import tlsmask as tls_client
117
+ ```
118
+
119
+ For most code that's the only change. The constructor arguments, the request methods, `response.json()` and the `session.cookies` helpers work the same way. A few things behave differently on purpose, mostly because the old behaviour was a bug:
120
+
121
+ | | `tls-client` | tlsmask |
122
+ |---|---|---|
123
+ | Unknown `client_identifier` (including typos like `chrome112`) | silently sends a different browser | raises `ValueError` and suggests the closest names |
124
+ | A panic inside the Go library | kills the whole Python process | raises `TLSClientException` (`catch_panics` is on by default) |
125
+ | `proxies={"https": ...}` | ignored, so the request goes out **without** the proxy | used |
126
+ | `post(json=...)` | adds `Content-Type` to every later request | adds it to that request only |
127
+ | Binary responses (images, PDFs) | corrupted | returned byte for byte |
128
+ | Header order | tls-client's own order | the order you wrote them in (or `header_order=`) |
129
+ | `cert_compression_algo` | silently ignored by current tls-client | translated to the new setting |
130
+ | `params` on a URL that already has `?` | `url?a=1?b=2` | `url?a=1&b=2` |
131
+ | Deleting a cookie | still sent, because a second copy lives inside Go | gone from the next request |
132
+ | Different `timeout_seconds` or `insecure_skip_verify` per request | ignored after the first request | honoured every time |
133
+ | Default profile | `chrome_120` | tls-client's current default (`tlsmask.DEFAULT_PROFILE`) |
134
+ | `get(url, cookies={...})` | also stored those cookies in `session.cookies` | sends them with that request only, and only to that site, even across redirects |
135
+ | A proxy written as `host:port` | failed | treated as `http://host:port`, like `requests` |
136
+ | `Authorization` on a redirect | kept whenever the host name matches | kept only on the same origin, or on an upgrade from http to https |
137
+ | `client_identifier=None` | built a client from whatever was set, failing later if something was missing | checks up front that `ja3_string` and the settings its extensions need are there, and raises `ValueError` naming what's missing; ALPN defaults to what browsers send |
138
+ | `additional_decode=` | decoded one extra encoding | not needed any more (tls-client decodes everything); it warns and is ignored |
139
+
140
+ The old misspelled `TLSClientExeption` still works. If your code imports `tls_client.settings.ClientIdentifiers`, use `tlsmask.ClientIdentifiers` instead. `response.headers` is case-insensitive now, so use `dict(response.headers)` where you need a plain dict (for `json.dumps`, say).
141
+
142
+ ## Choosing a profile
143
+
144
+ For most uses, pick a current browser, such as the default (`tlsmask.DEFAULT_PROFILE`), `firefox_148` or `safari_ios_26_0`. Send a User-Agent that matches the profile, because a Firefox User-Agent over a Chrome handshake stands out on its own. The `_PSK` variants resume TLS sessions the way a returning visitor's browser does.
145
+
146
+ `tlsmask.PROFILES` holds every name, and editors autocomplete them through the `tlsmask.ClientIdentifier` type.
147
+ <!-- profiles:start -->
148
+ <details>
149
+ <summary><b>All 83 profiles in tls-client v1.16.0</b></summary>
150
+
151
+ | Family | Profiles |
152
+ |---|---|
153
+ | Chrome | `chrome_103` `chrome_104` `chrome_105` `chrome_106` `chrome_107` `chrome_108` `chrome_109` `chrome_110` `chrome_111` `chrome_112` `chrome_116_PSK` `chrome_116_PSK_PQ` `chrome_117` `chrome_120` `chrome_124` `chrome_130_PSK` `chrome_131` `chrome_131_PSK` `chrome_133` `chrome_133_PSK` `chrome_144` `chrome_144_PSK` `chrome_146` `chrome_146_PSK` `chrome_150` `chrome_150_PSK` `chrome_152` `chrome_152_PSK` |
154
+ | Firefox | `firefox_102` `firefox_104` `firefox_105` `firefox_106` `firefox_108` `firefox_110` `firefox_117` `firefox_120` `firefox_123` `firefox_132` `firefox_133` `firefox_135` `firefox_146_PSK` `firefox_147` `firefox_147_PSK` `firefox_148` |
155
+ | Safari (iOS & iPadOS) | `safari_ios_15_5` `safari_ios_15_6` `safari_ios_16_0` `safari_ios_17_0` `safari_ios_18_0` `safari_ios_18_5` `safari_ios_26_0` `safari_ipad_15_6` |
156
+ | Safari (macOS) | `safari_15_6_1` `safari_16_0` |
157
+ | Opera | `opera_89` `opera_90` `opera_91` |
158
+ | Brave | `brave_146` `brave_146_PSK` |
159
+ | Mobile apps & others | `cloudscraper` `confirmed_android` `confirmed_ios` `mesh_android` `mesh_android_1` `mesh_android_2` `mesh_ios` `mesh_ios_1` `mesh_ios_2` `mms_ios` `mms_ios_1` `mms_ios_2` `mms_ios_3` `nike_android_mobile` `nike_ios_mobile` `okhttp4_android_7` `okhttp4_android_8` `okhttp4_android_9` `okhttp4_android_10` `okhttp4_android_11` `okhttp4_android_12` `okhttp4_android_13` `zalando_android_mobile` `zalando_ios_mobile` |
160
+
161
+ </details>
162
+ <!-- profiles:end -->
163
+
164
+ ## Where the library comes from
165
+
166
+ The native part of tlsmask is bogdanfinn's own release file, byte for byte. It isn't rebuilt or modified.
167
+
168
+ 1. When a wheel is built, the file is downloaded from [tls-client's GitHub releases](https://github.com/bogdanfinn/tls-client/releases). The build refuses it unless its SHA-256 matches both the hash pinned in [`tlsmask/_pins.py`](https://github.com/Ubaidullah71/tlsmask/blob/main/tlsmask/_pins.py) and the digest GitHub publishes for the release.
169
+ 2. The first time your program makes a request, tlsmask hashes the file again and won't load it if it doesn't match.
170
+ 3. Releases are published to PyPI from GitHub Actions with trusted publishing and signed attestations, and every GitHub release includes a `SHA256SUMS` file.
171
+
172
+ To check your own installation:
173
+
174
+ ```console
175
+ $ python -m tlsmask
176
+ tlsmask 1.16.0
177
+ tls-client 1.16.0 (github.com/bogdanfinn/tls-client)
178
+ platform win32/AMD64 (64-bit Python) -> windows-amd64
179
+ library OK: ...\tlsmask\bin\tls-client-windows-64-1.16.0.dll (sha256 53dca636..., as pinned)
180
+ ```
181
+
182
+ ## Staying up to date
183
+
184
+ Every Monday a scheduled job looks for a new tls-client release. When there is one, it downloads and verifies every file, reads the new list of profiles, compares the library's API with the previous version, and runs the full test suite on Windows, macOS and Linux, on both Intel and ARM machines.
185
+
186
+ If nothing important changed and the release is at least a week old, a new tlsmask version is published automatically. Anything unusual, like a removed profile or a changed API, waits for a person to look at it first.
187
+
188
+ ## FAQ
189
+
190
+ **Is this an official bogdanfinn project?**
191
+ No. tlsmask is an independent project and isn't affiliated with or endorsed by Bogdan Finn. It bundles his library unmodified. Please report tlsmask problems [here](https://github.com/Ubaidullah71/tlsmask/issues) rather than to him.
192
+
193
+ **Does it work on Alpine Linux?**
194
+ Not at the moment. tls-client's Alpine (musl) build can't be loaded into Python, so there is no Alpine wheel. In Docker, use a glibc-based image such as `python:3.12-slim` instead.
195
+
196
+ **My platform has no wheel.**
197
+ Get a build of tls-client for it (from its releases, or build it yourself) and point tlsmask at the file with the `TLSMASK_LIBRARY_PATH` environment variable. On such a platform `pip install tlsmask` installs from the source distribution, which has no library of its own.
198
+
199
+ **Does it work with multiprocessing?**
200
+ Yes. The library is only loaded when the first request is made, so child processes are fine as long as the parent hadn't made a request before it forked. If in doubt, use the `spawn` start method (the default on Windows and macOS).
201
+
202
+ **Why aren't redirects followed by default?**
203
+ `tls-client` didn't follow them by default, so existing code keeps working. Pass `allow_redirects=True`.
204
+
205
+ **What is it for?**
206
+ Making requests that look like a real browser: testing your own site's bot protection, research, or talking to APIs that turn away non-browser clients. Please respect the terms of the sites you use it with.
207
+
208
+ ## Contributing
209
+
210
+ Bug reports and pull requests are welcome. To set up a development copy:
211
+
212
+ ```bash
213
+ git clone https://github.com/Ubaidullah71/tlsmask && cd tlsmask
214
+ python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
215
+ pip install -e ".[dev]"
216
+ python scripts/fetch_binaries.py # downloads and verifies this machine's library into tlsmask/bin/
217
+ pytest # unit tests, plus tests against the real library and a local server
218
+ pytest -m live # fingerprint checks against a public echo service
219
+ ```
220
+
221
+ `tlsmask/_pins.py`, `tlsmask/profiles.py`, `tlsmask/_version.py` and the tables in this README are generated by `scripts/render.py`, so please don't edit them by hand.
222
+
223
+ ## Credits
224
+
225
+ - [bogdanfinn/tls-client](https://github.com/bogdanfinn/tls-client) does the real work. *This product includes software developed by Bogdan Finn*, distributed under the BSD 4-Clause license (see [LICENSE-tls-client](https://github.com/Ubaidullah71/tlsmask/blob/main/LICENSE-tls-client)).
226
+ - [FlorianREGAZ/Python-Tls-Client](https://github.com/FlorianREGAZ/Python-Tls-Client) designed the Python API that tlsmask keeps compatible.
227
+
228
+ ## License
229
+
230
+ tlsmask's own code is under the [MIT license](https://github.com/Ubaidullah71/tlsmask/blob/main/LICENSE). The bundled tls-client library is under the BSD 4-Clause license ([LICENSE-tls-client](https://github.com/Ubaidullah71/tlsmask/blob/main/LICENSE-tls-client)).