Metadata-Version: 2.4
Name: capbypass-sdk
Version: 1.0.14
Summary: Official Python SDK for CapBypass CAPTCHA solving API
Author-email: CapBypass Development <dev@capbypass.dev>
License: MIT
Project-URL: Homepage, https://capbypass.dev
Project-URL: Documentation, https://capbypass.dev/docs/sdks/python
Project-URL: Repository, https://github.com/CapBypass-Development/capbypass-sdk-python
Project-URL: Bug Tracker, https://github.com/CapBypass-Development/capbypass-sdk-python/issues
Keywords: captcha,recaptcha,aws-waf,automation,solver
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Internet :: WWW/HTTP
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.31.0
Provides-Extra: dev
Requires-Dist: pytest>=7.4.0; extra == "dev"
Requires-Dist: pytest-mock>=3.11.0; extra == "dev"
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
Requires-Dist: responses>=0.23.0; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Requires-Dist: mypy>=1.5.0; extra == "dev"
Requires-Dist: types-requests>=2.31.0; extra == "dev"
Dynamic: license-file

# CapBypass Python SDK

[![PyPI version](https://img.shields.io/pypi/v/capbypass-sdk.svg)](https://pypi.org/project/capbypass-sdk/)
[![Python versions](https://img.shields.io/pypi/pyversions/capbypass-sdk.svg)](https://pypi.org/project/capbypass-sdk/)
[![Downloads](https://pepy.tech/badge/capbypass-sdk)](https://pepy.tech/project/capbypass-sdk)
[![GitHub stars](https://img.shields.io/github/stars/CapBypass-Development/capbypass-sdk-python.svg)](https://github.com/CapBypass-Development/capbypass-sdk-python)

Official Python SDK for the [CapBypass](https://capbypass.pro) CAPTCHA solving API.

## Features

- ✨ Simple `solve()` method with auto-polling (first poll after 1 s, then every 1-3 s)
- 🎯 Advanced `createTask()` + `getTaskResult()` for granular control
- 💰 `getBalance()` to check account balance
- 🔄 Automatic retry logic for network failures
- 🛡️ Comprehensive error handling
- 📝 Type hints for better IDE support
- 🧪 100% test coverage

## Supported CAPTCHA Types

- reCAPTCHA v2 (normal & invisible)
- reCAPTCHA v3
- reCAPTCHA v3 Enterprise
- AWS WAF CAPTCHA
- Cloudflare Turnstile

## Installation

```bash
pip install capbypass-sdk
```

## Quick Start

```python
from capbypass import CapBypass

# Initialize client
client = CapBypass(api_key="your-api-key")
# Or use environment variable: export CAPBYPASS_API_KEY="your-key"

# Solve CAPTCHA (auto-polling)
solution = client.solve({
    "type": "ReCaptchaV2TaskProxyLess",
    "websiteURL": "https://example.com",
    "websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-"
})

print(solution["gRecaptchaResponse"])
```

## Advanced Usage

### Granular Control

```python
# Create task
task_id = client.createTask({
    "type": "ReCaptchaV2TaskProxyLess",
    "websiteURL": "https://example.com",
    "websiteKey": "site-key"
})

# Poll for result. getTaskResult does not wait by itself: wait 1 second after
# createTask, then 1 to 3 seconds between calls (not faster), until the task is
# ready or failed, and give up after your own deadline.
import time
deadline = time.monotonic() + 120
time.sleep(1)
while True:
    result = client.getTaskResult(task_id)
    if result["status"] == "ready":
        print(result["solution"])
        break
    if result["status"] == "failed":
        raise RuntimeError(result.get("errorDescription", "Task failed"))
    if time.monotonic() > deadline:
        raise TimeoutError("Task not ready in time")
    time.sleep(2)
```

### Check Balance

```python
balance = client.getBalance()
print(f"Balance: ${balance:.4f}")
```

### Cloudflare Turnstile

`websiteURL` and `websiteKey` are required. `action` (1 to 32 characters of `A-Z a-z 0-9 _ -`) and `cData` (1 to 255 characters of the same set) are optional and replace the page's `data-action` / `data-cdata`. The solution holds `token` (the `cf-turnstile-response` value) and `timing.solveMs`; Turnstile returns no `userAgent`.

```python
solution = client.solve({
    "type": "TurnstileTaskProxyLess",
    "websiteURL": "https://example.com/login",
    "websiteKey": "0x4AAAAAAAxxxxxxxxxxxxxx",
})
token = solution["token"]
```

With your own proxy (`TurnstileTask` requires one): a single `http(s)` URL in the `proxy` field, no `socks`:

```python
solution = client.solve({
    "type": "TurnstileTask",
    "websiteURL": "https://example.com/login",
    "websiteKey": "0x4AAAAAAAxxxxxxxxxxxxxx",
    "action": "login",
    "cData": "session-42",
    "proxy": "http://user:pass@host:port",
})
```

### With Proxy

Every task type with a proxy (the non-ProxyLess variants) takes it as one string in the `proxy` field. The SDK sends it unchanged; the API validates it when the task is created, before anything is billed. Supported protocols: `http`, `https`, `socks4`, `socks5` (`http` when omitted). Some task types accept `http(s)` proxies only, as their page says (Turnstile and Cloudflare, for example).

| Form | Pattern |
|------|---------|
| URL | `protocol://user:pass@host:port` |
| Colon | `host:port:user:pass` or `host:port` |
| Protocol + colon | `protocol:host:port:user:pass` or `protocol:host:port` |

Send only the proxy itself: no spaces or other text (a whole line copied from a proxy list is refused), a port from 1 to 65535, and percent-encode any `@`, `/`, `:`, `#` or `?` in the user or password of the URL form. The host must be public. A malformed proxy is refused with `ERROR_PROXY_FORMAT` (`ValidationError`) and an internal or reserved address with `ERROR_BLOCKED_TARGET` (`ValidationError`). See [Proxy Format](https://capbypass.pro/docs/api-reference#proxy-format) in the API reference.

```python
solution = client.solve({
    "type": "ReCaptchaV2Task",
    "websiteURL": "https://example.com",
    "websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
    "proxy": "http://username:password@proxy.example.com:8080",
})
```

### Error Handling

```python
from capbypass import CapBypass
from capbypass.errors import (
    AuthenticationError,
    InsufficientBalanceError,
    TimeoutError,
)

try:
    solution = client.solve(task)
except AuthenticationError:
    print("Invalid API key")
except InsufficientBalanceError:
    print("Insufficient balance")
except TimeoutError:
    print("Task timed out")
```

## Documentation

### 📚 Core Documentation
- [Quick Start Guide](https://github.com/CapBypass-Development/capbypass-sdks/blob/main/docs/quickstart/python.md)
- [Complete API Reference](https://github.com/CapBypass-Development/capbypass-sdks/blob/main/docs/api-reference/python-sdk.md)
- [Full SDK Documentation](https://capbypass.pro/docs/sdks/python)

### 🔧 Advanced Guides
- [Proxy Configuration](https://github.com/CapBypass-Development/capbypass-sdks/blob/main/docs/guides/proxy-configuration.md) — HTTP, HTTPS, SOCKS5 proxy support with rotation strategies
- [Error Handling](https://github.com/CapBypass-Development/capbypass-sdks/blob/main/docs/guides/error-handling.md) — Retry strategies, circuit breakers, production alerting
- [Performance Optimization](https://github.com/CapBypass-Development/capbypass-sdks/blob/main/docs/guides/performance-optimization.md) — Concurrent solving, connection pooling, token caching
- [Production Deployment](https://github.com/CapBypass-Development/capbypass-sdks/blob/main/docs/guides/production-deployment.md) — Kubernetes, AWS Lambda, monitoring, security

### 🔄 Migration
- [Migrating from Capsolver](https://github.com/CapBypass-Development/capbypass-sdks/blob/main/docs/migration/from-capsolver.md) — 100% API compatible, drop-in replacement

## Examples

### Basic Examples
See [examples/](examples/) directory for complete runnable examples:

- [recaptcha_v2.py](examples/recaptcha_v2.py) - reCAPTCHA v2 solving
- [recaptcha_v3.py](examples/recaptcha_v3.py) - reCAPTCHA v3 solving
- [aws_waf.py](examples/aws_waf.py) - AWS WAF CAPTCHA solving
- [turnstile.py](examples/turnstile.py) - Cloudflare Turnstile solving

### Advanced Examples
Full integration examples in the [documentation](https://github.com/CapBypass-Development/capbypass-sdks/tree/main/docs/examples):
- E-commerce checkout automation
- Social media automation
- Web scraping with CAPTCHA handling
- Microservice integration patterns

## Development

```bash
# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run linter
ruff check .

# Run type checker
mypy src/
```

## License

MIT

## Support

- [Website](https://capbypass.pro)
- [Documentation](https://capbypass.pro/docs/sdks/python)
- [Dashboard / Sign up](https://capbypass.pro/signup)
- [Pricing](https://capbypass.pro/pricing)
- [Discord](https://discord.gg/8WJsPKCGXN)
- Issues: https://github.com/CapBypass-Development/capbypass-sdk-python/issues
