Skip to main content

Official Python client for GhostCaptcha API — sync/async captcha solving

Project description

GhostCaptcha

GhostCaptcha Client

Official Python client for the GhostCaptcha API

PyPI version Python versions GitHub


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-After başlığını okuyup bekler
  • Proxy Support — HTTP/HTTPS proxy, set_proxy() ile canlı değiştirme
  • Debug Modeenable_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 CompatiblecreateTask, 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ghostcaptcha_client-1.0.0.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ghostcaptcha_client-1.0.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

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

Hashes for ghostcaptcha_client-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bbe313c89fbee006c0061cd9378af55252faefd56bac585fc9171b55430938d4
MD5 625a0353be1887b8b01f095e98c9dedc
BLAKE2b-256 16ce21589f95b7b3a2f6a28ee1e3dba8b82672a717caed92de06f219f934221d

See more details on using hashes here.

File details

Details for the file ghostcaptcha_client-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ghostcaptcha_client-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8475369a95e9c4cd44afb0e1f540893aac73002ae2e00943ccca8c496579520
MD5 a1f2d978dd809a6f3f47ae648b99d4f6
BLAKE2b-256 245dc34aefbed413496cb77a00400c1566078198d2e4068d40cbe9f17c489d2f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page