Registry / web-framework / drf-recaptcha

drf-recaptcha

JSON →
library4.0.3pypypiunverified

A Django REST Framework field and serializer for Google reCAPTCHA (v2 and v3) verification. Current version 4.0.3 supports Django ≥4.2, Python ≥3.10, DRF ≥3.14. Released irregularly; latest updates add Django 5.2 and Python 3.13 support.

pip install drf-recaptcha
INSTALL
IMPORT
SIG · DRF-RECAPTCHA
D
drf-recaptcha
web-frameworkpythonv4.0.3
Install
3.8s avg
Import
Disk
70MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.0.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 70.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.8s · import 0.000s · 71MB
70MB installed
● package 70MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ReCaptchaSerializer
from drf_recaptcha import ReCaptchaSerializer
from drf_recaptcha.serializers import ReCaptchaSerializer

Quickstart: define a serializer inheriting ReCaptchaSerializer. Configure DRF_RECAPTCHA_SECRET_KEY in Django settings. For testing, set DRF_RECAPTCHA_TESTING=True to bypass verification.

import os from django.conf import settings from rest_framework import serializers from drf_recaptcha.serializers import ReCaptchaSerializer settings.configure( DRF_RECAPTCHA_SECRET_KEY=os.environ.get('RECAPTCHA_SECRET_KEY', 'test-secret'), INSTALLED_APPS=['django.contrib.contenttypes', 'django.contrib.auth'], DATABASES={'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:'}}, ) import django django.setup() class MySerializer(ReCaptchaSerializer): email = serializers.EmailField() # Dummy data for testing (use valid reCAPTCHA response in production) data = {'email': 'test@example.com', 'recaptcha': 'dummy-response'} serializer = MySerializer(data=data) print(serializer.is_valid())
Debug
Known issues
breakingVersion 4.0.0 drops support for Django 3.2, 4.0, 4.1; Python 3.8, 3.9; and DRF 3.11, 3.12, 3.13. Upgrade your environment if migrating from <4.0.
fix
Ensure Django ≥4.2, Python ≥3.10, DRF ≥3.14 before upgrading to drf-recaptcha ≥4.0.
affects: <4.0
gotchaThe `ReCaptchaSerializer` includes a `recaptcha` field by default but does not hide it from the serializer output. This field will be serialized back to the client unless explicitly excluded using `exclude` or `fields`.
fix
Add `Meta.exclude = ['recaptcha']` or use `fields` to limit output fields.
affects: All
gotchaIn reCAPTCHA v3, the default required score is 0.5. Setting the required score to 0 (to allow all) was broken before version 3.2.0; the score 0 was treated as None and overridden to 0.5.
fix
Upgrade to ≥3.2.0 if you need a required score of 0. Now a score of 0 correctly allows all traffic.
affects: <3.2.0
deprecatedThe setting `DRF_RECAPTCHA_TESTING` when set to `True` skips actual verification. However, the field will still require a non-empty string. This is intended for testing but may confuse users expecting full bypass.
fix
Use `DRF_RECAPTCHA_TESTING=True` only in test environments; for real bypass consider using a mock serializer.
affects: All
gotchaMultiple/ dynamic secret keys (introduced in 3.0.0) require passing a secret key via the serializer's `context` or field kwargs. If not provided, the default `DRF_RECAPTCHA_SECRET_KEY` is used. Forgetting this can lead to wrong key usage.
fix
Always pass the intended secret key explicitly when using multiple keys: `ReCaptchaField(secret_key='...')`.
affects: ≥3.0.0
Upgrade
Version history
4.0.3latest on PyPI · released Aug 22, 2025
Audit
Dependencies
djangorequiredCore dependency for web framework
djangorestframeworkrequiredRequired for serializer field integration
requestsrequiredUsed to verify reCAPTCHA with Google's API
Agent activity
32 hits · last 30 days
node
30
Amazon
1
OpenAI (training)
1
Resources
drf-recaptcha — pip install drf-recaptcha · libregistry