capsolver-core 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- capsolver_core/__init__.py +44 -0
- capsolver_core/__main__.py +99 -0
- capsolver_core/browser/__init__.py +6 -0
- capsolver_core/browser/adapter.py +116 -0
- capsolver_core/browser/driver.py +26 -0
- capsolver_core/browser/inject/__init__.py +1 -0
- capsolver_core/browser/inject/cloudflare.py +67 -0
- capsolver_core/browser/inject/recaptcha.py +162 -0
- capsolver_core/capsolver.py +206 -0
- capsolver_core/captcha/__init__.py +20 -0
- capsolver_core/captcha/handler.py +55 -0
- capsolver_core/captcha/handlers/__init__.py +20 -0
- capsolver_core/captcha/handlers/cloudflare.py +83 -0
- capsolver_core/captcha/handlers/recaptcha.py +106 -0
- capsolver_core/captcha/handlers/support.py +30 -0
- capsolver_core/captcha/registry.py +56 -0
- capsolver_core/captcha/types.py +60 -0
- capsolver_core/core/__init__.py +7 -0
- capsolver_core/core/client.py +163 -0
- capsolver_core/core/errors.py +55 -0
- capsolver_core/core/http.py +137 -0
- capsolver_core/core/tasks.py +134 -0
- capsolver_core/core/types.py +157 -0
- capsolver_core/py.typed +0 -0
- capsolver_core-0.1.0.dist-info/METADATA +206 -0
- capsolver_core-0.1.0.dist-info/RECORD +29 -0
- capsolver_core-0.1.0.dist-info/WHEEL +4 -0
- capsolver_core-0.1.0.dist-info/entry_points.txt +2 -0
- capsolver_core-0.1.0.dist-info/licenses/LICENSE +15 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: capsolver-core
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: CapSolver core library — detect captchas, solve via API, and autofill tokens. Powers capsolver-agent and capsolver-mcp.
|
|
5
|
+
Project-URL: Homepage, https://capsolver.com
|
|
6
|
+
Project-URL: Repository, https://github.com/capsolver-ai/capsolver-core
|
|
7
|
+
Project-URL: Issues, https://github.com/capsolver-ai/capsolver-core/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/capsolver-ai/capsolver-core/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Security, https://github.com/capsolver-ai/capsolver-core/blob/main/SECURITY.md
|
|
10
|
+
Author-email: capsolver-ai <dev@capsolver.ai>
|
|
11
|
+
License-Expression: ISC
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: capsolver,captcha,recaptcha,turnstile
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Requires-Dist: httpx>=0.27
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest-asyncio>=1.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
32
|
+
Provides-Extra: playwright
|
|
33
|
+
Requires-Dist: playwright>=1.40; extra == 'playwright'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# capsolver-core
|
|
37
|
+
|
|
38
|
+
A Python SDK for [CapSolver](https://capsolver.com) — detect captchas on a page, read their parameters, solve them via the CapSolver API, and write the token back.
|
|
39
|
+
|
|
40
|
+
> **Token mode only.** This SDK solves captchas by requesting a token from the
|
|
41
|
+
> CapSolver API (reCAPTCHA v2/v3, Cloudflare Turnstile).
|
|
42
|
+
|
|
43
|
+
## Install
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install capsolver-core
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
With Playwright support:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install capsolver-core[playwright]
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Set your API key (or pass `api_key=` directly to `create_capsolver()`):
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# bash / zsh
|
|
59
|
+
export CAPSOLVER_API_KEY="your-capsolver-api-key"
|
|
60
|
+
|
|
61
|
+
# PowerShell
|
|
62
|
+
$env:CAPSOLVER_API_KEY = "your-capsolver-api-key"
|
|
63
|
+
|
|
64
|
+
# cmd
|
|
65
|
+
set CAPSOLVER_API_KEY=your-capsolver-api-key
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Two ways to use it
|
|
69
|
+
|
|
70
|
+
### 1. Pure API (you already have the sitekey)
|
|
71
|
+
|
|
72
|
+
No browser needed — give it the captcha parameters, get a token back.
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
import asyncio
|
|
76
|
+
from capsolver_core import create_capsolver, CaptchaType, CaptchaInfo
|
|
77
|
+
|
|
78
|
+
async def main():
|
|
79
|
+
cap = create_capsolver(api_key="YOUR_API_KEY")
|
|
80
|
+
|
|
81
|
+
info = CaptchaInfo(
|
|
82
|
+
type=CaptchaType.RECAPTCHA_V2,
|
|
83
|
+
website_url="https://example.com",
|
|
84
|
+
website_key="6Lc...",
|
|
85
|
+
)
|
|
86
|
+
solution = await cap.solve(info)
|
|
87
|
+
print(solution.token) # submit this as g-recaptcha-response
|
|
88
|
+
|
|
89
|
+
asyncio.run(main())
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 2. Driving a real browser (Playwright)
|
|
93
|
+
|
|
94
|
+
Detect, read params, solve, and autofill — all from a live page.
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
import asyncio
|
|
98
|
+
from capsolver_core import create_capsolver
|
|
99
|
+
from playwright.async_api import async_playwright
|
|
100
|
+
|
|
101
|
+
async def main():
|
|
102
|
+
cap = create_capsolver(api_key="YOUR_API_KEY")
|
|
103
|
+
|
|
104
|
+
async with async_playwright() as p:
|
|
105
|
+
browser = await p.chromium.launch()
|
|
106
|
+
page = await browser.new_page()
|
|
107
|
+
await page.goto("https://example.com/login")
|
|
108
|
+
|
|
109
|
+
# One-shot: detect every captcha, solve each, write tokens back.
|
|
110
|
+
results = await cap.solve_on_page(page)
|
|
111
|
+
for r in results:
|
|
112
|
+
print(r.info.type, r.solution.token if r.solution else None, r.filled, r.error)
|
|
113
|
+
|
|
114
|
+
# …or step by step:
|
|
115
|
+
types = await cap.detect(page)
|
|
116
|
+
infos = await cap.get_captcha_info(page)
|
|
117
|
+
solution = await cap.solve(infos[0])
|
|
118
|
+
|
|
119
|
+
asyncio.run(main())
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## CLI
|
|
123
|
+
|
|
124
|
+
The `capsolver` command provides quick diagnostics without writing code.
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# Show SDK version, Python version, and optional dependency status
|
|
128
|
+
capsolver info
|
|
129
|
+
|
|
130
|
+
# List all supported captcha types and registered handlers
|
|
131
|
+
capsolver list-types
|
|
132
|
+
|
|
133
|
+
# Check account balance (requires CAPSOLVER_API_KEY)
|
|
134
|
+
capsolver balance
|
|
135
|
+
capsolver balance --api-key YOUR_KEY
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Also works via `python -m capsolver_core info`.
|
|
139
|
+
|
|
140
|
+
## API
|
|
141
|
+
|
|
142
|
+
### `create_capsolver(**options)` / `Capsolver(**options)`
|
|
143
|
+
|
|
144
|
+
| Option | Default | Description |
|
|
145
|
+
|---------------------|-----------------------------|----------------------------------------|
|
|
146
|
+
| `api_key` | — | CapSolver client key (required to solve)|
|
|
147
|
+
| `service` | `https://api.capsolver.com` | API base URL |
|
|
148
|
+
| `default_timeout` | `120` | Polling budget, seconds |
|
|
149
|
+
| `polling_interval` | `5` | Delay between result polls, seconds |
|
|
150
|
+
| `request_timeout_ms`| `30000` | Per-HTTP-request timeout |
|
|
151
|
+
| `app_id` | — | Developer/affiliate id |
|
|
152
|
+
| `handlers` | all built-ins | Override the registered captcha handlers|
|
|
153
|
+
| `source` | — | Traffic source identifier |
|
|
154
|
+
| `version` | — | Client version tag |
|
|
155
|
+
| `on_error` | — | Callback for non-fatal errors |
|
|
156
|
+
|
|
157
|
+
### Resource cleanup
|
|
158
|
+
|
|
159
|
+
`Capsolver` holds an internal HTTP connection pool. Use it as an async context
|
|
160
|
+
manager to ensure connections are released:
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
async with create_capsolver(api_key="YOUR_API_KEY") as cap:
|
|
164
|
+
solution = await cap.solve(info)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Or call `await cap.aclose()` explicitly when done.
|
|
168
|
+
|
|
169
|
+
### Methods
|
|
170
|
+
|
|
171
|
+
- `solve(info, wait_options?)` → `Solution` — solve from a `CaptchaInfo`.
|
|
172
|
+
- `detect(page)` → `list[CaptchaType]` — which captchas are present.
|
|
173
|
+
- `get_captcha_info(page)` → `list[CaptchaInfo]` — structured params per widget.
|
|
174
|
+
- `solve_on_page(page, options?)` → `list[SolveOnPageResult]` — detect → solve → autofill.
|
|
175
|
+
- `get_balance()` → `BalanceResp` — account balance.
|
|
176
|
+
- `register(handler)` / `get_supported_captchas()` / `get_handler(key)` — registry access.
|
|
177
|
+
|
|
178
|
+
### Supported captchas
|
|
179
|
+
|
|
180
|
+
`reCaptchaV2`, `reCaptchaV3` (incl. enterprise), `cloudflare` (Turnstile).
|
|
181
|
+
|
|
182
|
+
## Architecture
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
src/capsolver_core/
|
|
186
|
+
__init__.py public API surface (all exports)
|
|
187
|
+
__main__.py CLI entry point (capsolver command)
|
|
188
|
+
core/ pure-Python token solving (http, client, task builders, types)
|
|
189
|
+
captcha/ handler registry + per-captcha handlers (the plugin layer)
|
|
190
|
+
browser/ PageDriver adapter + self-contained in-page inject scripts
|
|
191
|
+
capsolver.py public Capsolver class
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Development
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
git clone https://github.com/capsolver-ai/capsolver-core.git
|
|
198
|
+
cd capsolver-core
|
|
199
|
+
uv sync --all-extras # or: pip install -r requirements-dev.txt
|
|
200
|
+
uv run pytest # run tests
|
|
201
|
+
uv run ruff check src tests # lint
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
ISC
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
capsolver_core/__init__.py,sha256=bRdcXGG5y3bzjpEFzNm3T4heGJ3XKT1WxwN9352pXVw,1358
|
|
2
|
+
capsolver_core/__main__.py,sha256=HpnpZt7spPhm0cUZgScoy_djv5fZRN8n5ZZhvxnBYBg,3072
|
|
3
|
+
capsolver_core/capsolver.py,sha256=ifXehaqUm6XTwcZ5T-lJcnrqnKRZZ40THAb126joNn0,8352
|
|
4
|
+
capsolver_core/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
capsolver_core/browser/__init__.py,sha256=Vx4_ndHmBX0Z68lQ1X_G1sYeErEUIfivTiM1XktQTV0,265
|
|
6
|
+
capsolver_core/browser/adapter.py,sha256=ucpTcAdKg-ZiBRS2wTWrh8cOKd4KBcY0L0bS_WoUAvw,3925
|
|
7
|
+
capsolver_core/browser/driver.py,sha256=5l-2IcWIF7bKqLRMaBGez-aE_5WPq6Nmr6qIUP9PDrw,814
|
|
8
|
+
capsolver_core/browser/inject/__init__.py,sha256=Bf3ksjy92HoAJecrSFFEdif7fBGqiWKfahnlYUplOfs,81
|
|
9
|
+
capsolver_core/browser/inject/cloudflare.py,sha256=a2wlkt9VaVH48aHac3dtbhnitdxE2KWatAxPl_IIvjw,2806
|
|
10
|
+
capsolver_core/browser/inject/recaptcha.py,sha256=oRQ7Wjfj2dWqYwz2lxIYop-ID2sw9ViKvqsEBrsRJ2E,6061
|
|
11
|
+
capsolver_core/captcha/__init__.py,sha256=tTiQhsIkssTiLId4MnNSaxdaTI3bAYU5V07s3LLIQBo,556
|
|
12
|
+
capsolver_core/captcha/handler.py,sha256=zW_hmlgUREnuRiEtdHvBYwwATgK2mg3esKBVdLQud6A,1736
|
|
13
|
+
capsolver_core/captcha/registry.py,sha256=5cU23cgk8AUyoXiq8UT6HQmf8EXCXFtf860VvzR1wEI,1931
|
|
14
|
+
capsolver_core/captcha/types.py,sha256=3C6vy1iueJUnlvYegKtW74ViVOmmVQ5Dhmtu9mSGGQM,1629
|
|
15
|
+
capsolver_core/captcha/handlers/__init__.py,sha256=hs-awJIR8Mq3sXBitIPl4y7llBfYgiiPmFF7X9Q2oFw,535
|
|
16
|
+
capsolver_core/captcha/handlers/cloudflare.py,sha256=J8PBMZ_-1xbpcYLmaQNxdoipHqy6p-j6EpQ71QENigk,2829
|
|
17
|
+
capsolver_core/captcha/handlers/recaptcha.py,sha256=vxBou6e9n4DqQCIvOWKGdN9YTVFgZZlf57GAnjgFz9Y,3982
|
|
18
|
+
capsolver_core/captcha/handlers/support.py,sha256=PJzO3khKoCVOOwWYtpOIJ3N1-KDn5LftlZEjgEBwBrE,1245
|
|
19
|
+
capsolver_core/core/__init__.py,sha256=1lxePQ9VpqBIY4cLHDb20HRJKfww3QkUmSHbkbAUZAE,369
|
|
20
|
+
capsolver_core/core/client.py,sha256=9u3m1NHBWV3s50mfTnfBmpUp0ziS_GB86vruI5fE_GU,6715
|
|
21
|
+
capsolver_core/core/errors.py,sha256=G5OsC9h4KRx5QmYcrpgtSRGHgreB402oqQ1bbPo4iok,1781
|
|
22
|
+
capsolver_core/core/http.py,sha256=qj74X6vJFyJwZ8c3Hifa0Zk0TZa5NN6eilAJ1HjAM70,4825
|
|
23
|
+
capsolver_core/core/tasks.py,sha256=U_j65mU1TArFdZTk8AoyE4BoudC5qtbfN21kQP9Ixs8,3913
|
|
24
|
+
capsolver_core/core/types.py,sha256=vQXJ007NHTmIkBftMozoim42MSLMMPQL1yjbTFmYmvI,5161
|
|
25
|
+
capsolver_core-0.1.0.dist-info/METADATA,sha256=iPSpxmdhj3whSpQ2_3G6tNFeNnSLWGhX26VvTBIo3Vk,7050
|
|
26
|
+
capsolver_core-0.1.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
27
|
+
capsolver_core-0.1.0.dist-info/entry_points.txt,sha256=PNa5F9JsxuueV6T5vJpVxDrfr9oBZ4m2YftSqotKLk4,59
|
|
28
|
+
capsolver_core-0.1.0.dist-info/licenses/LICENSE,sha256=p65mlslnCknoxoEoP3lESj40mUaZRt2xzgMlrGE72hM,763
|
|
29
|
+
capsolver_core-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 capsolver-ai
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|