11# Captcha Solver Python SDK
22![ python-examples-banner] ( assets/repo-banner-python.png )
33
4- Official Python SDK for the Captcha Solver API. Solve reCAPTCHA v2, reCAPTCHA v3, Cloudflare Turnstile, GeeTest, and image captchas with a single method call.
4+ Official Python SDK for the Captcha Solver API. Solve reCAPTCHA v2/ v3, Cloudflare Turnstile, GeeTest, Yandex SmartCaptcha, Tencent, and image/click captchas with a single method call -- sync or async .
55
66## Table of Contents
77
88- [ Installation] ( #installation )
9+ - [ Configuration] ( #configuration )
910- [ Quick Start] ( #quick-start )
1011- [ Supported CAPTCHA Types] ( #supported-captcha-types )
1112- [ Usage Examples] ( #usage-examples )
12- - [ reCAPTCHA v2] ( #recaptcha-v2 )
13+ - [ reCAPTCHA v2 with proxy ] ( #recaptcha-v2-with-proxy )
1314 - [ reCAPTCHA v2 Enterprise] ( #recaptcha-v2-enterprise )
1415 - [ reCAPTCHA v3] ( #recaptcha-v3 )
1516 - [ Cloudflare Turnstile] ( #cloudflare-turnstile )
1617 - [ Image to Text] ( #image-to-text )
1718 - [ GeeTest v3] ( #geetest-v3 )
1819 - [ GeeTest v4] ( #geetest-v4 )
20+ - [ Yandex SmartCaptcha] ( #yandex-smartcaptcha )
21+ - [ Coordinates (click captcha)] ( #coordinates-click-captcha )
22+ - [ Tencent] ( #tencent )
1923 - [ Check Balance] ( #check-balance )
20- - [ Custom Timeout] ( #custom-timeout-and-polling )
24+ - [ Custom Timeout and Polling] ( #custom-timeout-and-polling )
25+ - [ Async Client] ( #async-client )
2126 - [ Error Handling] ( #error-handling )
2227- [ Requirements] ( #requirements )
2328- [ API Documentation] ( #api-documentation )
@@ -30,13 +35,18 @@ Official Python SDK for the Captcha Solver API. Solve reCAPTCHA v2, reCAPTCHA v3
3035pip install git+https://github.com/captcha-solver-api/python-sdk.git
3136```
3237## Configuration
33- Set your API key as an environment variable.
38+ The client always takes the API key as an explicit argument -- it does not read
39+ environment variables on its own. Read ` CAPTCHA_API_KEY ` yourself and pass it in:
3440``` bash
3541export CAPTCHA_API_KEY=your_api_key
3642```
37- Or pass it directly to the client.
3843``` python
44+ import os
3945from captcha_sdk import CaptchaClient
46+ client = CaptchaClient(os.getenv(" CAPTCHA_API_KEY" ))
47+ ```
48+ Or just pass the key directly, without an environment variable:
49+ ``` python
4050client = CaptchaClient(" your_api_key" )
4151```
4252## Quick Start
@@ -62,6 +72,9 @@ print(result["gRecaptchaResponse"])
6272| GeeTest v3 | ✅ | ✅ |
6373| GeeTest v4 | ✅ | ✅ |
6474| Image to Text | ✅ | ❌ |
75+ | Yandex SmartCaptcha | ✅ | ✅ |
76+ | Coordinates (click captcha) | ✅ | ❌ |
77+ | Tencent | ✅ | ✅ |
6578## Usage Examples
6679### reCAPTCHA v2 with proxy
6780``` python
@@ -165,6 +178,49 @@ task = GeeTestTaskProxyless(
165178result = client.solve(task)
166179print (result[" captcha_output" ])
167180```
181+ ### Yandex SmartCaptcha
182+ ``` python
183+ from captcha_sdk import CaptchaClient
184+ from captcha_sdk.tasks import YandexSmartCaptchaTaskProxyless
185+ client = CaptchaClient(" your_api_key" )
186+ task = YandexSmartCaptchaTaskProxyless(
187+ websiteURL = " https://example.com/login" ,
188+ websiteKey = " Y5Lh0ti..."
189+ )
190+ result = client.solve(task)
191+ print (result[" token" ])
192+ ```
193+ Use ` YandexSmartCaptchaTask ` instead for the with-proxy variant (same extra ` proxyType ` /` proxyAddress ` /` proxyPort ` /` proxyLogin ` /` proxyPassword ` fields as ` RecaptchaV2Task ` ).
194+
195+ To solve Yandex SmartCaptcha's image challenge instead of the token challenge, use ` CoordinatesTask ` with ` imgType="smart_captcha" ` or ` imgType="pazl_smart_captcha" ` -- see [ examples/sync/yandex_smartcaptcha_image.py] ( examples/sync/yandex_smartcaptcha_image.py ) (or [ examples/async] ( examples/async/yandex_smartcaptcha_image.py ) for the async version).
196+
197+ ### Coordinates (click captcha)
198+ ``` python
199+ from captcha_sdk import CaptchaClient
200+ from captcha_sdk.tasks import CoordinatesTask
201+ import base64
202+ with open (" captcha.png" , " rb" ) as f:
203+ image_base64 = base64.b64encode(f.read()).decode(" utf-8" )
204+ client = CaptchaClient(" your_api_key" )
205+ task = CoordinatesTask(
206+ body = image_base64,
207+ comment = " click on the green apple"
208+ )
209+ result = client.solve(task)
210+ print (result[" coordinates" ]) # [{"x": 358, "y": 268}, ...]
211+ ```
212+ ### Tencent
213+ ``` python
214+ from captcha_sdk import CaptchaClient
215+ from captcha_sdk.tasks import TencentTaskProxyless
216+ client = CaptchaClient(" your_api_key" )
217+ task = TencentTaskProxyless(
218+ websiteURL = " https://example.com/login" ,
219+ appId = " 190014885"
220+ )
221+ result = client.solve(task)
222+ print (result[" ticket" ])
223+ ```
168224### Check balance
169225``` python
170226from captcha_sdk import CaptchaClient
@@ -180,12 +236,63 @@ client = CaptchaClient(
180236 polling_interval = 5
181237)
182238```
239+ A single ` solve() ` call can also override the client's default timeout, which is handy for
240+ captcha types that reliably take longer to solve (e.g. classic reCAPTCHA v2) without changing
241+ it for every other call:
242+ ``` python
243+ result = client.solve(task, timeout = 300 )
244+ ```
245+ ### Async client
246+ ` AsyncCaptchaClient ` mirrors ` CaptchaClient ` method-for-method (` create_task ` , ` get_task_result ` ,
247+ ` get_balance ` , ` solve ` , same constructor options), just ` await ` ed and built on ` httpx ` instead of
248+ ` requests ` :
249+ ``` python
250+ import asyncio
251+ from captcha_sdk import AsyncCaptchaClient
252+ from captcha_sdk.tasks import RecaptchaV2TaskProxyless
253+
254+ async def main ():
255+ client = AsyncCaptchaClient(" your_api_key" )
256+ task = RecaptchaV2TaskProxyless(
257+ websiteURL = " https://example.com/login" ,
258+ websiteKey = " 6Le-xxxxxxxxx"
259+ )
260+ result = await client.solve(task)
261+ print (result[" gRecaptchaResponse" ])
262+
263+ asyncio.run(main())
264+ ```
265+ See [ examples/async] ( examples/async ) for more.
266+
267+ #### Solving multiple captchas in parallel
268+ This is the main reason to reach for the async client -- run several ` solve() ` calls
269+ concurrently instead of waiting for each one in turn:
270+ ``` python
271+ import asyncio
272+ from captcha_sdk import AsyncCaptchaClient
273+ from captcha_sdk.tasks import RecaptchaV2TaskProxyless, TurnstileTaskProxyless
274+
275+ async def solve_multiple ():
276+ client = AsyncCaptchaClient(" your_api_key" )
277+
278+ task1 = client.solve(RecaptchaV2TaskProxyless(websiteURL = " https://site1.com" , websiteKey = " key1" ))
279+ task2 = client.solve(TurnstileTaskProxyless(websiteURL = " https://site2.com" , websiteKey = " key2" ))
280+
281+ results = await asyncio.gather(task1, task2, return_exceptions = True )
282+ return results
283+
284+ results = asyncio.run(solve_multiple())
285+ ```
286+ This completes in roughly the time of the slowest single captcha, not the sum of all of them.
287+
183288### Error handling
184289``` python
185- from captcha_sdk import CaptchaClient, ApiError, TimeoutError , NetworkError
290+ from captcha_sdk import CaptchaClient, ApiError, TimeoutError , NetworkError, ValidationError
186291client = CaptchaClient(" your_api_key" )
187292try :
188293 result = client.solve(task)
294+ except ValidationError as e:
295+ print (f " Invalid argument: { e} " )
189296except ApiError as e:
190297 print (f " API error: { e.error_code} { e.error_description} " )
191298except TimeoutError :
0 commit comments