# 2captcha/2captcha-python architecture

> Architecture diagram of the GitHub repository 2captcha/2captcha-python, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/2captcha/2captcha-python
- Repository: https://github.com/2captcha/2captcha-python

## Overview

This is a Python client library for submitting CAPTCHA-solving tasks to 2Captcha and returning answers to application code. Developers configure either the synchronous or asynchronous solver, call a CAPTCHA-specific method or use the lower-level submission/result methods, and the client sends requests to the service. The README documents many CAPTCHA types, callback behavior, balance checks, and reporting. The graph groups CAPTCHA-specific wrappers by purpose; unsampled method details and some internal control flow are not inferred.

Main entry points: [`twocaptcha/solver.py`](https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/solver.py) (Sync solver), [`twocaptcha/async_solver.py`](https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/async_solver.py) (Async solver), [`twocaptcha/api.py`](https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/api.py) (Sync API client), [`twocaptcha/async_api.py`](https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/async_api.py) (Async API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Solver clients"]
  node_sync["Sync solver<br/>[solver.py]"]
  node_async["Async solver<br/>[async_solver.py]"]
end

subgraph group_capabilities["CAPTCHA capabilities"]
  node_sync_wrappers["Sync CAPTCHA methods<br/>[solver.py]"]
  node_async_wrappers["Async CAPTCHA methods<br/>[async_solver.py]"]
end

subgraph group_transport["API transport"]
  node_sync_api["Sync API client<br/>[api.py]"]
  node_async_api["Async API client<br/>[async_api.py]"]
end

subgraph group_errors["Errors"]
  node_solver_errors["Solver errors<br/>[solver.py]"]
  node_api_errors["API errors<br/>[api.py]"]
end

node_developer(("Application developer"))
node_service{{"2Captcha API"}}

node_developer -->|"configures and calls"| node_sync
node_developer -->|"configures and calls"| node_async
node_sync_wrappers -->|"invoke solve"| node_sync
node_async_wrappers -->|"invoke solve"| node_async
node_sync -->|"submits and polls"| node_sync_api
node_async -->|"submits and polls"| node_async_api
node_sync_api -->|"HTTP requests"| node_service
node_async_api -->|"HTTP requests"| node_service
node_sync -->|"raises"| node_solver_errors
node_async -->|"raises"| node_solver_errors
node_sync_api -->|"raises"| node_api_errors
node_async_api -->|"raises"| node_api_errors

click node_sync "https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/solver.py"
click node_async "https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/async_solver.py"
click node_sync_wrappers "https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/solver.py"
click node_async_wrappers "https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/async_solver.py"
click node_sync_api "https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/api.py"
click node_async_api "https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/async_api.py"
click node_solver_errors "https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/exceptions/solver.py"
click node_api_errors "https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/exceptions/api.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sync,node_async toneBlue
class node_sync_wrappers,node_async_wrappers toneAmber
class node_sync_api,node_async_api,node_service toneMint
class node_solver_errors,node_api_errors toneRose
class node_developer toneIndigo
```

## Components

### Solver clients

- [Sync solver](https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/solver.py): `twocaptcha/solver.py`
- [Async solver](https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/async_solver.py): `twocaptcha/async_solver.py`

### CAPTCHA capabilities

- [Sync CAPTCHA methods](https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/solver.py): `twocaptcha/solver.py`
- [Async CAPTCHA methods](https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/async_solver.py): `twocaptcha/async_solver.py`

### API transport

- [Sync API client](https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/api.py): `twocaptcha/api.py`
- [Async API client](https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/async_api.py): `twocaptcha/async_api.py`

### Errors

- [Solver errors](https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/exceptions/solver.py): `twocaptcha/exceptions/solver.py`
- [API errors](https://github.com/2captcha/2captcha-python/blob/master/twocaptcha/exceptions/api.py): `twocaptcha/exceptions/api.py`

### Other components

- **Application developer**
- **2Captcha API**

## Connections

- Application developer → Sync solver: configures and calls (evidence: `README.md`)
- Application developer → Async solver: configures and calls (evidence: `README.md`)
- Sync CAPTCHA methods → Sync solver: invoke solve (evidence: `twocaptcha/solver.py`)
- Async CAPTCHA methods → Async solver: invoke solve (evidence: `twocaptcha/async_solver.py`)
- Sync solver → Sync API client: submits and polls (evidence: `twocaptcha/solver.py`)
- Async solver → Async API client: submits and polls (evidence: `twocaptcha/async_solver.py`)
- Sync API client → 2Captcha API: HTTP requests (evidence: `twocaptcha/api.py`)
- Async API client → 2Captcha API: HTTP requests (evidence: `twocaptcha/async_api.py`)
- Sync solver → Solver errors: raises (evidence: `twocaptcha/solver.py`)
- Async solver → Solver errors: raises (evidence: `twocaptcha/async_solver.py`)
- Sync API client → API errors: raises (evidence: `twocaptcha/api.py`)
- Async API client → API errors: raises (evidence: `twocaptcha/async_api.py`)
