capsolver-core 0.1.0__tar.gz
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-0.1.0/.gitignore +44 -0
- capsolver_core-0.1.0/CHANGELOG.md +18 -0
- capsolver_core-0.1.0/CONTRIBUTING.md +39 -0
- capsolver_core-0.1.0/LICENSE +15 -0
- capsolver_core-0.1.0/PKG-INFO +206 -0
- capsolver_core-0.1.0/PUBLISHING.md +108 -0
- capsolver_core-0.1.0/README.md +171 -0
- capsolver_core-0.1.0/SECURITY.md +30 -0
- capsolver_core-0.1.0/SUPPORT.md +24 -0
- capsolver_core-0.1.0/pyproject.toml +64 -0
- capsolver_core-0.1.0/requirements-dev.txt +17 -0
- capsolver_core-0.1.0/requirements.txt +4 -0
- capsolver_core-0.1.0/src/capsolver_core/__init__.py +44 -0
- capsolver_core-0.1.0/src/capsolver_core/__main__.py +99 -0
- capsolver_core-0.1.0/src/capsolver_core/browser/__init__.py +6 -0
- capsolver_core-0.1.0/src/capsolver_core/browser/adapter.py +116 -0
- capsolver_core-0.1.0/src/capsolver_core/browser/driver.py +26 -0
- capsolver_core-0.1.0/src/capsolver_core/browser/inject/__init__.py +1 -0
- capsolver_core-0.1.0/src/capsolver_core/browser/inject/cloudflare.py +67 -0
- capsolver_core-0.1.0/src/capsolver_core/browser/inject/recaptcha.py +162 -0
- capsolver_core-0.1.0/src/capsolver_core/capsolver.py +206 -0
- capsolver_core-0.1.0/src/capsolver_core/captcha/__init__.py +20 -0
- capsolver_core-0.1.0/src/capsolver_core/captcha/handler.py +55 -0
- capsolver_core-0.1.0/src/capsolver_core/captcha/handlers/__init__.py +20 -0
- capsolver_core-0.1.0/src/capsolver_core/captcha/handlers/cloudflare.py +83 -0
- capsolver_core-0.1.0/src/capsolver_core/captcha/handlers/recaptcha.py +106 -0
- capsolver_core-0.1.0/src/capsolver_core/captcha/handlers/support.py +30 -0
- capsolver_core-0.1.0/src/capsolver_core/captcha/registry.py +56 -0
- capsolver_core-0.1.0/src/capsolver_core/captcha/types.py +60 -0
- capsolver_core-0.1.0/src/capsolver_core/core/__init__.py +7 -0
- capsolver_core-0.1.0/src/capsolver_core/core/client.py +163 -0
- capsolver_core-0.1.0/src/capsolver_core/core/errors.py +55 -0
- capsolver_core-0.1.0/src/capsolver_core/core/http.py +137 -0
- capsolver_core-0.1.0/src/capsolver_core/core/tasks.py +134 -0
- capsolver_core-0.1.0/src/capsolver_core/core/types.py +157 -0
- capsolver_core-0.1.0/src/capsolver_core/py.typed +0 -0
- capsolver_core-0.1.0/tests/__init__.py +0 -0
- capsolver_core-0.1.0/tests/fixtures/cloudflare.html +17 -0
- capsolver_core-0.1.0/tests/fixtures/recaptcha_v2.html +40 -0
- capsolver_core-0.1.0/tests/fixtures/recaptcha_v3.html +37 -0
- capsolver_core-0.1.0/tests/test_browser.py +163 -0
- capsolver_core-0.1.0/tests/test_client.py +64 -0
- capsolver_core-0.1.0/tests/test_core.py +419 -0
- capsolver_core-0.1.0/tests/test_integration_browser.py +294 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Byte-compiled / optimized
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
|
|
7
|
+
# Distribution
|
|
8
|
+
dist/
|
|
9
|
+
build/
|
|
10
|
+
*.egg-info/
|
|
11
|
+
*.egg
|
|
12
|
+
*.whl
|
|
13
|
+
|
|
14
|
+
# Virtual environments
|
|
15
|
+
.venv/
|
|
16
|
+
venv/
|
|
17
|
+
env/
|
|
18
|
+
|
|
19
|
+
# IDE
|
|
20
|
+
.idea/
|
|
21
|
+
.vscode/
|
|
22
|
+
.cursor/
|
|
23
|
+
*.swp
|
|
24
|
+
*.swo
|
|
25
|
+
|
|
26
|
+
# Testing
|
|
27
|
+
.pytest_cache/
|
|
28
|
+
.coverage
|
|
29
|
+
htmlcov/
|
|
30
|
+
.mypy_cache/
|
|
31
|
+
.ruff_cache/
|
|
32
|
+
.dmypy.json
|
|
33
|
+
|
|
34
|
+
# Environment
|
|
35
|
+
.env
|
|
36
|
+
.env.local
|
|
37
|
+
.python-version
|
|
38
|
+
|
|
39
|
+
# Logs
|
|
40
|
+
*.log
|
|
41
|
+
|
|
42
|
+
# OS
|
|
43
|
+
.DS_Store
|
|
44
|
+
Thumbs.db
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
This project follows semantic versioning where practical. Public releases are
|
|
6
|
+
tagged in Git as `vX.Y.Z` and published to PyPI with the same version.
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-09-01
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Initial public release of `capsolver-core`.
|
|
13
|
+
- Async CapSolver client for creating tasks, polling results, and checking
|
|
14
|
+
account balance.
|
|
15
|
+
- Captcha detection and token autofill helpers for Playwright pages.
|
|
16
|
+
- Built-in support for reCAPTCHA v2, reCAPTCHA v3, and Cloudflare Turnstile.
|
|
17
|
+
- `capsolver` CLI for local diagnostics.
|
|
18
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in `capsolver-core`.
|
|
4
|
+
|
|
5
|
+
This repository is maintained by the CapSolver team. Issues and pull requests
|
|
6
|
+
are welcome when they are focused on bugs, documentation, compatibility, or
|
|
7
|
+
small improvements to the public SDK surface.
|
|
8
|
+
|
|
9
|
+
## Before You Start
|
|
10
|
+
|
|
11
|
+
- Search existing issues before opening a new one.
|
|
12
|
+
- Open an issue before starting a large change.
|
|
13
|
+
- Do not include real API keys, cookies, private URLs, or customer data in
|
|
14
|
+
issues, tests, examples, or screenshots.
|
|
15
|
+
- Keep examples token-mode focused and use placeholder credentials.
|
|
16
|
+
|
|
17
|
+
## Development
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
uv sync --all-extras
|
|
21
|
+
uv run pytest
|
|
22
|
+
uv run ruff check src tests
|
|
23
|
+
uv run mypy src
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
If you do not use `uv`, install the development dependencies from
|
|
27
|
+
`requirements-dev.txt` and run the equivalent commands with Python.
|
|
28
|
+
|
|
29
|
+
## Pull Requests
|
|
30
|
+
|
|
31
|
+
Pull requests should include:
|
|
32
|
+
|
|
33
|
+
- A clear description of the change.
|
|
34
|
+
- Tests or a short explanation of why tests are not needed.
|
|
35
|
+
- Documentation updates for user-facing behavior.
|
|
36
|
+
|
|
37
|
+
Maintainers may close changes that are outside the public SDK scope or require
|
|
38
|
+
private service-side details.
|
|
39
|
+
|
|
@@ -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.
|
|
@@ -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,108 @@
|
|
|
1
|
+
# Publishing
|
|
2
|
+
|
|
3
|
+
Release target: `capsolver-core` version `0.1.0`, prepared for public release on
|
|
4
|
+
2026-09-01.
|
|
5
|
+
|
|
6
|
+
This checklist is for maintainers syncing the prepared public files to the
|
|
7
|
+
official open-source repository, testing the package on TestPyPI, and then
|
|
8
|
+
publishing the final package to PyPI.
|
|
9
|
+
|
|
10
|
+
## Preconditions
|
|
11
|
+
|
|
12
|
+
- The source is the prepared public copy, not a private development checkout.
|
|
13
|
+
- `pyproject.toml` has `version = "0.1.0"`.
|
|
14
|
+
- `CHANGELOG.md` has `## [0.1.0] - 2026-09-01`.
|
|
15
|
+
- `README.md`, `LICENSE`, `SECURITY.md`, `CONTRIBUTING.md`, and `SUPPORT.md`
|
|
16
|
+
are present.
|
|
17
|
+
- Documentation examples use placeholder credentials only.
|
|
18
|
+
- The tree does not contain `.git`, `.venv`, `uv.lock`, caches, local path
|
|
19
|
+
overrides, real API keys, browser profiles, or private service data.
|
|
20
|
+
|
|
21
|
+
## Sync to the Official Open-Source Repository
|
|
22
|
+
|
|
23
|
+
Copy this directory into the official `capsolver-core` public repository working
|
|
24
|
+
tree, then review the diff before committing.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
git status
|
|
28
|
+
git diff
|
|
29
|
+
git add .
|
|
30
|
+
git commit -m "Release v0.1.0"
|
|
31
|
+
git status
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Do not tag until the build, TestPyPI upload, and install test have passed.
|
|
35
|
+
|
|
36
|
+
## Verify Locally
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
uv sync --all-extras
|
|
40
|
+
uv run pytest
|
|
41
|
+
uv run ruff check src tests
|
|
42
|
+
uv run mypy src
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Build and Check
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
python -m pip install --upgrade build twine
|
|
49
|
+
python -m build
|
|
50
|
+
python -m twine check dist/*
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Inspect the source distribution and wheel before upload. Confirm that no
|
|
54
|
+
private files, local paths, secrets, browser profiles, caches, or test output
|
|
55
|
+
are included.
|
|
56
|
+
|
|
57
|
+
## TestPyPI Test Release
|
|
58
|
+
|
|
59
|
+
Upload the exact distribution files to TestPyPI first.
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
python -m twine upload --repository testpypi dist/*
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Install from TestPyPI in a clean environment and smoke-test the CLI import path.
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ capsolver-core==0.1.0
|
|
69
|
+
python -c "import capsolver_core; print(capsolver_core.__version__)"
|
|
70
|
+
capsolver --help
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
PyPI and TestPyPI distributions cannot be overwritten. If the test upload is
|
|
74
|
+
wrong, fix the issue and publish a new version.
|
|
75
|
+
|
|
76
|
+
## Formal PyPI Release
|
|
77
|
+
|
|
78
|
+
After TestPyPI passes, upload the same checked distribution files to PyPI.
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
python -m twine upload dist/*
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Then verify installation from PyPI.
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
python -m pip install capsolver-core==0.1.0
|
|
88
|
+
python -c "import capsolver_core; print(capsolver_core.__version__)"
|
|
89
|
+
capsolver --help
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Tag and GitHub Release
|
|
93
|
+
|
|
94
|
+
When the PyPI release is verified, create the release tag and push it from the
|
|
95
|
+
official public repository.
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
git tag v0.1.0
|
|
99
|
+
git push origin main
|
|
100
|
+
git push origin v0.1.0
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Create a GitHub Release for `v0.1.0` using the `CHANGELOG.md` entry.
|
|
104
|
+
|
|
105
|
+
Prefer PyPI Trusted Publishing from the official public GitHub repository for
|
|
106
|
+
future releases. If manual upload is used, use a project-scoped PyPI API token
|
|
107
|
+
instead of an account password.
|
|
108
|
+
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# capsolver-core
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
> **Token mode only.** This SDK solves captchas by requesting a token from the
|
|
6
|
+
> CapSolver API (reCAPTCHA v2/v3, Cloudflare Turnstile).
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pip install capsolver-core
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
With Playwright support:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install capsolver-core[playwright]
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Set your API key (or pass `api_key=` directly to `create_capsolver()`):
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# bash / zsh
|
|
24
|
+
export CAPSOLVER_API_KEY="your-capsolver-api-key"
|
|
25
|
+
|
|
26
|
+
# PowerShell
|
|
27
|
+
$env:CAPSOLVER_API_KEY = "your-capsolver-api-key"
|
|
28
|
+
|
|
29
|
+
# cmd
|
|
30
|
+
set CAPSOLVER_API_KEY=your-capsolver-api-key
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Two ways to use it
|
|
34
|
+
|
|
35
|
+
### 1. Pure API (you already have the sitekey)
|
|
36
|
+
|
|
37
|
+
No browser needed — give it the captcha parameters, get a token back.
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
import asyncio
|
|
41
|
+
from capsolver_core import create_capsolver, CaptchaType, CaptchaInfo
|
|
42
|
+
|
|
43
|
+
async def main():
|
|
44
|
+
cap = create_capsolver(api_key="YOUR_API_KEY")
|
|
45
|
+
|
|
46
|
+
info = CaptchaInfo(
|
|
47
|
+
type=CaptchaType.RECAPTCHA_V2,
|
|
48
|
+
website_url="https://example.com",
|
|
49
|
+
website_key="6Lc...",
|
|
50
|
+
)
|
|
51
|
+
solution = await cap.solve(info)
|
|
52
|
+
print(solution.token) # submit this as g-recaptcha-response
|
|
53
|
+
|
|
54
|
+
asyncio.run(main())
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 2. Driving a real browser (Playwright)
|
|
58
|
+
|
|
59
|
+
Detect, read params, solve, and autofill — all from a live page.
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import asyncio
|
|
63
|
+
from capsolver_core import create_capsolver
|
|
64
|
+
from playwright.async_api import async_playwright
|
|
65
|
+
|
|
66
|
+
async def main():
|
|
67
|
+
cap = create_capsolver(api_key="YOUR_API_KEY")
|
|
68
|
+
|
|
69
|
+
async with async_playwright() as p:
|
|
70
|
+
browser = await p.chromium.launch()
|
|
71
|
+
page = await browser.new_page()
|
|
72
|
+
await page.goto("https://example.com/login")
|
|
73
|
+
|
|
74
|
+
# One-shot: detect every captcha, solve each, write tokens back.
|
|
75
|
+
results = await cap.solve_on_page(page)
|
|
76
|
+
for r in results:
|
|
77
|
+
print(r.info.type, r.solution.token if r.solution else None, r.filled, r.error)
|
|
78
|
+
|
|
79
|
+
# …or step by step:
|
|
80
|
+
types = await cap.detect(page)
|
|
81
|
+
infos = await cap.get_captcha_info(page)
|
|
82
|
+
solution = await cap.solve(infos[0])
|
|
83
|
+
|
|
84
|
+
asyncio.run(main())
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## CLI
|
|
88
|
+
|
|
89
|
+
The `capsolver` command provides quick diagnostics without writing code.
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# Show SDK version, Python version, and optional dependency status
|
|
93
|
+
capsolver info
|
|
94
|
+
|
|
95
|
+
# List all supported captcha types and registered handlers
|
|
96
|
+
capsolver list-types
|
|
97
|
+
|
|
98
|
+
# Check account balance (requires CAPSOLVER_API_KEY)
|
|
99
|
+
capsolver balance
|
|
100
|
+
capsolver balance --api-key YOUR_KEY
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Also works via `python -m capsolver_core info`.
|
|
104
|
+
|
|
105
|
+
## API
|
|
106
|
+
|
|
107
|
+
### `create_capsolver(**options)` / `Capsolver(**options)`
|
|
108
|
+
|
|
109
|
+
| Option | Default | Description |
|
|
110
|
+
|---------------------|-----------------------------|----------------------------------------|
|
|
111
|
+
| `api_key` | — | CapSolver client key (required to solve)|
|
|
112
|
+
| `service` | `https://api.capsolver.com` | API base URL |
|
|
113
|
+
| `default_timeout` | `120` | Polling budget, seconds |
|
|
114
|
+
| `polling_interval` | `5` | Delay between result polls, seconds |
|
|
115
|
+
| `request_timeout_ms`| `30000` | Per-HTTP-request timeout |
|
|
116
|
+
| `app_id` | — | Developer/affiliate id |
|
|
117
|
+
| `handlers` | all built-ins | Override the registered captcha handlers|
|
|
118
|
+
| `source` | — | Traffic source identifier |
|
|
119
|
+
| `version` | — | Client version tag |
|
|
120
|
+
| `on_error` | — | Callback for non-fatal errors |
|
|
121
|
+
|
|
122
|
+
### Resource cleanup
|
|
123
|
+
|
|
124
|
+
`Capsolver` holds an internal HTTP connection pool. Use it as an async context
|
|
125
|
+
manager to ensure connections are released:
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
async with create_capsolver(api_key="YOUR_API_KEY") as cap:
|
|
129
|
+
solution = await cap.solve(info)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Or call `await cap.aclose()` explicitly when done.
|
|
133
|
+
|
|
134
|
+
### Methods
|
|
135
|
+
|
|
136
|
+
- `solve(info, wait_options?)` → `Solution` — solve from a `CaptchaInfo`.
|
|
137
|
+
- `detect(page)` → `list[CaptchaType]` — which captchas are present.
|
|
138
|
+
- `get_captcha_info(page)` → `list[CaptchaInfo]` — structured params per widget.
|
|
139
|
+
- `solve_on_page(page, options?)` → `list[SolveOnPageResult]` — detect → solve → autofill.
|
|
140
|
+
- `get_balance()` → `BalanceResp` — account balance.
|
|
141
|
+
- `register(handler)` / `get_supported_captchas()` / `get_handler(key)` — registry access.
|
|
142
|
+
|
|
143
|
+
### Supported captchas
|
|
144
|
+
|
|
145
|
+
`reCaptchaV2`, `reCaptchaV3` (incl. enterprise), `cloudflare` (Turnstile).
|
|
146
|
+
|
|
147
|
+
## Architecture
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
src/capsolver_core/
|
|
151
|
+
__init__.py public API surface (all exports)
|
|
152
|
+
__main__.py CLI entry point (capsolver command)
|
|
153
|
+
core/ pure-Python token solving (http, client, task builders, types)
|
|
154
|
+
captcha/ handler registry + per-captcha handlers (the plugin layer)
|
|
155
|
+
browser/ PageDriver adapter + self-contained in-page inject scripts
|
|
156
|
+
capsolver.py public Capsolver class
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Development
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
git clone https://github.com/capsolver-ai/capsolver-core.git
|
|
163
|
+
cd capsolver-core
|
|
164
|
+
uv sync --all-extras # or: pip install -r requirements-dev.txt
|
|
165
|
+
uv run pytest # run tests
|
|
166
|
+
uv run ruff check src tests # lint
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## License
|
|
170
|
+
|
|
171
|
+
ISC
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
Security fixes are provided for the latest public release line.
|
|
6
|
+
|
|
7
|
+
| Version | Supported |
|
|
8
|
+
| ------- | --------- |
|
|
9
|
+
| 0.1.x | Yes |
|
|
10
|
+
|
|
11
|
+
## Reporting a Vulnerability
|
|
12
|
+
|
|
13
|
+
Please do not open public issues for vulnerabilities, leaked credentials, or
|
|
14
|
+
reports that include private target URLs, API keys, or customer data.
|
|
15
|
+
|
|
16
|
+
Report security issues by emailing `dev@capsolver.ai` with:
|
|
17
|
+
|
|
18
|
+
- The affected package and version.
|
|
19
|
+
- A concise description of the issue.
|
|
20
|
+
- Reproduction steps or a minimal proof of concept.
|
|
21
|
+
- The impact you believe the issue has.
|
|
22
|
+
|
|
23
|
+
We will acknowledge valid reports as soon as possible and coordinate a fix or
|
|
24
|
+
mitigation before public disclosure.
|
|
25
|
+
|
|
26
|
+
## Handling API Keys
|
|
27
|
+
|
|
28
|
+
Never commit real `CAPSOLVER_API_KEY` values, browser profiles, cookies, or
|
|
29
|
+
captured tokens. Documentation examples must use placeholder values only.
|
|
30
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Support
|
|
2
|
+
|
|
3
|
+
Use the right channel for the type of help you need.
|
|
4
|
+
|
|
5
|
+
## Package Bugs and Documentation
|
|
6
|
+
|
|
7
|
+
Open a GitHub issue for:
|
|
8
|
+
|
|
9
|
+
- Installation problems.
|
|
10
|
+
- Runtime errors in this package.
|
|
11
|
+
- Documentation mistakes.
|
|
12
|
+
- Compatibility issues with supported Python versions or Playwright.
|
|
13
|
+
|
|
14
|
+
Include the package version, Python version, operating system, and a minimal
|
|
15
|
+
reproduction when possible.
|
|
16
|
+
|
|
17
|
+
## CapSolver Account or API Service Issues
|
|
18
|
+
|
|
19
|
+
For account access, billing, API key, balance, or service availability issues,
|
|
20
|
+
use the support options available from `https://capsolver.com`.
|
|
21
|
+
|
|
22
|
+
Do not post API keys, account identifiers, cookies, browser profiles, or target
|
|
23
|
+
site credentials in public issues.
|
|
24
|
+
|