Skip to main content

Flask Google ReCaptcha

PyPI pyversions

The Working Google ReCaptcha implementation for Flask without Flask-WTF.

Can also be used as standalone


Install

pip install Flask-GoogleReCaptcha

# or

pip install git+https://github.com/AndersonFirmino/flask-google-recaptcha.git

If you are using pipenv
pipenv install Flask-GoogleReCaptcha

This implementation is pure and has no dependencies from third parties. Works in both Python2 and Python3. You can use it in any flask project.

Has Google App Engine (GAE) support!

Usage

Implementation view.py

from flask import Flask
from flask_google_recaptcha import GoogleReCaptcha

app = Flask(__name__)
recaptcha = GoogleReCaptcha(app=app)

# or

recaptcha = GoogleReCaptcha()
recaptcha.init_app(app)

In your template: {{ recaptcha }}

Inside of the form you want to protect, include the tag: {{ recaptcha }}

It will insert the code automatically

<form method="post" action="/submit">
    ... your field
    ... your field

    {{ recaptcha }}

    [submit button]
</form>

Verify the captcha

In the view that's going to validate the captcha

from flask import Flask
from flask_google_recaptcha import GoogleReCaptcha

app = Flask(__name__)
recaptcha = GoogleReCaptcha(app=app)

@route("/submit", methods=["POST"])
def submit():

    if recaptcha.verify():
        # SUCCESS
        pass
    else:
        # FAILED
        pass

Remember to set SITE_KEY and SECRET_KEY if not it does not appear!

Api

reCaptcha.init(app, site_key, secret_key, is_enabled=True)

reCaptcha.get_code()

Returns the HTML code to implement. But you can use {{ recaptcha }} directly in your template

reCaptcha.verfiy()

Returns bool

In Template

Just include {{ recaptcha }} wherever you want to show the recaptcha

Config

Flask-ReCaptcha is configured through the standard Flask config API. These are the available options:

RECAPTCHA_ENABLED: Bool - True by default, when False it will bypass validation

RECAPTCHA_SITE_KEY : Public key

RECAPTCHA_SECRET_KEY: Private key

The following are Optional arguments.

RECAPTCHA_THEME: String - Theme can be 'light'(default) or 'dark'

RECAPTCHA_TYPE: String - Type of recaptcha can be 'image'(default) or 'audio'

RECAPTCHA_SIZE: String - Size of the image can be 'normal'(default) or 'compact'

RECAPTCHA_TABINDEX: Int - Tabindex of the widget can be used, if the page uses tabidex, to make navigation easier. Defaults to 0

RECAPTCHA_ENABLED = True
RECAPTCHA_SITE_KEY = ""
RECAPTCHA_SECRET_KEY = ""
RECAPTCHA_THEME = "dark"
RECAPTCHA_TYPE = "image"
RECAPTCHA_SIZE = "compact"
RECAPTCHA_RTABINDEX = 10

Anderson Araujo (coderpy) :snake:

Metadata

Release files for Flask-GoogleReCaptcha 0.5.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for Flask-GoogleReCaptcha 0.5.8
File Interpreter ABI Platform
Flask_GoogleRecaptcha-0.5.8-py2.py3-none-any.whl Python 2, Python 3 none any Details

Release files / Flask_GoogleRecaptcha-0.5.8-py2.py3-none-any.whl

Download URL Flask_GoogleRecaptcha-0.5.8-py2.py3-none-any.whl
Size 4.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
7a07badbf4b8a398152a91eec44f8fc6d8c1e02ea0b60cd03568da1d5948fc7f
BLAKE2b-256 checksum
How to use checksums
16f4d3cbea930a1625fa7c79a11a4a14b53066377eb6c16120a3fc84c93ea975
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.5.8 This release

1 release file

0.5.7

1 release file

0.5.5

1 release file

0.5.4

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page