Standalone Google Recaptcha for Python
Google recaptcha helps you protect your web form by using google's latest recaptcha (Completely Automated Public Turing test to tell Computers and Humans Apart) technology.
Documentation
Installation
pip install google-recaptcha
Introduction
Current version of the library works by placing the {{ recaptcha }} object in the form you want to protect. It searches automatically for the form that the object is placed in.
From version 2.0.0, you can use the "Checkbox" version of Google's recaptcha. By default, the library is using v3, so if you want to use v2 you have to explicitly set it when initializing the ReCaptcha object (See below).
Site's and secret's keys can be either passed to the object in your views file or export them as environment variables respectively RECAPTCHA_SITE_KEY and RECAPTCHA_SECRET_KEY.
# With environment variables
from google_recaptcha import ReCaptcha
app = Flask(__name__)
recaptcha = ReCaptcha(app) # Uses version 3 by default
recaptcha = ReCaptcha(app, version=3) # Explicitly set version 3 (same as above, just for brevity)
recaptcha = ReCaptcha(app, version=2) # Excplicitly set version 2
@app.route("/contact/", methods=["GET", "POST"])
def home():
if recaptcha.verify():
print('Recaptcha has successded.')
else:
print('Recaptcha has failed.')
# Without environment variables
from google_recaptcha import ReCaptcha
app = Flask(__name__)
recaptcha = ReCaptcha(
app=app,
site_key="your-site-key",
secret_key="your-secret-key"
)
@app.route("/contact/", methods=["GET", "POST"])
def home():
if recaptcha.verify():
print('Recaptcha has successded.')
else:
print('Recaptcha has failed.')
In your HTML template file:
<form id="contact-form" method="post" class="control-form">
<div class="row">
<div class="col-xl-6">
<input type="text" name="name" placeholder="Name" required="" id="id_name">
</div>
<div class="col-xl-6">
<input type="text" name="email" placeholder="Email" required="" id="id_email">
</div>
<div class="col-xl-12">
<input type="text" name="subject" placeholder="Subject" required="" id="id_subject">
</div>
<div class="col-xl-12">
<textarea name="message" cols="40" rows="10" placeholder="Message" required="" id="id_message"></textarea>
</div>
<div class="col-xl-12">
<button id="form-btn" type="submit" class="btn btn-block btn-primary">Send now</button>
</div>
</div>
{{ recaptcha }}
</form>
Metadata
Release files for google-recaptcha 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| google-recaptcha-2.0.1.tar.gz | 4.9 kB | Without provenance | Details for google-recaptcha-2.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| google_recaptcha-2.0.1-py3-none-any.whl | Python 3 | none | any | Details for google_recaptcha-2.0.1-py3-none-any.whl |
Total release size: 10.6 kB
Release files / google-recaptcha-2.0.1.tar.gz
| Download URL | google-recaptcha-2.0.1.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6abb5c01413919fdae4c6cf7f70b2c35fe4b2989a1abd47f212ed98c5f115355
|
|
BLAKE2b-256 checksum How to use checksums |
5ca7e4a28b8a1551ed4cc7c2ad1d0b85c37c09f054f807e6dff512a829617e8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.14
|
Release files / google_recaptcha-2.0.1-py3-none-any.whl
| Download URL | google_recaptcha-2.0.1-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9952d6b9bd7c7c29090c6967398ad89d90b79905ef23a3ab822630ccb985abf5
|
|
BLAKE2b-256 checksum How to use checksums |
c56033bb8f1f4a6779573da9ab14c8ffb92bde80232fc531b8013a29e14eda17
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.14
|
Security for google-recaptcha 2.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.