async-2captcha


Nameasync-2captcha JSON
Version 0.1.3 PyPI version JSON
download
home_pageNone
SummaryAn asynchronous Python client for the 2Captcha API.
upload_time2025-02-11 21:54:38
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2025 Dmitry Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords 2captcha async captcha-solving captcha
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # async-2captcha

[![PyPI version](https://badge.fury.io/py/async-2captcha.svg)](https://badge.fury.io/py/async-2captcha)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

**async-2captcha** is an **asynchronous Python client** for the [2Captcha API](https://2captcha.com/). It provides helper classes for creating and managing captcha-solving tasks, including specialized solvers for Cloudflare Turnstile and image-based captchas (with selectable coordinates). This library is designed to handle common errors gracefully, raising both HTTP exceptions and 2Captcha-specific exceptions when appropriate.

---

## Table of Contents

- [Features](#features)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Usage Examples](#usage-examples)
  - [Cloudflare Turnstile Captcha](#cloudflare-turnstile-captcha)
  - [Coordinates (Image-Click) Captcha](#coordinates-image-click-captcha)
  - [Retrieving Task Results](#retrieving-task-results)
  - [Checking Account Balance](#checking-account-balance)
- [API Reference](#api-reference)
  - [Async2Captcha Class](#async2captcha-class)
  - [Solvers](#solvers)
    - [TurnstileSolver](#turnstilesolver)
    - [CoordinatesSolver](#coordinatessolver)
    - [Not-Yet-Implemented Solvers](#not-yet-implemented-solvers)
  - [Models](#models)
  - [Error Handling](#error-handling)
- [Contributing](#contributing)
- [License](#license)

---

## Features

- **Asynchronous**: Built on top of [httpx](https://www.python-httpx.org/) and `async/await`, allowing concurrent operations.
- **Multiple Captcha Types**:
  - Cloudflare Turnstile
  - Coordinate-based image captchas (e.g., “click all apples”)
  - (More solver classes can be added or contributed)
- **Exception Handling**:
  - Raises HTTP errors (`4xx` / `5xx`) if the server’s status code is >= 400.
  - Raises 2Captcha-specific errors (e.g., `ERROR_NO_SLOT_AVAILABLE`, `ERROR_ZERO_BALANCE`, etc.) with clear messages.
- **HTTP/2 Support**:
  - For potentially improved performance, you can enable HTTP/2 by installing `httpx[http2]` and passing `http2=True` when creating the `Async2Captcha` client.
- **Convenient**: Automatically includes your 2Captcha API key in each request and provides high-level methods like `get_balance()`.

---

## Installation

Requires **Python 3.8+**.

```bash
pip install async-2captcha
```

If you want **HTTP/2** support (optional), install:
```bash
pip install httpx[http2]
```

---

## Quick Start

### 1. Get Your 2Captcha API Key

1. Sign up or log in to [2Captcha.com](https://2captcha.com/).
2. Navigate to your [account dashboard](https://2captcha.com/setting) to find your **API key**.

### 2. Instantiate the Client

```python
import asyncio

from async_2captcha.client import Async2Captcha

async def main():
    api_key = "YOUR_2CAPTCHA_API_KEY"
    # Pass http2=True if you installed httpx[http2] and want to enable HTTP/2
    captcha_client = Async2Captcha(api_key, http2=True)

    balance = await captcha_client.get_balance()
    print(f"Your 2Captcha balance is: ${balance:.2f}")

asyncio.run(main())
```

---

## Usage Examples

### Cloudflare Turnstile Captcha

**Turnstile** is Cloudflare’s captcha alternative. To solve a Turnstile captcha:

```python
import asyncio

from async_2captcha.client import Async2Captcha

async def solve_turnstile():
    api_key = "YOUR_2CAPTCHA_API_KEY"
    client = Async2Captcha(api_key)

    # For a normal Turnstile widget (proxyless):
    task_result = await client.turnstile.create_task(
        website_url="https://example.com/login",
        website_key="0x4AAAAAAAA...",
    )
    
    # If the task succeeded, you'll receive a TurnstileTask object with a solution field:
    if task_result.solution:
        print("Turnstile token:", task_result.solution.token)
        print("User agent used:", task_result.solution.user_agent)
    else:
        print("No solution found or an error occurred.")

asyncio.run(solve_turnstile())
```

- **Proxy Support**: To use your own proxy, provide a `proxy_url` such as `"http://user:pass@1.2.3.4:8080"` or `"socks5://..."` to `create_task()`. The solver will automatically switch to a proxy-based task.

### Coordinates (Image-Click) Captcha

Some captchas require clicking specific regions of an image. Use the **CoordinatesSolver**:

```python
import asyncio
import base64

from async_2captcha.client import Async2Captcha

async def solve_coordinates():
    api_key = "YOUR_2CAPTCHA_API_KEY"
    client = Async2Captcha(api_key)

    # Prepare the image as a base64 string
    with open("captcha.jpg", "rb") as f:
        image_data = base64.b64encode(f.read()).decode("utf-8")

    # Create and wait for the coordinates task
    task_result = await client.coordinates.create_task(
        body=image_data, 
        comment="Click all the apples in the image."
    )
    
    # On success, you'll have a list of (x, y) coordinates
    if task_result.solution:
        print("Coordinates:", task_result.solution.coordinates)
    else:
        print("No solution found or an error occurred.")

asyncio.run(solve_coordinates())
```

### Retrieving Task Results

While the included solver classes (`TurnstileSolver`, `CoordinatesSolver`, etc.) automate task creation and waiting, you can also manage tasks directly:

```python
import asyncio
from async_2captcha.client import Async2Captcha
from async_2captcha.enums import TaskType

async def create_and_poll_task():
    api_key = "YOUR_2CAPTCHA_API_KEY"
    client = Async2Captcha(api_key)

    # Create a task manually
    running_task = await client.create_task(TaskType.TURNSTILE_PROXYLESS, payload={
        "websiteURL": "https://example.com",
        "websiteKey": "0x4AAAAAAA..."
    })

    # Poll or wait until completed
    task_result = await running_task.wait_until_completed()
    
    if task_result.is_ready():
        print("Task is solved!", task_result.solution)
    else:
        print("Task is still processing...")

asyncio.run(create_and_poll_task())
```

### Checking Account Balance

```python
import asyncio
from async_2captcha.client import Async2Captcha

async def check_balance():
    client = Async2Captcha("YOUR_2CAPTCHA_API_KEY")
    balance = await client.get_balance()
    print(f"2Captcha balance: ${balance}")

asyncio.run(check_balance())
```

---

## API Reference

### Async2Captcha Class

Located in [`async_2captcha/client.py`](async_2captcha/client.py), the core class:

- **Parameters**:
  - `api_key` (str): 2Captcha API key.
  - `http2` (bool, optional): If `True`, enables HTTP/2 (requires `pip install httpx[http2]`).
- **Attributes**:
  - `turnstile`: A `TurnstileSolver` instance.
  - `coordinates`: A `CoordinatesSolver` instance.
- **Key Methods**:
  1. `create_task(type: TaskType, payload: Dict[str, Any]) -> RunningTask`
     - Creates a captcha task (low-level method).
  2. `get_task_result(task_id: int) -> Task`
     - Fetches result for an existing task.
  3. `get_balance() -> float`
     - Retrieves account balance.

### Solvers

#### TurnstileSolver

- **TurnstileSolver** (`async_2captcha/solvers/turnstile.py`):
  - `create_task(website_url, website_key, action=None, data=None, pagedata=None, proxy_url=None) -> TurnstileTask`
  - Returns a `TurnstileTask` object with the `solution` containing the Turnstile token.

#### CoordinatesSolver

- **CoordinatesSolver** (`async_2captcha/solvers/coordinates.py`):
  - `create_task(body, comment=None, img_instructions=None, min_clicks=None, max_clicks=None) -> CoordinatesTask`
  - Returns a `CoordinatesTask` object, whose `solution` includes a list of clicked coordinates.

#### Not-Yet-Implemented Solvers

The following captcha solvers are currently placeholders (`NotImplementedSolver`). They will raise a `NotImplementedError` if called. Contributions to implement them are welcome.

**Complex captchas:**
- reCAPTCHA V2 (Proxyless and proxy-based): `recaptcha_v2`
- reCAPTCHA V3 (Proxyless and proxy-based): `recaptcha_v3`
- reCAPTCHA V2 Enterprise (Proxyless and proxy-based): `recaptcha_v2_enterprise`
- reCAPTCHA V3 Enterprise: `recaptcha_v3_enterprise`
- Arkose Labs: `arkose_labs`
- GeeTest: `geetest`
- Capy Puzzle: `capy_puzzle`
- Keycaptcha: `keycaptcha`
- Lemin: `lemin`
- Amazon CAPTCHA: `amazon_captcha`
- Cybersiara CAPTCHA: `cybersiara`
- MtCaptcha: `mt_captcha`
- CutCaptcha: `cutcaptcha`
- Friendly CAPTCHA: `friendly_captcha`
- Datadome CAPTCHA: `datadome_captcha`
- ATB CAPTCHA: `atb_captcha`
- Tencent CAPTCHA: `tencent`
- Prosopo CAPTCHA: `prosopo_procaptcha`

**Simple captchas:**
- Normal image-based captchas: `normal_captcha`
- Text-based captchas: `text_captcha`
- Rotational captchas: `rotate`
- Grid-based captchas: `grid`
- Object-drawing captchas: `draw_around`
- Bounding box captchas: `bounding_box`
- Audio captchas: `audio_captcha`

---

### Models

The project uses **Pydantic models** to structure data responses from the 2Captcha API. These models are defined across various files within the `async_2captcha/models/` directory. Notable models include:

- **`Task`** (`models/task.py`):
  - Represents the response from the 2Captcha API for captcha tasks, including status, solution, or error details.
  - Methods:
    - `is_ready()`: Returns `True` if the task is completed and ready.
    - `is_processing()`: Returns `True` if the task is still being processed.

- **`TurnstileTask`** (`solvers/turnstile.py`):
  - Inherits from the `Task` model and includes Turnstile-specific solutions such as tokens and user agents.

- **`CoordinatesTask`** (`solvers/coordinates.py`):
  - Inherits from the `Task` model and includes the list of (x, y) coordinates selected in image-based captchas.

- **Base Models**:
  - **`CamelCaseModel`** (`models/base.py`): A base model used for converting fields between camelCase (used by 2Captcha) and snake_case (used internally).

These models ensure consistency and validation of API responses. When creating new solvers, you can extend these base models to support specific types of captchas.

### Error Handling

**2Captcha always returns HTTP 200** for successful or failed tasks. Errors are indicated by a non-zero `errorId` in the JSON response, at which point a 2Captcha-specific exception is raised. Example codes include:

- `ERROR_NO_SLOT_AVAILABLE` (`errorId=2`)
- `ERROR_ZERO_BALANCE` (`errorId=10`)
- `ERROR_CAPTCHA_UNSOLVABLE` (`errorId=12`)
- … and more.

Additionally, **HTTP errors** (e.g., if 2Captcha.com is unreachable or returns `4xx/5xx`) are raised as `HTTPError` subclasses. Here’s how to handle them:

```python
import asyncio
from async_2captcha.client import Async2Captcha
from async_2captcha.errors.http_errors import HTTPError
from async_2captcha.errors.client_errors import TwoCaptchaError

async def example():
    try:
        client = Async2Captcha("API_KEY", http2=True)
        balance = await client.get_balance()
        print("Balance:", balance)
    except HTTPError as http_err:
        print(f"HTTP error occurred: {http_err}")
    except TwoCaptchaError as captcha_err:
        print(f"2Captcha-specific error: {captcha_err}")

asyncio.run(example())
```

---

## Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request for:

- New captcha solver classes (e.g., reCAPTCHA, GeeTest, etc.).
- Bug fixes, performance improvements, or additional features.
- Documentation enhancements.

### Development Setup

1. **Clone** the repository:
   ```bash
   git clone https://github.com/diprog/async-2captcha.git
   ```
2. **Install** dependencies in a virtual environment:
   ```bash
   cd async-2captcha
   python -m venv venv
   source venv/bin/activate
   pip install -r requirements.txt
   ```
3. **Install** project locally in editable mode:
   ```bash
   pip install -e .
   ```

Please follow [PEP 8](https://www.python.org/dev/peps/pep-0008/) style guidelines and ensure all tests pass before submitting a pull request.

---

## License

This project is licensed under the [MIT License](LICENSE).  
© 2025 Dmitry. All rights reserved.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "async-2captcha",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "2captcha, async, captcha-solving, captcha",
    "author": null,
    "author_email": "Dmitry <diprog991@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/94/0a/bc8e86e8c0b18a6409a2ba10893b5dfa3c7a3ac46b9be1b4874708882168/async_2captcha-0.1.3.tar.gz",
    "platform": null,
    "description": "# async-2captcha\r\n\r\n[![PyPI version](https://badge.fury.io/py/async-2captcha.svg)](https://badge.fury.io/py/async-2captcha)\r\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)\r\n\r\n**async-2captcha** is an **asynchronous Python client** for the [2Captcha API](https://2captcha.com/). It provides helper classes for creating and managing captcha-solving tasks, including specialized solvers for Cloudflare Turnstile and image-based captchas (with selectable coordinates). This library is designed to handle common errors gracefully, raising both HTTP exceptions and 2Captcha-specific exceptions when appropriate.\r\n\r\n---\r\n\r\n## Table of Contents\r\n\r\n- [Features](#features)\r\n- [Installation](#installation)\r\n- [Quick Start](#quick-start)\r\n- [Usage Examples](#usage-examples)\r\n  - [Cloudflare Turnstile Captcha](#cloudflare-turnstile-captcha)\r\n  - [Coordinates (Image-Click) Captcha](#coordinates-image-click-captcha)\r\n  - [Retrieving Task Results](#retrieving-task-results)\r\n  - [Checking Account Balance](#checking-account-balance)\r\n- [API Reference](#api-reference)\r\n  - [Async2Captcha Class](#async2captcha-class)\r\n  - [Solvers](#solvers)\r\n    - [TurnstileSolver](#turnstilesolver)\r\n    - [CoordinatesSolver](#coordinatessolver)\r\n    - [Not-Yet-Implemented Solvers](#not-yet-implemented-solvers)\r\n  - [Models](#models)\r\n  - [Error Handling](#error-handling)\r\n- [Contributing](#contributing)\r\n- [License](#license)\r\n\r\n---\r\n\r\n## Features\r\n\r\n- **Asynchronous**: Built on top of [httpx](https://www.python-httpx.org/) and `async/await`, allowing concurrent operations.\r\n- **Multiple Captcha Types**:\r\n  - Cloudflare Turnstile\r\n  - Coordinate-based image captchas (e.g., \u201cclick all apples\u201d)\r\n  - (More solver classes can be added or contributed)\r\n- **Exception Handling**:\r\n  - Raises HTTP errors (`4xx` / `5xx`) if the server\u2019s status code is >= 400.\r\n  - Raises 2Captcha-specific errors (e.g., `ERROR_NO_SLOT_AVAILABLE`, `ERROR_ZERO_BALANCE`, etc.) with clear messages.\r\n- **HTTP/2 Support**:\r\n  - For potentially improved performance, you can enable HTTP/2 by installing `httpx[http2]` and passing `http2=True` when creating the `Async2Captcha` client.\r\n- **Convenient**: Automatically includes your 2Captcha API key in each request and provides high-level methods like `get_balance()`.\r\n\r\n---\r\n\r\n## Installation\r\n\r\nRequires **Python 3.8+**.\r\n\r\n```bash\r\npip install async-2captcha\r\n```\r\n\r\nIf you want **HTTP/2** support (optional), install:\r\n```bash\r\npip install httpx[http2]\r\n```\r\n\r\n---\r\n\r\n## Quick Start\r\n\r\n### 1. Get Your 2Captcha API Key\r\n\r\n1. Sign up or log in to [2Captcha.com](https://2captcha.com/).\r\n2. Navigate to your [account dashboard](https://2captcha.com/setting) to find your **API key**.\r\n\r\n### 2. Instantiate the Client\r\n\r\n```python\r\nimport asyncio\r\n\r\nfrom async_2captcha.client import Async2Captcha\r\n\r\nasync def main():\r\n    api_key = \"YOUR_2CAPTCHA_API_KEY\"\r\n    # Pass http2=True if you installed httpx[http2] and want to enable HTTP/2\r\n    captcha_client = Async2Captcha(api_key, http2=True)\r\n\r\n    balance = await captcha_client.get_balance()\r\n    print(f\"Your 2Captcha balance is: ${balance:.2f}\")\r\n\r\nasyncio.run(main())\r\n```\r\n\r\n---\r\n\r\n## Usage Examples\r\n\r\n### Cloudflare Turnstile Captcha\r\n\r\n**Turnstile** is Cloudflare\u2019s captcha alternative. To solve a Turnstile captcha:\r\n\r\n```python\r\nimport asyncio\r\n\r\nfrom async_2captcha.client import Async2Captcha\r\n\r\nasync def solve_turnstile():\r\n    api_key = \"YOUR_2CAPTCHA_API_KEY\"\r\n    client = Async2Captcha(api_key)\r\n\r\n    # For a normal Turnstile widget (proxyless):\r\n    task_result = await client.turnstile.create_task(\r\n        website_url=\"https://example.com/login\",\r\n        website_key=\"0x4AAAAAAAA...\",\r\n    )\r\n    \r\n    # If the task succeeded, you'll receive a TurnstileTask object with a solution field:\r\n    if task_result.solution:\r\n        print(\"Turnstile token:\", task_result.solution.token)\r\n        print(\"User agent used:\", task_result.solution.user_agent)\r\n    else:\r\n        print(\"No solution found or an error occurred.\")\r\n\r\nasyncio.run(solve_turnstile())\r\n```\r\n\r\n- **Proxy Support**: To use your own proxy, provide a `proxy_url` such as `\"http://user:pass@1.2.3.4:8080\"` or `\"socks5://...\"` to `create_task()`. The solver will automatically switch to a proxy-based task.\r\n\r\n### Coordinates (Image-Click) Captcha\r\n\r\nSome captchas require clicking specific regions of an image. Use the **CoordinatesSolver**:\r\n\r\n```python\r\nimport asyncio\r\nimport base64\r\n\r\nfrom async_2captcha.client import Async2Captcha\r\n\r\nasync def solve_coordinates():\r\n    api_key = \"YOUR_2CAPTCHA_API_KEY\"\r\n    client = Async2Captcha(api_key)\r\n\r\n    # Prepare the image as a base64 string\r\n    with open(\"captcha.jpg\", \"rb\") as f:\r\n        image_data = base64.b64encode(f.read()).decode(\"utf-8\")\r\n\r\n    # Create and wait for the coordinates task\r\n    task_result = await client.coordinates.create_task(\r\n        body=image_data, \r\n        comment=\"Click all the apples in the image.\"\r\n    )\r\n    \r\n    # On success, you'll have a list of (x, y) coordinates\r\n    if task_result.solution:\r\n        print(\"Coordinates:\", task_result.solution.coordinates)\r\n    else:\r\n        print(\"No solution found or an error occurred.\")\r\n\r\nasyncio.run(solve_coordinates())\r\n```\r\n\r\n### Retrieving Task Results\r\n\r\nWhile the included solver classes (`TurnstileSolver`, `CoordinatesSolver`, etc.) automate task creation and waiting, you can also manage tasks directly:\r\n\r\n```python\r\nimport asyncio\r\nfrom async_2captcha.client import Async2Captcha\r\nfrom async_2captcha.enums import TaskType\r\n\r\nasync def create_and_poll_task():\r\n    api_key = \"YOUR_2CAPTCHA_API_KEY\"\r\n    client = Async2Captcha(api_key)\r\n\r\n    # Create a task manually\r\n    running_task = await client.create_task(TaskType.TURNSTILE_PROXYLESS, payload={\r\n        \"websiteURL\": \"https://example.com\",\r\n        \"websiteKey\": \"0x4AAAAAAA...\"\r\n    })\r\n\r\n    # Poll or wait until completed\r\n    task_result = await running_task.wait_until_completed()\r\n    \r\n    if task_result.is_ready():\r\n        print(\"Task is solved!\", task_result.solution)\r\n    else:\r\n        print(\"Task is still processing...\")\r\n\r\nasyncio.run(create_and_poll_task())\r\n```\r\n\r\n### Checking Account Balance\r\n\r\n```python\r\nimport asyncio\r\nfrom async_2captcha.client import Async2Captcha\r\n\r\nasync def check_balance():\r\n    client = Async2Captcha(\"YOUR_2CAPTCHA_API_KEY\")\r\n    balance = await client.get_balance()\r\n    print(f\"2Captcha balance: ${balance}\")\r\n\r\nasyncio.run(check_balance())\r\n```\r\n\r\n---\r\n\r\n## API Reference\r\n\r\n### Async2Captcha Class\r\n\r\nLocated in [`async_2captcha/client.py`](async_2captcha/client.py), the core class:\r\n\r\n- **Parameters**:\r\n  - `api_key` (str): 2Captcha API key.\r\n  - `http2` (bool, optional): If `True`, enables HTTP/2 (requires `pip install httpx[http2]`).\r\n- **Attributes**:\r\n  - `turnstile`: A `TurnstileSolver` instance.\r\n  - `coordinates`: A `CoordinatesSolver` instance.\r\n- **Key Methods**:\r\n  1. `create_task(type: TaskType, payload: Dict[str, Any]) -> RunningTask`\r\n     - Creates a captcha task (low-level method).\r\n  2. `get_task_result(task_id: int) -> Task`\r\n     - Fetches result for an existing task.\r\n  3. `get_balance() -> float`\r\n     - Retrieves account balance.\r\n\r\n### Solvers\r\n\r\n#### TurnstileSolver\r\n\r\n- **TurnstileSolver** (`async_2captcha/solvers/turnstile.py`):\r\n  - `create_task(website_url, website_key, action=None, data=None, pagedata=None, proxy_url=None) -> TurnstileTask`\r\n  - Returns a `TurnstileTask` object with the `solution` containing the Turnstile token.\r\n\r\n#### CoordinatesSolver\r\n\r\n- **CoordinatesSolver** (`async_2captcha/solvers/coordinates.py`):\r\n  - `create_task(body, comment=None, img_instructions=None, min_clicks=None, max_clicks=None) -> CoordinatesTask`\r\n  - Returns a `CoordinatesTask` object, whose `solution` includes a list of clicked coordinates.\r\n\r\n#### Not-Yet-Implemented Solvers\r\n\r\nThe following captcha solvers are currently placeholders (`NotImplementedSolver`). They will raise a `NotImplementedError` if called. Contributions to implement them are welcome.\r\n\r\n**Complex captchas:**\r\n- reCAPTCHA V2 (Proxyless and proxy-based): `recaptcha_v2`\r\n- reCAPTCHA V3 (Proxyless and proxy-based): `recaptcha_v3`\r\n- reCAPTCHA V2 Enterprise (Proxyless and proxy-based): `recaptcha_v2_enterprise`\r\n- reCAPTCHA V3 Enterprise: `recaptcha_v3_enterprise`\r\n- Arkose Labs: `arkose_labs`\r\n- GeeTest: `geetest`\r\n- Capy Puzzle: `capy_puzzle`\r\n- Keycaptcha: `keycaptcha`\r\n- Lemin: `lemin`\r\n- Amazon CAPTCHA: `amazon_captcha`\r\n- Cybersiara CAPTCHA: `cybersiara`\r\n- MtCaptcha: `mt_captcha`\r\n- CutCaptcha: `cutcaptcha`\r\n- Friendly CAPTCHA: `friendly_captcha`\r\n- Datadome CAPTCHA: `datadome_captcha`\r\n- ATB CAPTCHA: `atb_captcha`\r\n- Tencent CAPTCHA: `tencent`\r\n- Prosopo CAPTCHA: `prosopo_procaptcha`\r\n\r\n**Simple captchas:**\r\n- Normal image-based captchas: `normal_captcha`\r\n- Text-based captchas: `text_captcha`\r\n- Rotational captchas: `rotate`\r\n- Grid-based captchas: `grid`\r\n- Object-drawing captchas: `draw_around`\r\n- Bounding box captchas: `bounding_box`\r\n- Audio captchas: `audio_captcha`\r\n\r\n---\r\n\r\n### Models\r\n\r\nThe project uses **Pydantic models** to structure data responses from the 2Captcha API. These models are defined across various files within the `async_2captcha/models/` directory. Notable models include:\r\n\r\n- **`Task`** (`models/task.py`):\r\n  - Represents the response from the 2Captcha API for captcha tasks, including status, solution, or error details.\r\n  - Methods:\r\n    - `is_ready()`: Returns `True` if the task is completed and ready.\r\n    - `is_processing()`: Returns `True` if the task is still being processed.\r\n\r\n- **`TurnstileTask`** (`solvers/turnstile.py`):\r\n  - Inherits from the `Task` model and includes Turnstile-specific solutions such as tokens and user agents.\r\n\r\n- **`CoordinatesTask`** (`solvers/coordinates.py`):\r\n  - Inherits from the `Task` model and includes the list of (x, y) coordinates selected in image-based captchas.\r\n\r\n- **Base Models**:\r\n  - **`CamelCaseModel`** (`models/base.py`): A base model used for converting fields between camelCase (used by 2Captcha) and snake_case (used internally).\r\n\r\nThese models ensure consistency and validation of API responses. When creating new solvers, you can extend these base models to support specific types of captchas.\r\n\r\n### Error Handling\r\n\r\n**2Captcha always returns HTTP 200** for successful or failed tasks. Errors are indicated by a non-zero `errorId` in the JSON response, at which point a 2Captcha-specific exception is raised. Example codes include:\r\n\r\n- `ERROR_NO_SLOT_AVAILABLE` (`errorId=2`)\r\n- `ERROR_ZERO_BALANCE` (`errorId=10`)\r\n- `ERROR_CAPTCHA_UNSOLVABLE` (`errorId=12`)\r\n- \u2026 and more.\r\n\r\nAdditionally, **HTTP errors** (e.g., if 2Captcha.com is unreachable or returns `4xx/5xx`) are raised as `HTTPError` subclasses. Here\u2019s how to handle them:\r\n\r\n```python\r\nimport asyncio\r\nfrom async_2captcha.client import Async2Captcha\r\nfrom async_2captcha.errors.http_errors import HTTPError\r\nfrom async_2captcha.errors.client_errors import TwoCaptchaError\r\n\r\nasync def example():\r\n    try:\r\n        client = Async2Captcha(\"API_KEY\", http2=True)\r\n        balance = await client.get_balance()\r\n        print(\"Balance:\", balance)\r\n    except HTTPError as http_err:\r\n        print(f\"HTTP error occurred: {http_err}\")\r\n    except TwoCaptchaError as captcha_err:\r\n        print(f\"2Captcha-specific error: {captcha_err}\")\r\n\r\nasyncio.run(example())\r\n```\r\n\r\n---\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Feel free to open an issue or submit a pull request for:\r\n\r\n- New captcha solver classes (e.g., reCAPTCHA, GeeTest, etc.).\r\n- Bug fixes, performance improvements, or additional features.\r\n- Documentation enhancements.\r\n\r\n### Development Setup\r\n\r\n1. **Clone** the repository:\r\n   ```bash\r\n   git clone https://github.com/diprog/async-2captcha.git\r\n   ```\r\n2. **Install** dependencies in a virtual environment:\r\n   ```bash\r\n   cd async-2captcha\r\n   python -m venv venv\r\n   source venv/bin/activate\r\n   pip install -r requirements.txt\r\n   ```\r\n3. **Install** project locally in editable mode:\r\n   ```bash\r\n   pip install -e .\r\n   ```\r\n\r\nPlease follow [PEP 8](https://www.python.org/dev/peps/pep-0008/) style guidelines and ensure all tests pass before submitting a pull request.\r\n\r\n---\r\n\r\n## License\r\n\r\nThis project is licensed under the [MIT License](LICENSE).  \r\n&copy; 2025 Dmitry. All rights reserved.\r\n",
    "bugtrack_url": null,
    "license": "MIT License\r\n        \r\n        Copyright (c) 2025 Dmitry\r\n        \r\n        Permission is hereby granted, free of charge, to any person obtaining a copy\r\n        of this software and associated documentation files (the \"Software\"), to deal\r\n        in the Software without restriction, including without limitation the rights\r\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n        copies of the Software, and to permit persons to whom the Software is\r\n        furnished to do so, subject to the following conditions:\r\n        \r\n        The above copyright notice and this permission notice shall be included in all\r\n        copies or substantial portions of the Software.\r\n        \r\n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n        SOFTWARE.\r\n        ",
    "summary": "An asynchronous Python client for the 2Captcha API.",
    "version": "0.1.3",
    "project_urls": {
        "Homepage": "https://github.com/diprog/async-2captcha",
        "Issue Tracker": "https://github.com/diprog/async-2captcha/issues",
        "Repository": "https://github.com/diprog/async-2captcha",
        "Telegram": "https://t.me/groowo"
    },
    "split_keywords": [
        "2captcha",
        " async",
        " captcha-solving",
        " captcha"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "7d6d9e55900f10943c346feaa54de19e96120f5118f419f599d850128450d825",
                "md5": "9dd1d0016e31743228e693fd2f57f81f",
                "sha256": "d030b255d4e09e2ccbe1193071f192d204d7ceb148789305b72bf34fed03d8f5"
            },
            "downloads": -1,
            "filename": "async_2captcha-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9dd1d0016e31743228e693fd2f57f81f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 23134,
            "upload_time": "2025-02-11T21:54:36",
            "upload_time_iso_8601": "2025-02-11T21:54:36.138151Z",
            "url": "https://files.pythonhosted.org/packages/7d/6d/9e55900f10943c346feaa54de19e96120f5118f419f599d850128450d825/async_2captcha-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "940abc8e86e8c0b18a6409a2ba10893b5dfa3c7a3ac46b9be1b4874708882168",
                "md5": "43b23612ab8689dece8ef341229a3a4f",
                "sha256": "62361dd82c3ce5bc10a9a5218cb91038482a0524e74feb365ed915b60dcadbc0"
            },
            "downloads": -1,
            "filename": "async_2captcha-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "43b23612ab8689dece8ef341229a3a4f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 22759,
            "upload_time": "2025-02-11T21:54:38",
            "upload_time_iso_8601": "2025-02-11T21:54:38.165222Z",
            "url": "https://files.pythonhosted.org/packages/94/0a/bc8e86e8c0b18a6409a2ba10893b5dfa3c7a3ac46b9be1b4874708882168/async_2captcha-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-11 21:54:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "diprog",
    "github_project": "async-2captcha",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "async-2captcha"
}
        
Elapsed time: 1.20023s