Official Python client for GhostCaptcha API — sync/async captcha solving
Project description
GhostCaptcha Client
Official Python client for the GhostCaptcha API
GhostCaptcha Client, hCaptca çözüm API'si için yazılmış, production-grade Python kütüphanesidir. Senkron ve asenkron istemci, bağlantı havuzu, otomatik yeniden deneme, ve kapsamlı hata yönetimi sunar.
Features
- Dual Client — Sync (
GhostCaptchaClient) + Async (AsyncGhostCaptchaClient) - Connection Pooling — Single httpx connection pool, auto cleanup
- Rate Limit Auto-Retry — 429 hatasında
Retry-Afterbaşlığını okuyup bekler - Proxy Support — HTTP/HTTPS proxy,
set_proxy()ile canlı değiştirme - Debug Mode —
enable_debug()ile detaylı request/response loglama - Device Registration — HWID/MAC/CPU toplama (Windows/Linux/Mac)
- TypedDict Responses — IDE otocomplete ile tip güvenli yanıtlar
- YesCaptcha Compatible —
createTask,getTaskResult,getBalance
Installation
pip install ghostcaptcha-client
Requires Python 3.9+ and httpx.
Quick Start
from ghostcaptcha_client import GhostCaptchaClient
client = GhostCaptchaClient("hcap-xxx...")
print(client.get_balance())
client.close()
import asyncio
from ghostcaptcha_client import AsyncGhostCaptchaClient
async def main():
async with AsyncGhostCaptchaClient("hcap-xxx...") as client:
print(await client.get_balance())
asyncio.run(main())
API Reference
Constructor Options
| Parameter | Default | Description |
|---|---|---|
api_key |
— | Your API key (hcap-...) |
base_url |
production | API base URL (can also set GHOSTCAPTCHA_API_URL env) |
verify_ssl |
True |
SSL certificate verification |
timeout |
60 |
Request timeout in seconds |
auto_register |
False |
Auto-register device info on init |
proxy |
None |
Proxy URL (e.g. http://user:pass@host:8080) |
Configuration
client = GhostCaptchaClient("hcap-xxx...")
client.enable_debug() # Enable debug logging
client.set_proxy("http://proxy:8080") # Set HTTP proxy
Captcha Solving
| Method | Returns | Description |
|---|---|---|
solve(image_bytes) |
dict |
Solve from raw image bytes |
solve_file(path) |
dict |
Solve from image file |
solve_base64(b64) |
dict |
Solve from base64-encoded image |
result = client.solve_file("captcha.png")
print(result["actions"]) # [{"x": 120, "y": 340}, ...]
YesCaptcha-Compatible
| Method | Returns | Description |
|---|---|---|
get_balance() |
dict |
Get account balance |
get_soft_id() |
str |
Get Soft ID |
create_task(task) |
str |
Create solving task (returns taskId) |
get_task_result(task_id) |
dict |
Poll for task result |
wait_for_result(task_id) |
dict |
Poll with auto-retry until ready |
task_id = client.create_task({
"type": "HCaptchaClassification",
"queries": ["base64_encoded_image"],
})
result = client.wait_for_result(task_id, poll_interval=0.5, timeout=120)
Error Handling
from ghostcaptcha_client import (
GhostCaptchaError, AuthError, RateLimitError,
BalanceError, NetworkError,
)
try:
balance = client.get_balance()
except AuthError:
print("Invalid API key")
except RateLimitError as e:
print(f"Rate limited, retry after {e.retry_after}s")
except BalanceError:
print("Insufficient balance")
except NetworkError:
print("Connection error")
except GhostCaptchaError as e:
print(f"API error [{e.code}]: {e.description}")
| Exception | HTTP Status | Description |
|---|---|---|
AuthError |
401 | Invalid or missing API key |
RateLimitError |
429 | Too many requests (auto-retries with Retry-After) |
BalanceError |
401 | Insufficient credits |
NetworkError |
— | Connection or timeout error |
GhostCaptchaError |
varies | Base exception for all API errors |
Context Managers
# Sync
with GhostCaptchaClient("hcap-xxx...") as client:
balance = client.get_balance()
# Async
async with AsyncGhostCaptchaClient("hcap-xxx...") as client:
balance = await client.get_balance()
Device Registration
Auto-collects HWID, CPU ID, MAC address, and OS info for device-bound licensing. Works on Windows (WMI/PowerShell), Linux (sysfs/dmidecode), and macOS (system_profiler).
client = GhostCaptchaClient("hcap-xxx...", auto_register=True)
print(client.device_id) # UUID if registration succeeded
Wait for Result (Polling)
Automatically polls get_task_result until the task completes or times out:
# Sync
result = client.wait_for_result(task_id, poll_interval=0.5, timeout=120)
# Async
result = await client.wait_for_result(task_id, poll_interval=0.5, timeout=120)
Connection Pooling
Both clients use a single httpx.Client / httpx.AsyncClient instance with
connection pooling. For manual resource management:
client = GhostCaptchaClient("hcap-xxx...")
# ... use client ...
client.close() # Frees the connection pool
Testing
GHOSTCAPTCHA_API_URL=http://api.ghostcaptcha.xyz/v1 python -m pytest tests/ -v
Made with ❤️ by GhostCaptcha · GitHub
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ghostcaptcha_client-1.0.0.tar.gz.
File metadata
- Download URL: ghostcaptcha_client-1.0.0.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbe313c89fbee006c0061cd9378af55252faefd56bac585fc9171b55430938d4
|
|
| MD5 |
625a0353be1887b8b01f095e98c9dedc
|
|
| BLAKE2b-256 |
16ce21589f95b7b3a2f6a28ee1e3dba8b82672a717caed92de06f219f934221d
|
File details
Details for the file ghostcaptcha_client-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ghostcaptcha_client-1.0.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8475369a95e9c4cd44afb0e1f540893aac73002ae2e00943ccca8c496579520
|
|
| MD5 |
a1f2d978dd809a6f3f47ae648b99d4f6
|
|
| BLAKE2b-256 |
245dc34aefbed413496cb77a00400c1566078198d2e4068d40cbe9f17c489d2f
|