|
1 | | -# 🤖 Capmonster Python |
| 1 | +# Capmonster Python |
2 | 2 |
|
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | -&cacheSeconds=3600) |
| 3 | +[](https://pypi.org/project/capmonster-python/) |
| 4 | +[](https://github.com/alperensert/capmonster_python/releases) |
| 5 | +[](https://github.com/alperensert/capmonster_python/commits/master) |
| 6 | +[&cacheSeconds=3600)](https://github.com/alperensert/capmonster_python) |
8 | 7 |
|
9 | | -A modern, strongly typed, async-friendly Python SDK for solving CAPTCHA challenges |
10 | | -using [Capmonster.Cloud](https://capmonster.cloud/). |
| 8 | +A modern, strongly-typed Python SDK for [CapMonster Cloud](https://capmonster.cloud/) — solve reCAPTCHA, Turnstile, GeeTest, and 20+ other CAPTCHA types with both sync and async support. |
11 | 9 |
|
12 | | -Supports reCAPTCHA v2 & v3, Cloudflare Turnstile, GeeTest (v3 & v4) and [much more](#-supported-captcha-types). |
| 10 | +## Installation |
13 | 11 |
|
14 | | ---- |
15 | | - |
16 | | -## ✨ Features |
| 12 | +```bash |
| 13 | +pip install capmonster_python |
| 14 | +``` |
17 | 15 |
|
18 | | -- ✅ Fully typed Pydantic v2 models |
19 | | -- 🔁 Both sync and async API support |
20 | | -- 🔐 Proxy and User-Agent configuration |
21 | | -- 📦 Supports the most common CAPTCHA types |
22 | | -- 📚 Intuitive API with powerful task building |
| 16 | +> [!IMPORTANT] |
| 17 | +> This is **v4** of Capmonster Python, which includes breaking changes from v3.x. |
| 18 | +> For the legacy API: `pip install capmonster_python==3.2` |
23 | 19 |
|
24 | | ---- |
| 20 | +## Quick Start |
25 | 21 |
|
26 | | -## 🔧 Installation |
| 22 | +```python |
| 23 | +from capmonster_python import CapmonsterClient, RecaptchaV2Task |
27 | 24 |
|
28 | | -```bash |
29 | | -pip install capmonster_python |
30 | | -``` |
| 25 | +client = CapmonsterClient(api_key="YOUR_API_KEY") |
31 | 26 |
|
32 | | -> [!IMPORTANT] |
33 | | -> You're viewing the documentation for **Capmonster Python v4**, which includes breaking changes. If you prefer the |
34 | | -> old syntax used in versions prior to 4.x, you can continue using it by installing the legacy version: |
35 | | -> ```pip install capmonster_python==3.2``` |
| 27 | +task = RecaptchaV2Task( |
| 28 | + websiteURL="https://example.com", |
| 29 | + websiteKey="SITE_KEY_HERE" |
| 30 | +) |
36 | 31 |
|
37 | | -## 🚀 Quick Start |
| 32 | +result = client.solve(task) |
| 33 | +print(result) # {"gRecaptchaResponse": "03AGdBq24..."} |
| 34 | +``` |
38 | 35 |
|
39 | | -### Async Example |
| 36 | +### Async |
40 | 37 |
|
41 | 38 | ```python |
42 | 39 | import asyncio |
43 | 40 | from capmonster_python import CapmonsterClient, RecaptchaV3Task |
44 | 41 |
|
45 | | - |
46 | 42 | async def main(): |
47 | | - client = CapmonsterClient(api_key="YOUR_API_KEY") |
48 | | - |
49 | | - task = RecaptchaV3Task( |
50 | | - websiteURL="https://example.com", |
51 | | - websiteKey="SITE_KEY_HERE", |
52 | | - minScore=0.5, |
53 | | - pageAction="verify" |
54 | | - ) |
55 | | - |
56 | | - task_id = await client.create_task_async(task) |
57 | | - result = await client.join_task_result_async(task_id) |
58 | | - print(result) |
59 | | - |
| 43 | + async with CapmonsterClient(api_key="YOUR_API_KEY") as client: |
| 44 | + task = RecaptchaV3Task( |
| 45 | + websiteURL="https://example.com", |
| 46 | + websiteKey="SITE_KEY_HERE", |
| 47 | + minScore=0.5, |
| 48 | + pageAction="verify" |
| 49 | + ) |
| 50 | + result = await client.solve_async(task) |
| 51 | + print(result) |
60 | 52 |
|
61 | 53 | asyncio.run(main()) |
62 | | - |
63 | 54 | ``` |
64 | 55 |
|
65 | | -### Sync Example |
| 56 | +### With Proxy |
66 | 57 |
|
67 | 58 | ```python |
68 | | -from capmonster_python import CapmonsterClient, RecaptchaV2Task |
| 59 | +from capmonster_python import CapmonsterClient, RecaptchaV2Task, ProxyPayload |
69 | 60 |
|
70 | | -client = CapmonsterClient(api_key="<YOUR_API_KEY>") |
| 61 | +client = CapmonsterClient(api_key="YOUR_API_KEY") |
71 | 62 |
|
72 | 63 | task = RecaptchaV2Task( |
73 | 64 | websiteURL="https://example.com", |
74 | | - websiteKey="SITE_KEY_HERE" |
| 65 | + websiteKey="SITE_KEY_HERE", |
| 66 | + proxy=ProxyPayload( |
| 67 | + proxyType="http", |
| 68 | + proxyAddress="1.2.3.4", |
| 69 | + proxyPort=8080, |
| 70 | + proxyLogin="user", |
| 71 | + proxyPassword="pass" |
| 72 | + ) |
75 | 73 | ) |
76 | 74 |
|
77 | | -task_id = client.create_task(task) |
78 | | -result = client.join_task_result(task_id) |
79 | | -print(result) |
| 75 | +result = client.solve(task) |
| 76 | +``` |
| 77 | + |
| 78 | +## Client API |
| 79 | + |
| 80 | +```python |
| 81 | +CapmonsterClient(api_key, timeout=30.0, max_retries=120, retry_delay=2.0) |
80 | 82 | ``` |
81 | 83 |
|
82 | | ---- |
| 84 | +| Method | Description | |
| 85 | +|--------|-------------| |
| 86 | +| `solve(task)` | Create task and poll until solved | |
| 87 | +| `create_task(task)` | Create a task, returns `task_id` | |
| 88 | +| `join_task_result(task_id)` | Poll until result is ready | |
| 89 | +| `get_task_result(task_id)` | Single poll (no waiting) | |
| 90 | +| `get_balance()` | Get account balance | |
| 91 | +| `get_user_agent()` | Get current valid User-Agent string | |
| 92 | +| `report_incorrect_image(task_id)` | Report bad image captcha solution | |
| 93 | +| `report_incorrect_token(task_id)` | Report bad token captcha solution | |
| 94 | + |
| 95 | +All methods have async variants with the `_async` suffix (e.g. `solve_async`, `get_balance_async`). |
| 96 | + |
| 97 | +Both sync and async context managers are supported for proper connection cleanup. |
| 98 | + |
| 99 | +## Supported CAPTCHA Types |
83 | 100 |
|
84 | | -## 🧠 Supported CAPTCHA Types |
| 101 | +### reCAPTCHA |
85 | 102 |
|
86 | | -Capmonster Python v4 supports a wide range of CAPTCHA formats — from mainstream challenges like reCAPTCHA and Turnstile |
87 | | -to enterprise-grade shields like Imperva and DataDome. Each task supports full Pydantic validation ✅ and both sync and |
88 | | -async clients 🔄 unless noted. |
| 103 | +| CAPTCHA Type | Class | Proxy | |
| 104 | +|---|---|---| |
| 105 | +| reCAPTCHA v2 | `RecaptchaV2Task` | Optional | |
| 106 | +| reCAPTCHA v2 Enterprise | `RecaptchaV2EnterpriseTask` | Optional | |
| 107 | +| reCAPTCHA v3 | `RecaptchaV3Task` | No | |
| 108 | +| reCAPTCHA v3 Enterprise | `RecaptchaV3EnterpriseTask` | No | |
| 109 | +| reCAPTCHA Click | `RecaptchaClickTask` | Optional | |
89 | 110 |
|
90 | | -| 🔖 Category | CAPTCHA Type | Class Name | Proxy Required | Notes | |
91 | | -|---------------------------|--------------------------------|-------------------------------|----------------|----------------------------------------| |
92 | | -| 🧩 reCAPTCHA | reCAPTCHA v2 | `RecaptchaV2Task` | Optional | Visible / Invisible supported ✅ 🔄 | |
93 | | -| | reCAPTCHA v2 Enterprise | `RecaptchaV2EnterpriseTask` | Optional | `enterprisePayload` & `apiDomain` ✅ 🔄 | |
94 | | -| | reCAPTCHA v3 | `RecaptchaV3Task` | ❌ No | Score-based, proxyless ✅ 🔄 | |
95 | | -| 🛡️ Cloudflare | Turnstile (token) | `TurnstileTask` | ❌ No | Lightweight, async-ready ✅ 🔄 | |
96 | | -| | Turnstile (cf_clearance) | `TurnstileCloudFlareTask` | ✅ Yes | Full HTML + proxy required ✅ 🔄 | |
97 | | -| 📸 Image-based | Image-to-Text OCR | `ImageToTextTask` | ❌ No | Base64 image + module control ✅ 🔄 | |
98 | | -| | Complex Image (Recaptcha-like) | `ComplexImageRecaptchaTask` | ❌ No | Grid-based, metadata aware ✅ 🔄 | |
99 | | -| | Complex Image Recognition (AI) | `ComplexImageRecognitionTask` | ❌ No | Supports tasks like Shein, OOCL ✅ 🔄 | |
100 | | -| 🧠 Human Behavior | GeeTest v3 | `GeeTestV3Task` | Optional | Challenge + `gt` key + freshness ✅ 🔄 | |
101 | | -| | GeeTest v4 | `GeeTestV4Task` | Optional | `initParameters` supported ✅ 🔄 | |
102 | | -| 🛡️ Enterprise Protection | DataDome | `DataDomeTask` | ✅ Recommended | Cookie & page context needed ✅ 🔄 | |
103 | | -| | Imperva | `ImpervaTask` | ✅ Recommended | Incapsula + Reese84 logic ✅ 🔄 | |
104 | | -| 🏦 Platform-Specific | Binance Login | `BinanceTask` | ✅ Yes | `validateId` for login flow ✅ 🔄 | |
105 | | -| | Temu | `TemuTask` | ❌ No | Cookie-injected behavioral solver ✅ 🔄 | |
106 | | -| | TenDI | `TenDITask` | ✅ Yes | Custom captchaAppId field ✅ 🔄 | |
107 | | -| 🧪 Miscellaneous | Prosopo | `ProsopoTask` | Optional | Used in zk or crypto UIs ✅ 🔄 | |
108 | | -| | Basilisk | `BasiliskTask` | ❌ No | Minimalist site-key puzzle ✅ 🔄 | |
| 111 | +### Cloudflare |
109 | 112 |
|
110 | | -## 🧩 Advanced Usage |
| 113 | +| CAPTCHA Type | Class | Proxy | |
| 114 | +|---|---|---| |
| 115 | +| Turnstile | `TurnstileTask` | No | |
| 116 | +| Turnstile Challenge (cf_clearance) | `TurnstileCloudFlareTask` | Required | |
| 117 | +| Turnstile Waiting Room | `TurnstileWaitingRoomTask` | Required | |
| 118 | + |
| 119 | +### Image-Based |
| 120 | + |
| 121 | +| CAPTCHA Type | Class | Proxy | |
| 122 | +|---|---|---| |
| 123 | +| Image-to-Text OCR | `ImageToTextTask` | No | |
| 124 | +| Complex Image (reCAPTCHA grid) | `ComplexImageRecaptchaTask` | No | |
| 125 | +| Complex Image Recognition | `ComplexImageRecognitionTask` | No | |
| 126 | + |
| 127 | +### Behavioral / Interactive |
| 128 | + |
| 129 | +| CAPTCHA Type | Class | Proxy | |
| 130 | +|---|---|---| |
| 131 | +| GeeTest v3 | `GeeTestV3Task` | Optional | |
| 132 | +| GeeTest v4 | `GeeTestV4Task` | Optional | |
| 133 | +| FunCaptcha (Arkose Labs) | `FunCaptchaTask` | Optional | |
| 134 | +| Hunt | `HuntTask` | Optional | |
| 135 | + |
| 136 | +### Enterprise Protection |
| 137 | + |
| 138 | +| CAPTCHA Type | Class | Proxy | |
| 139 | +|---|---|---| |
| 140 | +| DataDome | `DataDomeTask` | Required | |
| 141 | +| Imperva (Incapsula) | `ImpervaTask` | Required | |
| 142 | +| Amazon WAF | `AmazonTask` | Optional | |
| 143 | +| TSPD | `TSPDTask` | Optional | |
| 144 | + |
| 145 | +### Platform-Specific |
| 146 | + |
| 147 | +| CAPTCHA Type | Class | Proxy | |
| 148 | +|---|---|---| |
| 149 | +| Binance | `BinanceTask` | Required | |
| 150 | +| Temu | `TemuTask` | No | |
| 151 | +| TenDI | `TenDITask` | Required | |
| 152 | + |
| 153 | +### Other |
| 154 | + |
| 155 | +| CAPTCHA Type | Class | Proxy | |
| 156 | +|---|---|---| |
| 157 | +| Altcha | `AltchaTask` | No | |
| 158 | +| Basilisk | `BasiliskTask` | No | |
| 159 | +| Castle | `CastleTask` | No | |
| 160 | +| MTCaptcha | `MTCaptchaTask` | Optional | |
| 161 | +| Prosopo | `ProsopoTask` | Optional | |
| 162 | +| Yidun | `YidunTask` | Optional | |
| 163 | + |
| 164 | +> Don't see your captcha type? Use `VanillaTaskPayload` to build custom task payloads without waiting for an SDK update. |
| 165 | +
|
| 166 | +## Advanced Usage |
| 167 | + |
| 168 | +### Callback URLs |
| 169 | + |
| 170 | +```python |
| 171 | +result = client.solve(task, callback_url="https://yoursite.com/callback") |
| 172 | +``` |
| 173 | + |
| 174 | +### Report Incorrect Solutions |
| 175 | + |
| 176 | +```python |
| 177 | +task_id = client.create_task(task) |
| 178 | +result = client.join_task_result(task_id) |
| 179 | + |
| 180 | +# If the token was rejected by the target site: |
| 181 | +client.report_incorrect_token(task_id) |
| 182 | +``` |
| 183 | + |
| 184 | +### Fresh Token Generation |
| 185 | + |
| 186 | +Use `nocache=True` on reCAPTCHA tasks to prevent cached token reuse: |
| 187 | + |
| 188 | +```python |
| 189 | +task = RecaptchaV2Task( |
| 190 | + websiteURL="https://example.com", |
| 191 | + websiteKey="SITE_KEY_HERE", |
| 192 | + nocache=True |
| 193 | +) |
| 194 | +``` |
111 | 195 |
|
112 | | -- Callback URLs are supported during task creation. |
113 | | -- Includes auto-retry loop for polling results (up to 120s) |
| 196 | +## Documentation |
114 | 197 |
|
115 | | -## 💬 Community & Support |
| 198 | +Full API reference available at [alperensert.github.io/capmonster_python](https://alperensert.github.io/capmonster_python/). |
116 | 199 |
|
117 | | -Need help or have a question? |
| 200 | +## Support |
118 | 201 |
|
119 | | -- 📧 Contact: business@alperen.io |
120 | | -- 🐛 Found a bug? [Open an issue](https://github.com/alperensert/capmonster_python/issues) |
| 202 | +- Found a bug? [Open an issue](https://github.com/alperensert/capmonster_python/issues) |
| 203 | +- Contact: business@alperen.io |
121 | 204 |
|
122 | | -> [!NOTE] |
123 | | -> Community support is intended only for questions and issues related to this project. Custom usage scenarios, |
124 | | -> integrations, or application-specific logic are outside the scope of support. |
| 205 | +> [!NOTE] |
| 206 | +> Support is limited to questions and issues related to this project. Custom integrations and application-specific logic are outside the scope of support. |
125 | 207 |
|
126 | | -## 📄 License |
| 208 | +## License |
127 | 209 |
|
128 | | -This project is licensed under the [MIT License](/LICENSE). |
| 210 | +[MIT License](/LICENSE) |
0 commit comments