You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Refactor: Move exceptions to a separate module
* Refactor: Move exceptions to a separate module
* Refactor: Move exceptions to a separate module
* Add async support
* Fix: Set follow_redirects=True for all AsyncClient instances
* Fix: Resolve example image paths in tests
Copy file name to clipboardExpand all lines: README.md
+64-1Lines changed: 64 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,6 +76,18 @@ from twocaptcha import TwoCaptcha
76
76
77
77
solver = TwoCaptcha('YOUR_API_KEY')
78
78
```
79
+
80
+
<details>
81
+
<summary>Async</summary>
82
+
83
+
```python
84
+
from twocaptcha import AsyncTwoCaptcha
85
+
86
+
solver = AsyncTwoCaptcha('YOUR_API_KEY')
87
+
```
88
+
89
+
</details>
90
+
79
91
Also, there are a few options that can be configured:
80
92
81
93
```python
@@ -517,7 +529,55 @@ proxy={
517
529
```
518
530
519
531
## Async calls
520
-
You can also make async calls with [asyncio], for example:
532
+
533
+
To use the async version, just replace `TwoCaptcha` with `AsyncTwoCaptcha`:
534
+
535
+
```python
536
+
import asyncio
537
+
from twocaptcha import AsyncTwoCaptcha
538
+
539
+
asyncdefsolve_captcha():
540
+
solver = AsyncTwoCaptcha('YOUR_API_KEY')
541
+
542
+
try:
543
+
recaptcha_result =await solver.recaptcha(...)
544
+
return recaptcha_result
545
+
exceptExceptionas e:
546
+
print(e)
547
+
returnNone
548
+
549
+
if__name__=='__main__':
550
+
result = asyncio.run(solve_captcha())
551
+
```
552
+
553
+
The `AsyncTwoCaptcha` class supports all the same methods and parameters as the synchronous `TwoCaptcha` class but operates asynchronously. Configuration is identical.
554
+
555
+
### Solving Multiple Captchas in Parallel
556
+
557
+
One of the main advantages of using async support is the ability to solve multiple captchas concurrently:
558
+
559
+
```python
560
+
asyncdefsolve_multiple_captchas():
561
+
solver = AsyncTwoCaptcha('YOUR_API_KEY')
562
+
563
+
# Start all tasks simultaneously
564
+
task1 = asyncio.create_task(solver.text('What color is the sky on a clear day?'))
565
+
task2 = asyncio.create_task(solver.text('What is 2+2?'))
566
+
task3 = asyncio.create_task(solver.text('Name of the planet we live on?'))
0 commit comments