googletrans-curl 4.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.
@@ -0,0 +1,66 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+
5
+ # C extensions
6
+ *.so
7
+
8
+ # Distribution / packaging
9
+ .Python
10
+ env/
11
+ .venv/
12
+ build/
13
+ develop-eggs/
14
+ dist/
15
+ downloads/
16
+ eggs/
17
+ .eggs/
18
+ lib/
19
+ lib64/
20
+ parts/
21
+ sdist/
22
+ var/
23
+ *.egg-info/
24
+ .installed.cfg
25
+ *.egg
26
+
27
+ # PyInstaller
28
+ # Usually these files are written by a python script from a template
29
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
30
+ *.manifest
31
+ *.spec
32
+
33
+ # Installer logs
34
+ pip-log.txt
35
+ pip-delete-this-directory.txt
36
+
37
+ # Unit test / coverage reports
38
+ htmlcov/
39
+ .tox/
40
+ .coverage
41
+ .coverage.*
42
+ .cache
43
+ nosetests.xml
44
+ coverage.xml
45
+ *,cover
46
+ .testmondata
47
+
48
+ # Translations
49
+ *.mo
50
+ *.pot
51
+
52
+ # Django stuff:
53
+ *.log
54
+
55
+ # Sphinx documentation
56
+ docs/_build/
57
+
58
+ # PyBuilder
59
+ target/
60
+
61
+ .DS_Store
62
+ .python-version
63
+
64
+ # IDE
65
+ .idea
66
+ .vscode
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 SuHun Han
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.
22
+
@@ -0,0 +1,265 @@
1
+ Metadata-Version: 2.5
2
+ Name: googletrans-curl
3
+ Version: 4.0.3
4
+ Summary: A drop-in replacement for googletrans using curl-cffi to prevent HTTP 429 rate limits
5
+ Project-URL: Homepage, https://github.com/kreier/googletrans-curl
6
+ Project-URL: Repository, https://github.com/kreier/googletrans-curl
7
+ Project-URL: Issues, https://github.com/kreier/googletrans-curl/issues
8
+ Project-URL: Upstream, https://github.com/ssut/py-googletrans
9
+ Author-email: Suhun Han <suhunhankr@gmail.com>
10
+ Maintainer: Klaus Kreier
11
+ License-File: LICENSE
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Education
14
+ Classifier: Intended Audience :: End Users/Desktop
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: MacOS :: MacOS X
17
+ Classifier: Operating System :: Microsoft :: Windows
18
+ Classifier: Operating System :: POSIX
19
+ Classifier: Programming Language :: Python
20
+ Classifier: Programming Language :: Python :: 3.8
21
+ Classifier: Programming Language :: Python :: 3.9
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Topic :: Education
26
+ Requires-Python: >=3.8
27
+ Requires-Dist: curl-cffi>=0.7.0
28
+ Requires-Dist: httpx[http2]>=0.27.2
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest; extra == 'dev'
31
+ Requires-Dist: pytest-asyncio; extra == 'dev'
32
+ Requires-Dist: pytest-cov; extra == 'dev'
33
+ Requires-Dist: ruff>=0.7; extra == 'dev'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # googletrans-curl
37
+
38
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
39
+ [![Python Version](https://img.shields.io/badge/python-3.8%2B-blue.svg)](https://www.python.org/)
40
+ [![GitHub Repo](https://img.shields.io/badge/github-kreier%2Fgoogletrans--curl-blue.svg)](https://github.com/kreier/googletrans-curl)
41
+
42
+ **googletrans-curl** is a fast, drop-in replacement fork of [`googletrans`](https://github.com/ssut/py-googletrans) that integrates [`curl-cffi`](https://github.com/lexiforest/curl_cffi) to eliminate Google Translate **HTTP 429 Too Many Requests** and rate-limiting blocks via browser TLS fingerprint impersonation.
43
+
44
+ ---
45
+
46
+ ## Drop-in Replacement for googletrans
47
+
48
+ The PyPI distribution package is named `googletrans-curl`, but the Python import namespace remains **`googletrans`**:
49
+
50
+ ```bash
51
+ # Uninstall old package if present
52
+ pip uninstall googletrans
53
+
54
+ # Install drop-in replacement
55
+ pip install googletrans-curl
56
+ ```
57
+
58
+ Existing applications continue importing `googletrans` with **zero code modifications**:
59
+
60
+ ```python
61
+ from googletrans import Translator
62
+ ```
63
+
64
+ ---
65
+
66
+ ## Why googletrans-curl?
67
+
68
+ The upstream `googletrans` uses `httpx` for HTTP requests. Google Translate's web endpoints actively monitor client TLS handshakes and HTTP/2 settings, frequently rejecting automated Python HTTP clients with `HTTP 429 Too Many Requests` or `HTTP 403 Forbidden`.
69
+
70
+ `googletrans-curl` solves this by introducing a flexible HTTP layer backed by `curl-cffi`. By impersonating real browser fingerprints (default: Chrome), requests match legitimate browser traffic and bypass fingerprint-based rate limiting.
71
+
72
+ ### Architecture
73
+
74
+ ```text
75
+ Existing Application
76
+ │
77
+ │ from googletrans import Translator
78
+ ▼
79
+ ┌───────────────┐
80
+ │ Translator │
81
+ │ Python API │
82
+ └───────┬───────┘
83
+ │
84
+ ┌───────▼───────┐
85
+ │ HTTP Session │
86
+ │ Abstraction │
87
+ └───┬───────┬───┘
88
+ │ │
89
+ transport="curl"│ │ transport="httpx"
90
+ │ │
91
+ ▼ ▼
92
+ curl-cffi httpx
93
+ │
94
+ (Chrome impersonation)
95
+ │
96
+ ▼
97
+ Google Translate Service
98
+ ```
99
+
100
+ ---
101
+
102
+ ## Features
103
+
104
+ - **Drop-in Compatible**: 100% compatible with existing `googletrans` code.
105
+ - **Anti-429 Protection**: Uses `curl-cffi` with Chrome TLS/HTTP2 impersonation.
106
+ - **Pluggable Transports**: Switch between `curl` (anti-blocking) and standard `httpx`.
107
+ - **Async First**: Native `async`/`await` support with async context manager.
108
+ - **Bulk Translation**: Efficiently translate batches of text in a single request.
109
+ - **Auto Language Detection**: Automatically detect language and confidence scores.
110
+ - **CLI Tool Included**: Includes the command-line utility `translate`.
111
+ - **Complete Type Annotations**: Fully typed for modern Python environments.
112
+
113
+ ---
114
+
115
+ ## Installation
116
+
117
+ ```bash
118
+ pip install googletrans-curl
119
+ ```
120
+
121
+ Requirements: Python 3.8 or newer.
122
+
123
+ ---
124
+
125
+ ## Quickstart
126
+
127
+ ### Basic Usage (Async)
128
+
129
+ ```python
130
+ import asyncio
131
+ from googletrans import Translator
132
+
133
+ async def main():
134
+ async with Translator() as translator:
135
+ # Detect and translate to English (default)
136
+ result = await translator.translate("안녕하세요.")
137
+ print(result.text) # "Hello."
138
+ print(result.src) # "ko"
139
+
140
+ # Translate to Japanese
141
+ result = await translator.translate("안녕하세요.", dest="ja")
142
+ print(result.text) # "こんにちは。"
143
+
144
+ # Specify source language
145
+ result = await translator.translate("veritas lux mea", src="la", dest="en")
146
+ print(result.text) # "truth is my light"
147
+
148
+ asyncio.run(main())
149
+ ```
150
+
151
+ ---
152
+
153
+ ## Transport Configuration
154
+
155
+ By default, `Translator()` automatically uses `curl-cffi` with Chrome impersonation. You can customize the transport and browser fingerprint as needed:
156
+
157
+ ```python
158
+ from googletrans import Translator
159
+
160
+ # Default: automatic browser impersonation via curl-cffi
161
+ translator = Translator()
162
+
163
+ # Explicit curl transport with Safari impersonation
164
+ translator = Translator(
165
+ transport="curl",
166
+ impersonate="safari",
167
+ )
168
+
169
+ # Standard httpx transport
170
+ translator = Translator(
171
+ transport="httpx",
172
+ )
173
+ ```
174
+
175
+ Available impersonation presets for `curl-cffi` include: `"chrome"`, `"chrome110"`, `"chrome120"`, `"safari"`, `"safari15_3"`, `"safari15_5"`, `"edge99"`, `"edge101"`, etc.
176
+
177
+ ---
178
+
179
+ ## Advanced Usage
180
+
181
+ ### Bulk Translation
182
+
183
+ Translate multiple strings in a single call:
184
+
185
+ ```python
186
+ import asyncio
187
+ from googletrans import Translator
188
+
189
+ async def main():
190
+ async with Translator() as translator:
191
+ phrases = ["The quick brown fox", "jumps over", "the lazy dog"]
192
+ translations = await translator.translate(phrases, dest="ko")
193
+ for item in translations:
194
+ print(f"{item.origin} -> {item.text}")
195
+
196
+ asyncio.run(main())
197
+ ```
198
+
199
+ ### Language Detection
200
+
201
+ Detect the language of text with confidence scores:
202
+
203
+ ```python
204
+ import asyncio
205
+ from googletrans import Translator
206
+
207
+ async def main():
208
+ async with Translator() as translator:
209
+ detection = await translator.detect("이 문장은 한글로 쓰여졌습니다.")
210
+ print(detection.lang) # "ko"
211
+ print(detection.confidence) # 0.27...
212
+
213
+ asyncio.run(main())
214
+ ```
215
+
216
+ ### Custom Service URLs
217
+
218
+ Use alternate Google Translate service endpoints:
219
+
220
+ ```python
221
+ # Rotate across multiple domains
222
+ translator = Translator(service_urls=[
223
+ "translate.google.com",
224
+ "translate.google.co.kr",
225
+ ])
226
+
227
+ # Direct client API (no token acquirer needed)
228
+ translator = Translator(service_urls=[
229
+ "translate.googleapis.com",
230
+ ])
231
+ ```
232
+
233
+ ---
234
+
235
+ ## Command-Line Tool
236
+
237
+ `googletrans-curl` includes the `translate` CLI command:
238
+
239
+ ```bash
240
+ # Translate text to English (default)
241
+ translate "veritas lux mea" -s la -d en
242
+
243
+ # Translate text to Korean
244
+ translate "Hello world" -d ko
245
+
246
+ # Detect language
247
+ translate -c "안녕하세요."
248
+ ```
249
+
250
+ ---
251
+
252
+ ## Unofficial API Disclaimer
253
+
254
+ > [!WARNING]
255
+ > This library uses Google Translate's unofficial web endpoints (`translate.google.com`).
256
+ > - While `curl-cffi` impersonation drastically reduces 429 blocks, Google may modify web endpoints at any time.
257
+ > - Maximum character limit per single request is approximately 15,000 characters.
258
+ > - For mission-critical production environments requiring guaranteed SLAs, please use [Google Cloud Translation API](https://cloud.google.com/translate/docs).
259
+
260
+ ---
261
+
262
+ ## License
263
+
264
+ This project is licensed under the [MIT License](LICENSE).
265
+ Upstream copyright (c) 2015 SuHun Han. Modifications copyright (c) 2026 Klaus Kreier and contributors.
@@ -0,0 +1,230 @@
1
+ # googletrans-curl
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+ [![Python Version](https://img.shields.io/badge/python-3.8%2B-blue.svg)](https://www.python.org/)
5
+ [![GitHub Repo](https://img.shields.io/badge/github-kreier%2Fgoogletrans--curl-blue.svg)](https://github.com/kreier/googletrans-curl)
6
+
7
+ **googletrans-curl** is a fast, drop-in replacement fork of [`googletrans`](https://github.com/ssut/py-googletrans) that integrates [`curl-cffi`](https://github.com/lexiforest/curl_cffi) to eliminate Google Translate **HTTP 429 Too Many Requests** and rate-limiting blocks via browser TLS fingerprint impersonation.
8
+
9
+ ---
10
+
11
+ ## Drop-in Replacement for googletrans
12
+
13
+ The PyPI distribution package is named `googletrans-curl`, but the Python import namespace remains **`googletrans`**:
14
+
15
+ ```bash
16
+ # Uninstall old package if present
17
+ pip uninstall googletrans
18
+
19
+ # Install drop-in replacement
20
+ pip install googletrans-curl
21
+ ```
22
+
23
+ Existing applications continue importing `googletrans` with **zero code modifications**:
24
+
25
+ ```python
26
+ from googletrans import Translator
27
+ ```
28
+
29
+ ---
30
+
31
+ ## Why googletrans-curl?
32
+
33
+ The upstream `googletrans` uses `httpx` for HTTP requests. Google Translate's web endpoints actively monitor client TLS handshakes and HTTP/2 settings, frequently rejecting automated Python HTTP clients with `HTTP 429 Too Many Requests` or `HTTP 403 Forbidden`.
34
+
35
+ `googletrans-curl` solves this by introducing a flexible HTTP layer backed by `curl-cffi`. By impersonating real browser fingerprints (default: Chrome), requests match legitimate browser traffic and bypass fingerprint-based rate limiting.
36
+
37
+ ### Architecture
38
+
39
+ ```text
40
+ Existing Application
41
+ │
42
+ │ from googletrans import Translator
43
+ ▼
44
+ ┌───────────────┐
45
+ │ Translator │
46
+ │ Python API │
47
+ └───────┬───────┘
48
+ │
49
+ ┌───────▼───────┐
50
+ │ HTTP Session │
51
+ │ Abstraction │
52
+ └───┬───────┬───┘
53
+ │ │
54
+ transport="curl"│ │ transport="httpx"
55
+ │ │
56
+ ▼ ▼
57
+ curl-cffi httpx
58
+ │
59
+ (Chrome impersonation)
60
+ │
61
+ ▼
62
+ Google Translate Service
63
+ ```
64
+
65
+ ---
66
+
67
+ ## Features
68
+
69
+ - **Drop-in Compatible**: 100% compatible with existing `googletrans` code.
70
+ - **Anti-429 Protection**: Uses `curl-cffi` with Chrome TLS/HTTP2 impersonation.
71
+ - **Pluggable Transports**: Switch between `curl` (anti-blocking) and standard `httpx`.
72
+ - **Async First**: Native `async`/`await` support with async context manager.
73
+ - **Bulk Translation**: Efficiently translate batches of text in a single request.
74
+ - **Auto Language Detection**: Automatically detect language and confidence scores.
75
+ - **CLI Tool Included**: Includes the command-line utility `translate`.
76
+ - **Complete Type Annotations**: Fully typed for modern Python environments.
77
+
78
+ ---
79
+
80
+ ## Installation
81
+
82
+ ```bash
83
+ pip install googletrans-curl
84
+ ```
85
+
86
+ Requirements: Python 3.8 or newer.
87
+
88
+ ---
89
+
90
+ ## Quickstart
91
+
92
+ ### Basic Usage (Async)
93
+
94
+ ```python
95
+ import asyncio
96
+ from googletrans import Translator
97
+
98
+ async def main():
99
+ async with Translator() as translator:
100
+ # Detect and translate to English (default)
101
+ result = await translator.translate("안녕하세요.")
102
+ print(result.text) # "Hello."
103
+ print(result.src) # "ko"
104
+
105
+ # Translate to Japanese
106
+ result = await translator.translate("안녕하세요.", dest="ja")
107
+ print(result.text) # "こんにちは。"
108
+
109
+ # Specify source language
110
+ result = await translator.translate("veritas lux mea", src="la", dest="en")
111
+ print(result.text) # "truth is my light"
112
+
113
+ asyncio.run(main())
114
+ ```
115
+
116
+ ---
117
+
118
+ ## Transport Configuration
119
+
120
+ By default, `Translator()` automatically uses `curl-cffi` with Chrome impersonation. You can customize the transport and browser fingerprint as needed:
121
+
122
+ ```python
123
+ from googletrans import Translator
124
+
125
+ # Default: automatic browser impersonation via curl-cffi
126
+ translator = Translator()
127
+
128
+ # Explicit curl transport with Safari impersonation
129
+ translator = Translator(
130
+ transport="curl",
131
+ impersonate="safari",
132
+ )
133
+
134
+ # Standard httpx transport
135
+ translator = Translator(
136
+ transport="httpx",
137
+ )
138
+ ```
139
+
140
+ Available impersonation presets for `curl-cffi` include: `"chrome"`, `"chrome110"`, `"chrome120"`, `"safari"`, `"safari15_3"`, `"safari15_5"`, `"edge99"`, `"edge101"`, etc.
141
+
142
+ ---
143
+
144
+ ## Advanced Usage
145
+
146
+ ### Bulk Translation
147
+
148
+ Translate multiple strings in a single call:
149
+
150
+ ```python
151
+ import asyncio
152
+ from googletrans import Translator
153
+
154
+ async def main():
155
+ async with Translator() as translator:
156
+ phrases = ["The quick brown fox", "jumps over", "the lazy dog"]
157
+ translations = await translator.translate(phrases, dest="ko")
158
+ for item in translations:
159
+ print(f"{item.origin} -> {item.text}")
160
+
161
+ asyncio.run(main())
162
+ ```
163
+
164
+ ### Language Detection
165
+
166
+ Detect the language of text with confidence scores:
167
+
168
+ ```python
169
+ import asyncio
170
+ from googletrans import Translator
171
+
172
+ async def main():
173
+ async with Translator() as translator:
174
+ detection = await translator.detect("이 문장은 한글로 쓰여졌습니다.")
175
+ print(detection.lang) # "ko"
176
+ print(detection.confidence) # 0.27...
177
+
178
+ asyncio.run(main())
179
+ ```
180
+
181
+ ### Custom Service URLs
182
+
183
+ Use alternate Google Translate service endpoints:
184
+
185
+ ```python
186
+ # Rotate across multiple domains
187
+ translator = Translator(service_urls=[
188
+ "translate.google.com",
189
+ "translate.google.co.kr",
190
+ ])
191
+
192
+ # Direct client API (no token acquirer needed)
193
+ translator = Translator(service_urls=[
194
+ "translate.googleapis.com",
195
+ ])
196
+ ```
197
+
198
+ ---
199
+
200
+ ## Command-Line Tool
201
+
202
+ `googletrans-curl` includes the `translate` CLI command:
203
+
204
+ ```bash
205
+ # Translate text to English (default)
206
+ translate "veritas lux mea" -s la -d en
207
+
208
+ # Translate text to Korean
209
+ translate "Hello world" -d ko
210
+
211
+ # Detect language
212
+ translate -c "안녕하세요."
213
+ ```
214
+
215
+ ---
216
+
217
+ ## Unofficial API Disclaimer
218
+
219
+ > [!WARNING]
220
+ > This library uses Google Translate's unofficial web endpoints (`translate.google.com`).
221
+ > - While `curl-cffi` impersonation drastically reduces 429 blocks, Google may modify web endpoints at any time.
222
+ > - Maximum character limit per single request is approximately 15,000 characters.
223
+ > - For mission-critical production environments requiring guaranteed SLAs, please use [Google Cloud Translation API](https://cloud.google.com/translate/docs).
224
+
225
+ ---
226
+
227
+ ## License
228
+
229
+ This project is licensed under the [MIT License](LICENSE).
230
+ Upstream copyright (c) 2015 SuHun Han. Modifications copyright (c) 2026 Klaus Kreier and contributors.
@@ -0,0 +1,8 @@
1
+ """Free Google Translate API for Python. Translates totally free of charge."""
2
+
3
+ __all__ = ("Translator",)
4
+ __version__ = "4.0.3"
5
+
6
+
7
+ from googletrans.client import Translator
8
+ from googletrans.constants import LANGCODES, LANGUAGES # noqa
@@ -0,0 +1,48 @@
1
+ import argparse
2
+ import asyncio
3
+ import sys
4
+
5
+ from googletrans.client import Translator
6
+
7
+
8
+ async def _run_cli(args: argparse.Namespace) -> None:
9
+ async with Translator() as translator:
10
+ if args.detect:
11
+ result = await translator.detect(args.text)
12
+ print(f"[{result.lang}, {result.confidence}] {args.text}")
13
+ return
14
+
15
+ result = await translator.translate(args.text, dest=args.dest, src=args.src)
16
+ output = f"""[{result.src}] {result.origin}
17
+ ->
18
+ [{result.dest}] {result.text}
19
+ [pron.] {result.pronunciation}"""
20
+ print(output)
21
+
22
+
23
+ def main() -> None:
24
+ parser = argparse.ArgumentParser(
25
+ description="Python Google Translator as a command-line tool"
26
+ )
27
+ parser.add_argument("text", help="The text you want to translate.")
28
+ parser.add_argument(
29
+ "-d",
30
+ "--dest",
31
+ default="en",
32
+ help="The destination language you want to translate. (Default: en)",
33
+ )
34
+ parser.add_argument(
35
+ "-s",
36
+ "--src",
37
+ default="auto",
38
+ help="The source language you want to translate. (Default: auto)",
39
+ )
40
+ parser.add_argument(
41
+ "-c", "--detect", action="store_true", default=False, help="Detect language"
42
+ )
43
+ args = parser.parse_args()
44
+ asyncio.run(_run_cli(args))
45
+
46
+
47
+ if __name__ == "__main__":
48
+ main()