Python library for RuCaptcha\2Captcha.
python-rucaptcha
Python 3.9+ library to solve CAPTCHAs automatically using RuCaptcha, 2Captcha, or DeathByCaptcha services.
What is this?
This library automates CAPTCHA solving by connecting to third-party services. When your code encounters a CAPTCHA, python-rucaptcha sends it to the service, waits for a human to solve it, and returns the solution to your application.
Supports 30+ CAPTCHA types:
- reCAPTCHA v2/v3, hCaptcha, Cloudflare Turnstile
- Image captchas, Audio captchas
- GeeTest, KeyCaptcha, Amazon WAF, Tencent
- And many more...
Quick Start
1. Install
pip install python-rucaptcha
2. Get an API Key
Sign up at RuCaptcha or 2Captcha, then copy your API key from the dashboard.
3. Solve a CAPTCHA
from python_rucaptcha import HCaptcha
Your API key
key = "yourapikey_here"
Solve hCaptcha
result = HCaptcha(aptchakey=key).captchahandler(siteurl="https://example.com", sitekey="abc123")
if result['code'] == 0: print(f"Solved! Token: {result['token']}") else: print(f"Error: {result['message']}")
Solving Different CAPTCHA Types
reCAPTCHA v2:
from python_rucaptcha import ReCaptcha
result = ReCaptcha(apikey).captchahandler( site_url="https://example.com", sitekey="yoursite_key" )
Image CAPTCHA:
from python_rucaptcha import ImageCaptcha
result = ImageCaptcha(apikey).captchahandler( image_link="https://example.com/captcha.jpg" )
ALTCHA:
from python_rucaptcha import AltchaCaptcha from python_rucaptcha.core.enums import AltchaEnm
result = AltchaCaptcha( rucaptchakey=apikey, websiteURL="https://example.com", challengeURL="https://example.com/altcha/challenge", method=AltchaEnm.AltchaTaskProxyless, ).captcha_handler()
Using async:
import asyncio from python_rucaptcha import HCaptcha
async def solve(): result = await HCaptcha(apikey).aiocaptcha_handler( site_url="https://example.com", site_key="abc123" ) return result
token = asyncio.run(solve())
Supported CAPTCHA Types
| CAPTCHA | Module | Description | |---------|--------|-------------| | reCAPTCHA v2/v3 | ReCaptcha | Google reCAPTCHA | | hCaptcha | HCaptcha | hCaptcha challenge | | Cloudflare Turnstile | Turnstile | Cloudflare protection | | Image | ImageCaptcha | Type the text from image | | Audio | AudioCaptcha | Listen and type audio | | GeeTest | GeeTest | Chinese geetest puzzles | | KeyCaptcha | KeyCaptcha | KeyCAPTCHA service | | Amazon WAF | AmazonWaf | AWS WAF challenge | | ALTCHA | AltchaCaptcha | ALTCHA challenge | | Binance | BinanceCaptcha | Token-based Binance challenge | | Grid | GridCaptcha | Select grid cells | | Coordinates | CoordinatesCaptcha | Click on coordinates | | And 20+ more | ... | See full docs |
Switching Services
Use the same code with different services:
from python_rucaptcha import HCaptcha
from python_rucaptcha.core.enums import ServiceEnm
Use 2Captcha (default)
result = HCaptcha("2captchakey").captchahandler(...)
Use RuCaptcha
result = HCaptcha("rucaptchakey", servicetype=ServiceEnm.RuCaptcha).captcha_handler(...)
Use DeathByCaptcha
result = HCaptcha("dbcuser:dbcpass", servicetype=ServiceEnm.DeathByCaptcha).captchahandler(...)
Testing
# Set your API key
export RUCAPTCHAKEY="yourkey_here"
Run tests
make tests
Documentation
For advanced usage, configuration options, and all CAPTCHA types, see the full documentation.
Support
- Telegram: pythoncaptcha
- Email: python-captcha@pm.me
- Issues: GitHub Issues
Changelog
See Releases for full changelog.
- v6.0 - Refactored to use msgspec (faster), API v2, dropped Python 3.8
- v5.3 - Added DeathByCaptcha support
- v5.2 - Added audio CAPTCHA solving