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.1.tar.gz (11.1 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.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: captchakings-1.0.1.tar.gz
  • Upload date:
  • Size: 11.1 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.1.tar.gz
Algorithm Hash digest
SHA256 477abce90efc77ee67c3a480a60ba2c9835c1d1757569d937ac01e43ee05f65b
MD5 61234298e85b1d69024d5068f9d3be0c
BLAKE2b-256 a397b053c95e9fc6df154991201121e4e52d0c1143a4d4cef9797f0859caf97f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: captchakings-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.7 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fdfe841e7d72619bbdb3eb2b450ecaee47de397d9a03488694da2ac378bdaa31
MD5 b67ac7d28bb2800cf0195eab71ef56d7
BLAKE2b-256 cdb5f0d4191b1d95d48cde38726e57f8f700defc25dc24a63436f04b7c19e4c7

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