
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
twocaptcha-python
Advanced tools
Python client for 2captcha solving service - Bypass reCAPTCHA, Cloudflare Turnstile, FunCaptcha, GeeTest and solve any other captchas
A simple 2captcha Python client for the 2captcha solving service - Bypass reCAPTCHA, Cloudflare Turnstile, FunCaptcha, GeeTest and solve any other captchas.
pip install twocaptcha-python -U
uv add twocaptcha-python -U
Note: You can use any task configuration directly from the 2Captcha API documentation. Just copy the task object from their examples and pass it to solve_captcha().
ImageToTextTaskRecaptchaV2TaskProxyless, RecaptchaV2TaskRecaptchaV3TaskProxyless, RecaptchaV3TaskRecaptchaV2EnterpriseTaskProxyless, RecaptchaV3EnterpriseTaskProxylessFunCaptchaTaskProxyless, FunCaptchaTaskGeeTestTaskProxyless, GeeTestTaskTurnstileTaskProxyless, TurnstileTaskCapyTaskProxyless, CapyTaskLeminTaskProxyless, LeminTaskAmazonTaskProxyless, AmazonTaskTextCaptchaTaskRotateTaskCoordinatesTaskDrawAroundTaskGridTaskAudioTaskMtCaptchaTaskProxyless, MtCaptchaTaskDataDomeTaskProxyless, DataDomeTaskFriendlyCaptchaTaskProxyless, FriendlyCaptchaTaskBoundingBoxTaskCutCaptchaTaskProxyless, CutCaptchaTaskAtbCaptchaTaskProxyless, AtbCaptchaTaskTencentTaskProxyless, TencentTaskProsopoTaskProxyless, ProsopoTaskCaptchaFoxTaskProxyless, CaptchaFoxTaskVKTaskProxyless, VKTaskTemuTaskProxyless, TemuTaskfrom TwoCaptcha import SyncTwoCaptcha, TwoCaptchaError
client = SyncTwoCaptcha(api_key="YOUR_API_KEY")
def auto_solve_captcha():
"""Auto solve captcha using 2captcha api."""
try:
task = {
"type": "RecaptchaV2TaskProxyless",
"websiteURL": "https://2captcha.com/demo/recaptcha-v2",
"websiteKey": "6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u",
}
balance = client.balance()
print(f"Balance: {balance}")
result = client.solve_captcha(task)
print(f"Result: {result}")
except TwoCaptchaError as e:
print(f"TwoCaptcha Error: {e}")
auto_solve_captcha()
from TwoCaptcha import SyncTwoCaptcha, TwoCaptchaError
client = SyncTwoCaptcha(api_key="YOUR_API_KEY")
def manual_solve_captcha(task_id=None):
"""Manual solve captcha using 2captcha api."""
try:
task = {
"type": "RecaptchaV2TaskProxyless",
"websiteURL": "https://2captcha.com/demo/recaptcha-v2",
"websiteKey": "6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u",
}
create_result = client.create_task(task)
task_id = create_result["taskId"]
print(f"Created task with ID: {task_id}")
task_result = client.get_task_result(task_id)
print(f"Task result: {task_result}")
except TwoCaptchaError as e:
print(f"TwoCaptcha Error: {e}")
manual_solve_captcha()
from TwoCaptcha import AsyncTwoCaptcha, TwoCaptchaError
import asyncio
async def auto_solve_captcha():
"""Auto solve captcha using 2captcha api."""
client = AsyncTwoCaptcha(api_key="YOUR_API_KEY")
try:
task = {
"type": "RecaptchaV2TaskProxyless",
"websiteURL": "https://2captcha.com/demo/recaptcha-v2",
"websiteKey": "6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u",
}
balance = await client.balance()
print(f"Balance: {balance}")
result = await client.solve_captcha(task)
print(f"Result: {result}")
except TwoCaptchaError as e:
print(f"TwoCaptcha Error: {e}")
finally:
await client.close()
if __name__ == "__main__":
asyncio.run(auto_solve_captcha())
from TwoCaptcha import AsyncTwoCaptcha, TwoCaptchaError
import asyncio
async def manual_solve_captcha():
"""Manual solve captcha using 2captcha api."""
client = AsyncTwoCaptcha(api_key="YOUR_API_KEY")
try:
task = {
"type": "RecaptchaV2TaskProxyless",
"websiteURL": "https://2captcha.com/demo/recaptcha-v2",
"websiteKey": "6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u",
}
create_result = await client.create_task(task)
task_id = create_result["taskId"]
print(f"Created task with ID: {task_id}")
task_result = await client.get_task_result(task_id)
print(f"Task result: {task_result}")
except TwoCaptchaError as e:
print(f"TwoCaptcha Error: {e}")
finally:
await client.close()
if __name__ == "__main__":
asyncio.run(manual_solve_captcha())
from TwoCaptcha import AsyncTwoCaptcha, TwoCaptchaError
import asyncio
async def context_manager_example():
"""Context manager example."""
async with AsyncTwoCaptcha(api_key="YOUR_API_KEY") as client:
balance = await client.balance()
print(f"Context manager balance: {balance}")
if __name__ == "__main__":
asyncio.run(context_manager_example())
from TwoCaptcha import AsyncTwoCaptcha, TwoCaptchaError
import asyncio
async def multiple_tasks_example():
"""Multiple tasks example."""
client = AsyncTwoCaptcha(api_key="YOUR_API_KEY")
try:
tasks = [
{
"type": "RecaptchaV2TaskProxyless",
"websiteURL": "https://2captcha.com/demo/recaptcha-v2",
"websiteKey": "6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u",
},
{
"type": "RecaptchaV2TaskProxyless",
"websiteURL": "https://2captcha.com/demo/recaptcha-v2",
"websiteKey": "6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u",
},
]
print("Solving multiple captchas concurrently...")
results = await asyncio.gather(
*[client.solve_captcha(task) for task in tasks], return_exceptions=True
)
for i, result in enumerate(results):
if isinstance(result, Exception):
print(f"Task {i+1} failed: {result}")
else:
print(f"Task {i+1} solved: {result['solution']['gRecaptchaResponse'][:30]}...")
except Exception as e:
print(f"Error in multiple tasks: {e}")
finally:
await client.close()
if __name__ == "__main__":
asyncio.run(multiple_tasks_example())
task = {
"type": "RecaptchaV2TaskProxyless",
"websiteURL": "https://example.com",
"websiteKey": "6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u"
}
result = client.solve_captcha(task)
task = {
"type": "RecaptchaV2Task",
"websiteURL": "https://example.com",
"websiteKey": "6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u",
"proxyType": "http",
"proxyAddress": "1.2.3.4",
"proxyPort": "8080",
"proxyLogin": "user",
"proxyPassword": "pass"
}
result = client.solve_captcha(task)
task = {
"type": "RecaptchaV3TaskProxyless",
"websiteURL": "https://example.com",
"websiteKey": "6LfB5_IbAAAAAMCtsjEHEHKqcB9iQocwwxTiihJu",
"minScore": 0.9,
"pageAction": "submit"
}
result = client.solve_captcha(task)
task = {
"type": "ImageToTextTask",
"body": "base64_encoded_image_data"
}
result = client.solve_captcha(task)
balance = client.balance()
print(f"Balance: ${balance['balance']}")
{
"errorId": 0,
"status": "ready",
"solution": {
"gRecaptchaResponse": "03ADUVZw...UWxTAe6ncIa",
"token": "03ADUVZw...UWxTAe6ncIa"
},
"cost": "0.00299",
"ip": "1.2.3.4",
"createTime": 1692863536,
"endTime": 1692863556,
"solveCount": 1
}
from twocaptcha import TwoCaptchaError
try:
result = client.solve_captcha(task)
except TwoCaptchaError as e:
print(f"Error: {e}")
client.solve_captcha(task) - Solve captcha and wait for resultclient.balance() - Check account balanceclient.create_task.create_task(task) - Create task onlyclient.get_task_result.get_task_result(task_id) - Get task resultclient.get_balance.get_balance() - Check account balance (alternative)client = TwoCaptcha(
api_key="YOUR_API_KEY",
timeout=120, # Max wait time in seconds
polling_interval=5 # Check interval in seconds
)
For complete API documentation and task parameters, visit 2captcha.com/api-docs.
FAQs
Python client for 2captcha solving service - Bypass reCAPTCHA, Cloudflare Turnstile, FunCaptcha, GeeTest and solve any other captchas
We found that twocaptcha-python demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.