Skip to main content

Logo

Build Status Software License Code style: black Downloads Monthly Downloads

Async Recaptcha V2 & V3

Setup ⚙️

$ pip install aio-recaptcha

Usage

import aiorecaptcha

@app.route('/')
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):
    try:
        await aiorecaptcha.verify(
            secret=client_secret, 
            response=response_recieved_from_form,
            fail_for_less_than=0.55, # Recaptcha V3 only
        )

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

    else:
        return 'Hello hooman!'

API:

js()
html()
coro verify()
exc RecaptchaError

aiorecaptcha.html()

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

    site_key:
        * Required
        * Your Sitekey
    theme:
        * The color theme of the widget.
        * Optional
        * One of: (dark, light)
        * Default: light
    badge:
        * Reposition the reCAPTCHA badge. 'inline' lets you position it with CSS.
        * Optional
        * One of: ('bottomright', 'bottomleft', 'inline')
        * Default: None
    size:
        * Optional
        * The size of the widget
        * One of: ("compact", "normal", "invisible")
        * Default: normal
    type_:
        * 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.

aiorecaptcha.js()

Get JS script that loads the Recaptcha V2/V3 script

Appending this script to your HTML will expose the following API:
    https://developers.google.com/recaptcha/docs/display#js_api
    **If your html div is invisible, it will expose this API:**
    https://developers.google.com/recaptcha/docs/invisible#js_api

Arguments:
    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: https://developers.google.com/recaptcha/docs/language
    async_ (bool):
        * Optional
        * add async tag to JS script
        * Default True
    defer (bool):
        * Optional
        * Add def tag to JS Script
        * Default True

aiorecaptcha.verify()

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

    secret:
        * Required
        * The shared key between your site and reCAPTCHA.
    response:
        * 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'.
    remoteip:
        * Optional
        * The user's IP address.
    fail_for_less_than:
        * Optional
        * Only relevant for Recaptcha V3
        * Default 0.5
        * Read more about how to interpret the score here: https://developers.google.com/recaptcha/docs/v3#interpreting_the_score
        * Fail for score less than this value.

Test

Run:

$ aio-recaptcha/test.sh

Download files

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

Source Distribution

aio-recaptcha-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aio_recaptcha-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file aio-recaptcha-0.1.0.tar.gz.

File metadata

  • Download URL: aio-recaptcha-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.0

File hashes

Hashes for aio-recaptcha-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3d22dac5b850a5b290ea5054a1ec4e1341d6602f9f3c4682d139a7a7f20c6644
MD5 3ebe879b0ebb04242841c1566eb94295
BLAKE2b-256 31fa3d7011f6b6615cd2b1ced1a1ad803da94a3b2993f59db674e6409997c046

See more details on using hashes here.

File details

Details for the file aio_recaptcha-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: aio_recaptcha-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.0

File hashes

Hashes for aio_recaptcha-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7202706d31e7f12513d26feb9a0ae629dc51bea65829b261a57bb920368fad02
MD5 536d9cba9492d438ca3e7eebd8ee9bc6
BLAKE2b-256 bb52d295e5fab4ee9edb818248d7b2a66e62cdc78b0ea922a7a85b4f24176eb3

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

0.0.9

1 file

0.0.8

1 file

0.0.6

1 file

0.0.5

1 file

0.0.4

1 file

0.0.3

1 file

0.0.2

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page