Python module for easy integration with 2Captcha API service to solve various types of captchas including reCAPTCHA, FunCaptcha, GeeTest, and many others
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Methods for solving various types of image-based captchas including normal text captchas, grid-based selection captchas, coordinate-based click captchas, canvas drawing captchas, and image rotation captchas.
Solves traditional text-based image captchas where users need to type the characters shown in the image.
def normal(self, file, **kwargs):
"""
Solve normal image captcha.
Parameters:
- file (str): Path to captcha image file or base64-encoded image
- phrase (int): 0=one word, 1=two+ words (default: 0)
- numeric (int): 0=not specified, 1=numbers only, 2=letters only,
3=numbers OR letters, 4=numbers AND letters (default: 0)
- minLen (int): Minimum number of symbols (1-20, default: 0)
- maxLen (int): Maximum number of symbols (1-20, default: 0)
- caseSensitive (int): 0=not case sensitive, 1=case sensitive (default: 0)
- calc (int): 0=not specified, 1=math calculation required (default: 0)
- lang (str): Language code (see 2captcha.com language list)
- hintText (str): Text hint for worker (max 140 chars)
- hintImg (str): Path to hint image (max 400x150px, 100KB)
- softId (int): Software developer ID
- callback (str): Pingback URL for result notification
Returns:
dict: {'captchaId': str, 'code': str}
"""Solves grid-based captchas where users need to click on specific areas or objects within an image grid.
def grid(self, file, **kwargs):
"""
Solve grid/reCAPTCHA image selection captcha.
Parameters:
- file (str): Path to captcha image file or base64-encoded image (required)
- hintText (str): Text describing what to select (required if no hintImg)
- hintImg (str): Path to hint image showing what to select (required if no hintText)
- rows (int): Number of grid rows (default: auto-detect)
- cols (int): Number of grid columns (default: auto-detect)
- previousId (str): ID of previous captcha for chained solving
- canSkip (int): 1=can skip if no matching images, 0=must select (default: 0)
- lang (str): Language code for hint text
- softId (int): Software developer ID
- callback (str): Pingback URL for result notification
- proxy (dict): Proxy configuration {'type': 'HTTPS', 'uri': 'login:pass@ip:port'}
Returns:
dict: {'captchaId': str, 'code': str} - code contains clicked cell numbers
"""Solves coordinate-based captchas where users need to click on specific points within an image.
def coordinates(self, file, **kwargs):
"""
Solve coordinate/click captcha.
Parameters:
- file (str): Path to captcha image file or base64-encoded image (required)
- hintText (str): Text describing where to click
- hintImg (str): Path to hint image showing where to click
- lang (str): Language code for hint text
- softId (int): Software developer ID
- callback (str): Pingback URL for result notification
Returns:
dict: {'captchaId': str, 'code': str} - code contains x,y coordinates
"""Solves canvas-based captchas where users need to draw or trace specific shapes or patterns.
def canvas(self, file, **kwargs):
"""
Solve canvas drawing captcha.
Parameters:
- file (str): Path to captcha image file or base64-encoded image (required)
- hintText (str): Text describing what to draw (required if no hintImg)
- hintImg (str): Path to hint image showing what to draw (required if no hintText)
- canSkip (int): 1=can skip if unable to draw, 0=must draw (default: 0)
- lang (str): Language code for hint text
- softId (int): Software developer ID
- callback (str): Pingback URL for result notification
Returns:
dict: {'captchaId': str, 'code': str} - code contains drawing coordinates
"""Solves image rotation captchas where users need to rotate images to the correct orientation.
def rotate(self, files, **kwargs):
"""
Solve image rotation captcha.
Parameters:
- files (str|dict): Single image path/base64 or dict mapping filenames to paths
- angle (int): Rotation step in degrees (default: auto-detect)
- lang (str): Language code for any text hints
- hintImg (str): Path to hint image showing correct orientation
- hintText (str): Text hint describing correct orientation
- softId (int): Software developer ID
- callback (str): Pingback URL for result notification
- proxy (dict): Proxy configuration {'type': 'HTTPS', 'uri': 'login:pass@ip:port'}
Returns:
dict: {'captchaId': str, 'code': str} - code contains rotation angles
"""from twocaptcha import TwoCaptcha
solver = TwoCaptcha('your_api_key')
# Simple text captcha
result = solver.normal('path/to/captcha.jpg')
print(f"Text: {result['code']}")
# Math captcha with constraints
result = solver.normal(
'math_captcha.jpg',
calc=1, # Math calculation required
numeric=1, # Numbers only
minLen=1, # At least 1 digit
maxLen=3 # At most 3 digits
)
print(f"Answer: {result['code']}")
# Case-sensitive with hint
result = solver.normal(
'complex_captcha.jpg',
caseSensitive=1,
hintText='Type only the red letters',
lang='en'
)
print(f"Text: {result['code']}")from twocaptcha import TwoCaptcha
solver = TwoCaptcha('your_api_key')
# reCAPTCHA-style image selection
result = solver.grid(
'recaptcha_grid.jpg',
hintText='Select all images with traffic lights',
rows=3,
cols=3
)
print(f"Selected cells: {result['code']}")
# Custom grid with hint image
result = solver.grid(
'custom_grid.jpg',
hintImg='hint_image.jpg',
canSkip=1 # Allow skipping if no matches
)
print(f"Selected: {result['code']}")from twocaptcha import TwoCaptcha
solver = TwoCaptcha('your_api_key')
# Click on specific object
result = solver.coordinates(
'click_captcha.jpg',
hintText='Click on the cat'
)
print(f"Click coordinates: {result['code']}") # "x=123,y=456"from twocaptcha import TwoCaptcha
solver = TwoCaptcha('your_api_key')
# Draw a line or shape
result = solver.canvas(
'canvas_captcha.jpg',
hintText='Draw a line from point A to point B'
)
print(f"Drawing path: {result['code']}")from twocaptcha import TwoCaptcha
solver = TwoCaptcha('your_api_key')
# Single image rotation
result = solver.rotate('rotated_image.jpg')
print(f"Rotation angle: {result['code']}")
# Multiple images
result = solver.rotate({
'img1': 'path/to/image1.jpg',
'img2': 'path/to/image2.jpg'
})
print(f"Rotations: {result['code']}")from twocaptcha import TwoCaptcha, ValidationException
solver = TwoCaptcha('your_api_key')
try:
result = solver.normal('captcha.jpg', minLen=5, maxLen=3) # Invalid: min > max
except ValidationException as e:
print(f"Validation error: {e}")
try:
result = solver.grid('grid.jpg') # Missing required hint
except ValidationException as e:
print(f"Missing hint: {e}")Install with Tessl CLI
npx tessl i tessl/pypi-2captcha-python