Skip to main content

Official Python client for CaptchaKings API

Project description

CaptchaKings Python Library

Python Version License

Official Python client library for CaptchaKings API - Fast, accurate, and affordable CAPTCHA solving service.

✨ Features

  • 🚀 Simple & Clean API - Just 2 lines of code to solve CAPTCHAs
  • 🔄 Automatic Retry - Built-in retry logic for failed requests
  • 🛡️ Type Hints - Full type annotations for better IDE support
  • Fast & Reliable - Optimized for performance
  • 🎯 Error Handling - Custom exceptions for different error types
  • 📦 Zero Configuration - Works out of the box

📦 Installation

From Source (Local Development)

cd captchakings-python
pip install -e .

Requirements

  • Python 3.6 or higher
  • requests library (automatically installed)

🚀 Quick Start

from captchakings import CaptchaKings

# Initialize client
client = CaptchaKings('ck_your_api_key_here')

# Solve CAPTCHA
result = client.solve('captcha.jpg')

print(f"Solved: {result['prediction']}")
print(f"Confidence: {result['confidence']}")
print(f"Credits Remaining: {result['credits_remaining']}")

That's it! Just 3 lines of code. 🎉

📖 Usage Examples

Basic Usage

from captchakings import CaptchaKings

client = CaptchaKings('ck_your_api_key')
result = client.solve('path/to/captcha.jpg')

if result:
    print(f"✅ CAPTCHA Solved: {result['prediction']}")
    print(f"Confidence: {result['confidence']}")
    print(f"Credits Remaining: {result['credits_remaining']}")

With Automatic Retry

from captchakings import CaptchaKings

client = CaptchaKings('ck_your_api_key')

# Automatically retry up to 5 times with 2 second delay
result = client.solve_with_retry(
    'captcha.jpg',
    max_retries=5,
    retry_delay=2
)

print(f"Solved: {result['prediction']}")

Error Handling

from captchakings import CaptchaKings
from captchakings.exceptions import (
    AuthenticationError,
    InsufficientCreditsError,
    InvalidImageError,
    APIError
)

client = CaptchaKings('ck_your_api_key')

try:
    result = client.solve('captcha.jpg')
    print(f"Solved: {result['prediction']}")
    
except AuthenticationError:
    print("❌ Invalid API key")
except InsufficientCreditsError:
    print("❌ Not enough credits")
except InvalidImageError:
    print("❌ Invalid image file")
except APIError as e:
    print(f"❌ API Error: {e}")

Using Context Manager

from captchakings import CaptchaKings

# Automatically closes session after use
with CaptchaKings('ck_your_api_key') as client:
    result = client.solve('captcha.jpg')
    print(f"Solved: {result['prediction']}")

Processing Multiple CAPTCHAs

from captchakings import CaptchaKings
import os

client = CaptchaKings('ck_your_api_key')

captcha_folder = 'captchas/'
for filename in os.listdir(captcha_folder):
    if filename.endswith(('.jpg', '.png', '.jpeg')):
        filepath = os.path.join(captcha_folder, filename)
        
        try:
            result = client.solve(filepath)
            print(f"{filename}: {result['prediction']}")
        except Exception as e:
            print(f"{filename}: Error - {e}")

🎯 API Reference

CaptchaKings Class

__init__(api_key, base_url='https://captchakings.com/api/process.php')

Initialize the client.

Parameters:

  • api_key (str): Your CaptchaKings API key
  • base_url (str, optional): API endpoint URL

solve(image_path, timeout=30)

Solve a CAPTCHA from an image file.

Parameters:

  • image_path (str): Path to CAPTCHA image file
  • timeout (int, optional): Request timeout in seconds (default: 30)

Returns:

  • dict: Response containing:
    • prediction (str): Solved CAPTCHA text
    • confidence (float): Prediction confidence score
    • process_time (float): Processing time in seconds
    • credits_deducted (int): Credits used for this request
    • credits_remaining (int): Remaining credits in account
    • plan (str): Your current plan name

Raises:

  • InvalidImageError: Image file not found or invalid
  • AuthenticationError: Invalid API key
  • InsufficientCreditsError: Not enough credits
  • TimeoutError: Request timeout
  • NetworkError: Connection error
  • APIError: Other API errors

solve_with_retry(image_path, max_retries=3, retry_delay=2, timeout=30)

Solve CAPTCHA with automatic retry on transient failures.

Parameters:

  • image_path (str): Path to CAPTCHA image file
  • max_retries (int, optional): Maximum retry attempts (default: 3)
  • retry_delay (int, optional): Delay between retries in seconds (default: 2)
  • timeout (int, optional): Request timeout in seconds (default: 30)

Returns:

  • Same as solve() method

🎨 Response Format

{
    'prediction': 'ABC123',           # Solved CAPTCHA text
    'confidence': 0.98,               # Confidence score (0-1)
    'process_time': 0.234,            # Processing time in seconds
    'credits_deducted': 1,            # Credits used
    'credits_remaining': 9999,        # Remaining credits
    'plan': 'Professional'            # Your plan name
}

⚠️ Exception Types

  • CaptchaKingsException - Base exception class
  • APIError - General API errors
  • AuthenticationError - Invalid API key
  • InsufficientCreditsError - Not enough credits
  • InvalidImageError - Invalid or missing image file
  • TimeoutError - Request timeout
  • NetworkError - Network connection error

🔑 Getting API Key

  1. Visit CaptchaKings.com
  2. Register for an account
  3. Go to Dashboard
  4. Copy your API key (starts with ck_)

💡 Tips

  1. Use context manager - Ensures proper session cleanup
  2. Enable retry logic - For better reliability
  3. Handle exceptions - For robust error handling
  4. Batch processing - Reuse the same client instance

📚 More Examples

Check the examples/ folder for more usage examples:

  • basic_usage.py - Simple CAPTCHA solving
  • advanced_usage.py - Advanced features and error handling
  • batch_processing.py - Process multiple CAPTCHAs

🤝 Support

📄 License

MIT License - see LICENSE file for details

🌟 Why CaptchaKings?

  • High Accuracy - 99%+ success rate
  • Fast Processing - < 1 second average response time
  • Affordable Pricing - Starting from $1/1000 solves
  • 24/7 Support - Always here to help
  • No Setup Required - Start in seconds

Made with ❤️ by CaptchaKings

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

captchakings-1.0.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

captchakings-1.0.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file captchakings-1.0.0.tar.gz.

File metadata

  • Download URL: captchakings-1.0.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.0

File hashes

Hashes for captchakings-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c9bfad799d1e886c99cacf4f64503790d9a019ef08ab7cf3b3e30920df661d8b
MD5 6ec350a0ae2b7501ab966d942e9148a5
BLAKE2b-256 4ef85241473bec5c7b481b5755e509fc5f06fbfc5856ab64e850174171af8fd2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: captchakings-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.0

File hashes

Hashes for captchakings-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61749ba78d52668e546d9ec17a5ab09b43e31563067e24662be63df068ab7dc4
MD5 a6e4f4cd73fcdd2e00c0f6d455c78e2b
BLAKE2b-256 80ae5876a38e4412eeaf6e2a1643777cef56ec7fcee2b3b9ffeb2439338b3a26

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