Skip to main content

Python client for 2captcha solving service - Bypass reCAPTCHA, Cloudflare Turnstile, FunCaptcha, GeeTest and solve any other captchas

Project description

PyPI version Python Versions Downloads Downloads Downloads

TwoCaptcha Python Library

A simple 2captcha Python client for the 2captcha solving service - Bypass reCAPTCHA, Cloudflare Turnstile, FunCaptcha, GeeTest and solve any other captchas.

Installation

  • Using pip
pip install twocaptcha-python -U
  • Using uv
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().

Supported Captcha Types

  • Normal CAPTCHA - ImageToTextTask
  • reCAPTCHA V2 - RecaptchaV2TaskProxyless, RecaptchaV2Task
  • reCAPTCHA V3 - RecaptchaV3TaskProxyless, RecaptchaV3Task
  • reCAPTCHA Enterprise - RecaptchaV2EnterpriseTaskProxyless, RecaptchaV3EnterpriseTaskProxyless
  • Arkose Labs CAPTCHA - FunCaptchaTaskProxyless, FunCaptchaTask
  • GeeTest CAPTCHA - GeeTestTaskProxyless, GeeTestTask
  • Cloudflare Turnstile - TurnstileTaskProxyless, TurnstileTask
  • Capy Puzzle CAPTCHA - CapyTaskProxyless, CapyTask
  • Lemin CAPTCHA - LeminTaskProxyless, LeminTask
  • Amazon CAPTCHA - AmazonTaskProxyless, AmazonTask
  • Text CAPTCHA - TextCaptchaTask
  • Rotate CAPTCHA - RotateTask
  • Click CAPTCHA - CoordinatesTask
  • Draw Around - DrawAroundTask
  • Grid CAPTCHA - GridTask
  • Audio CAPTCHA - AudioTask
  • MTCaptcha - MtCaptchaTaskProxyless, MtCaptchaTask
  • DataDome CAPTCHA - DataDomeTaskProxyless, DataDomeTask
  • Friendly Captcha - FriendlyCaptchaTaskProxyless, FriendlyCaptchaTask
  • Bounding box - BoundingBoxTask
  • Cutcaptcha - CutCaptchaTaskProxyless, CutCaptchaTask
  • atbCAPTCHA - AtbCaptchaTaskProxyless, AtbCaptchaTask
  • Tencent - TencentTaskProxyless, TencentTask
  • Prosopo Procaptcha - ProsopoTaskProxyless, ProsopoTask
  • CaptchaFox - CaptchaFoxTaskProxyless, CaptchaFoxTask
  • VK Captcha - VKTaskProxyless, VKTask
  • Temu Captcha - TemuTaskProxyless, TemuTask

Usage Examples

Synchronous Client

Auto solve captcha sync

from 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()

Manual solve captcha sync

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()

Asynchronous Client

Auto solve captcha Async

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())

Manual solve captcha Async

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())

Solve captcha using async context manager

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())

Async multiple captcha solver

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())

Different Captcha Types

reCAPTCHA v2 (Proxyless)

task = {
    "type": "RecaptchaV2TaskProxyless",
    "websiteURL": "https://example.com",
    "websiteKey": "6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u"
}
result = client.solve_captcha(task)

reCAPTCHA v2 (With Proxy)

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)

reCAPTCHA v3

task = {
    "type": "RecaptchaV3TaskProxyless",
    "websiteURL": "https://example.com",
    "websiteKey": "6LfB5_IbAAAAAMCtsjEHEHKqcB9iQocwwxTiihJu",
    "minScore": 0.9,
    "pageAction": "submit"
}
result = client.solve_captcha(task)

Normal Image Captcha

task = {
    "type": "ImageToTextTask",
    "body": "base64_encoded_image_data"
}
result = client.solve_captcha(task)

Check Balance

balance = client.balance()
print(f"Balance: ${balance['balance']}")

Response Format

{
  "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
}

Error Handling

from twocaptcha import TwoCaptchaError

try:
    result = client.solve_captcha(task)
except TwoCaptchaError as e:
    print(f"Error: {e}")

API Methods

  • client.solve_captcha(task) - Solve captcha and wait for result
  • client.balance() - Check account balance
  • client.create_task.create_task(task) - Create task only
  • client.get_task_result.get_task_result(task_id) - Get task result
  • client.get_balance.get_balance() - Check account balance (alternative)

Configuration

client = TwoCaptcha(
    api_key="YOUR_API_KEY",
    timeout=120,        # Max wait time in seconds
    polling_interval=5  # Check interval in seconds
)

Documentation

For complete API documentation and task parameters, visit 2captcha.com/api-docs.

Star History

Star History Chart

Visitors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twocaptcha_python-0.0.4.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

twocaptcha_python-0.0.4-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file twocaptcha_python-0.0.4.tar.gz.

File metadata

  • Download URL: twocaptcha_python-0.0.4.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for twocaptcha_python-0.0.4.tar.gz
Algorithm Hash digest
SHA256 94fd3e2390d7441ad61671005f66f2a93ca971e3b8e3335a8a7970a28f00362c
MD5 f9019b7483f6d45a7b10dfda45e8c966
BLAKE2b-256 3cd4b6fb0b5d0a212abf665695daaf6decda2718c10383e3b2d18d67202107f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for twocaptcha_python-0.0.4.tar.gz:

Publisher: pypi-publish.yml on SSujitX/twocaptcha-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file twocaptcha_python-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for twocaptcha_python-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f43098e4dafeb6c931a3be0217acace42aee57ce7b8e44f1214972fb4be3c65d
MD5 301de593f4bbbf0d87f7e9691b2dc487
BLAKE2b-256 ef407c46e2cc5da108ac166b61de2a4f55cc1566a5dfebe1ba8c6b20c47b95d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for twocaptcha_python-0.0.4-py3-none-any.whl:

Publisher: pypi-publish.yml on SSujitX/twocaptcha-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page