Skip to main content

Python module for easy integration with 2Captcha API

Project description

Python Module for 2Captcha API

The easiest way to quickly integrate 2Captcha captcha solving service into your code to automate solving of any types of captcha.


This package can be installed with Pip:

pip3 install 2captcha-python


TwoCaptcha instance can be created like this:

from twocaptcha import TwoCaptcha

solver = TwoCaptcha('YOUR_API_KEY')

Also there are few options that can be configured:

config = {
    		'apiKey':           'YOUR_API_KEY',
    		'softId':            123,
    		'callback':         '',
    		'defaultTimeout':    120,
    		'recaptchaTimeout':  600,
    		'pollingInterval':   10,
solver = TwoCaptcha(**config)

TwoCaptcha instance options

Option Default value Description
softId - your software ID obtained after publishing in 2captcha sofware catalog
callback - URL of your web-sever that receives the captcha recognition result. The URl should be first registered in pingback settings of your account
defaultTimeout 120 Polling timeout in seconds for all captcha types except ReCaptcha. Defines how long the module tries to get the answer from res.php API endpoint
recaptchaTimeout 600 Polling timeout for ReCaptcha in seconds. Defines how long the module tries to get the answer from res.php API endpoint
pollingInterval 10 Interval in seconds between requests to res.php API endpoint, setting values less than 5 seconds is not recommended

IMPORTANT: once callback is defined for TwoCaptcha instance, all methods return only the captcha ID and DO NOT poll the API to get the result. The result will be sent to the callback URL. To get the answer manually use getResult method

Solve captcha

When you submit any image-based captcha use can provide additional options to help 2captcha workers to solve it properly.

Captcha options

Option Default Value Description
numeric 0 Defines if captcha contains numeric or other symbols see more info in the API docs
minLength 0 minimal answer lenght
maxLength 0 maximum answer length
phrase 0 defines if the answer contains multiple words or not
caseSensitive 0 defines if the answer is case sensitive
calc 0 defines captcha requires calculation
lang - defines the captcha language, see the list of supported languages
hintImg - an image with hint shown to workers with the captcha
hintText - hint or task text shown to workers with the captcha

Below you can find basic examples for every captcha type. Check out examples directory to find more examples with all available options.

Normal Captcha

To bypass a normal captcha (distorted text on image) use the following method. This method also can be used to recognize any text on the image.

result = solver.normal('path/to/captcha.jpg', param1=..., ...)

Text Captcha

This method can be used to bypass a captcha that requires to answer a question provided in clear text.

result = solver.text('If tomorrow is Saturday, what day is today?', param1=..., ...)

ReCaptcha v2

Use this method to solve ReCaptcha V2 and obtain a token to bypass the protection.

result = solver.recaptcha(sitekey='6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
                          param1=..., ...)

ReCaptcha v3

This method provides ReCaptcha V3 solver and returns a token.

result = solver.recaptcha(sitekey=6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
                            param1=..., ...)


FunCaptcha (Arkoselabs) solving method. Returns a token.

result = solver.funcaptcha(sitekey='6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
                            param1=..., ...)


Method to solve GeeTest puzzle captcha. Returns a set of tokens as JSON.

result = solver.geetest(gt='f1ab2cdefa3456789012345b6c78d90e',
                        param1=..., ...)


Use this method to solve hCaptcha challenge. Returns a token to bypass captcha.

result = solver.funcaptcha(sitekey='f1ab2cdefa3456789012345b6c78d90e',
                            param1=..., ...)


Token-based method to solve KeyCaptcha.

result = solver.keycaptcha(s_s_c_user_id=10,
    				   param1=..., ...)


Token-based method to bypass Capy puzzle captcha.

result = solver.capy(sitekey='PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v',
                     param1=..., ...)


Grid method is originally called Old ReCaptcha V2 method. The method can be used to bypass any type of captcha where you can apply a grid on image and need to click specific grid boxes. Returns numbers of boxes.

result = solver.grid('path/to/captcha.jpg', param1=..., ...)


Canvas method can be used when you need to draw a line around an object on image. Returns a set of points' coordinates to draw a polygon.

result = solver.canvas('path/to/captcha.jpg', param1=..., ...)


ClickCaptcha method returns coordinates of points on captcha image. Can be used if you need to click on particular points on the image.

result = solver.coordinates('path/to/captcha.jpg', param1=..., ...)


This method can be used to solve a captcha that asks to rotate an object. Mostly used to bypass FunCaptcha. Returns the rotation angle.

result = solver.rotate(['path/to/captcha1.jpg', 'path/to/captcha2.jpg', ...], param1=..., ...)

Other methods

send / getResult

These methods can be used for manual captcha submission and answer polling.

import time
. . . . . 

id = solver.send(file='path/to/captcha.jpg')

code = solver.getResult(id)


Use this method to get your account's balance

balance = solver.balance()


Use this method to report good or bad captcha answer., True) # captcha solved correctly, False) # captcha solved incorrectly

Error handling

If case of an error captcha solver throws an exception. It's important to properly handle these cases. We recommend to use try except to handle exceptions.

    result = solver.text('If tomorrow is Saturday, what day is today?')
Except ValidationException as e:
    # invalid parameters passed
Except NetworkException as e:
	# network error occurred
Except ApiException as e:
    # api respond with error
Except TimeoutException as e:
    # captcha is not solved so far

Project details

Download files

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

Files for 2captcha-python, version 1.0.2
Filename, size File type Python version Upload date Hashes
Filename, size 2captcha_python-1.0.2-py3-none-any.whl (8.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size 2captcha-python-1.0.2.tar.gz (7.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page