Skip to main content

Recaptcha v2 and v3

Project description


Build Status Software License Code style: black Downloads Monthly Downloads

Async Recaptcha V2 & V3

Setup ⚙️

$ pip install aio-recaptcha


import aiorecaptcha

def render_recaptcha():
    render(aiorecaptcha.html(site_key='your_site_key') + aiorecaptcha.js())

@app.route('/verify', methods=['POST'])
async def verify_recaptcha(response_received_from_form):
        await aiorecaptcha.verify(
            fail_for_less_than=0.55, # Recaptcha V3 only

    except recaptcha.RecaptchaError:
        return 'No! Only hoomans!'

        return 'Hello hooman!'


coro verify()
exc RecaptchaError


Get HTML <div> used by Recaptcha's JS script

        * Required
        * Your Sitekey
        * The color theme of the widget.
        * Optional
        * One of: (dark, light)
        * Default: light
        * Reposition the reCAPTCHA badge. 'inline' lets you position it with CSS.
        * Optional
        * One of: ('bottomright', 'bottomleft', 'inline')
        * Default: None
        * Optional
        * The size of the widget
        * One of: ("compact", "normal", "invisible")
        * Default: normal
        * Optional
        * One of: ('image', 'audio')
        * Default: 'image'
    tabindex (int):
        * Optional
        * The tabindex of the widget and challenge. 

        * If other elements in your page use tabindex, it should be set to make user navigation easier.
        * Default: 0
    callback (str):
        * Optional
        * The name of your callback function, executed when the user submits a successful response.
        * The **g-recaptcha-response** token is passed to your callback.
    expired_callback (str):
        * Opional
        * The name of your callback function, executed when the reCAPTCHA response expires and the user needs to re-verify.
    error_callback (str):
        * Optional
        * The name of your callback function, executed when reCAPTCHA encounters an error 
            (usually network connectivity) and cannot continue until connectivity is restored.
        * If you specify a function here, you are responsible for informing the user that they should retry.


Get JS script that loads the Recaptcha V2/V3 script

Appending this script to your HTML will expose the following API:
    **If your html div is invisible, it will expose this API:**

    onload (str):
        * Optional
        * The name of your callback function to be executed once all the dependencies have loaded.
    render (str):
        * Optional

        * Whether to render the widget explicitly. 

        * Defaults to onload, which will render the widget in the first g-recaptcha tag it finds.
        * Either: ``"onload"`` or explicitly specify a widget value
    language (str):
        * Optional
        * hl language code
        * Reference:
    async_ (bool):
        * Optional
        * add async tag to JS script
        * Default True
    defer (bool):
        * Optional
        * Add def tag to JS Script
        * Default True


Returns None if Recaptcha's response is valid, raises error

        * Required
        * The shared key between your site and reCAPTCHA.
        * Required
        * The user response token provided by reCAPTCHA, verifying the user on your site.
        * Should be typically found as an item named: 'g-recaptcha-response'.
        * Optional
        * The user's IP address.
        * Optional
        * Only relevant for Recaptcha V3
        * Default 0.5
        * Read more about how to interpret the score here:
        * Fail for score less than this value.



$ aio-recaptcha/

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 aio-recaptcha, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size aio_recaptcha-0.1.0-py3-none-any.whl (6.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size aio-recaptcha-0.1.0.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page