Arcaptcha integration for Django REST Framework — field, mixin, and validator.
Project description
django-arcaptcha
Arcaptcha integration for Django REST Framework.
Works exactly like django-recaptcha — add one line to any serializer.
Requirements
- Python 3.10+
- Django 4.2+
- Django REST Framework 3.14+
- arcaptcha-python 0.1.2+
Installation
pip install django-arcaptcha
settings.py
INSTALLED_APPS = [
...
"arcaptcha",
]
# Get your keys at https://arcaptcha.ir
ARCAPTCHA_SITE_KEY = "your_site_key"
ARCAPTCHA_SECRET_KEY = "your_secret_key"
Verify your setup:
python manage.py check --deploy
Usage
Option 1 — Field (explicit, one line)
from arcaptcha import ArcaptchaField
class LoginSerializer(serializers.Serializer):
email = serializers.EmailField()
password = serializers.CharField(write_only=True)
captcha = ArcaptchaField()
Option 2 — Mixin (automatic injection)
from arcaptcha import ArcaptchaMixin
class LoginSerializer(ArcaptchaMixin, serializers.Serializer):
email = serializers.EmailField()
password = serializers.CharField(write_only=True)
# `captcha` field is injected automatically
Option 3 — Validator (anywhere outside a serializer)
from arcaptcha import ArcaptchaValidator
# in a view, task, or any callable
ArcaptchaValidator()(request.data["captcha"])
What the client sends
POST /api/auth/login/
{
"email": "alice@example.com",
"password": "secret",
"captcha": "<token-from-arcaptcha-widget>"
}
Error responses
// Invalid token → HTTP 400
{"captcha": ["Invalid or expired captcha. Please try again."]}
// Service down → HTTP 400
{"captcha": ["Captcha verification is temporarily unavailable. Please try again later."]}
All settings
| Setting | Default | Description |
|---|---|---|
ARCAPTCHA_SITE_KEY |
— | Required. Your site key from arcaptcha.ir |
ARCAPTCHA_SECRET_KEY |
— | Required. Your secret key from arcaptcha.ir |
ARCAPTCHA_DISABLE |
False |
Skip verification — test/local only |
ARCAPTCHA_LANG |
"en" |
Widget language: "en" or "fa" |
ARCAPTCHA_THEME |
"light" |
Widget theme: "light" or "dark" |
ARCAPTCHA_SIZE |
"normal" |
Widget size: "normal" or "compact" |
Testing in your project
Option A — disable in test settings (simplest)
# settings/test.py
ARCAPTCHA_DISABLE = True
Option B — mock the verify call per test
from unittest.mock import patch
@patch("arcaptcha.validators.verify_arcaptcha", return_value=True)
def test_login(mock_verify, api_client):
res = api_client.post("/api/auth/login/", {
"email": "a@b.com", "password": "secret", "captcha": "any"
})
assert res.status_code == 200
Contributing
git clone https://github.com/rassoulshah/django-arcaptcha
cd django-arcaptcha
pip install -e ".[dev]"
pytest
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_arcaptcha-1.0.0.tar.gz.
File metadata
- Download URL: django_arcaptcha-1.0.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3521699ee6950b1db994801e154b86d3338844d82552ab9b99a2a26de063a92
|
|
| MD5 |
d7414860bd33358ee486c02afecf5bcc
|
|
| BLAKE2b-256 |
bb55504393f979e9dabc65bca6bafe0fd38b9749d2a8dede4a3b5946b9db36f4
|
Provenance
The following attestation bundles were made for django_arcaptcha-1.0.0.tar.gz:
Publisher:
publish.yml on rassoulshah/django-arcaptcha
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_arcaptcha-1.0.0.tar.gz -
Subject digest:
b3521699ee6950b1db994801e154b86d3338844d82552ab9b99a2a26de063a92 - Sigstore transparency entry: 1439972198
- Sigstore integration time:
-
Permalink:
rassoulshah/django-arcaptcha@a2cc4020a859a2b87462657f736264b33442729e -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/rassoulshah
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a2cc4020a859a2b87462657f736264b33442729e -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_arcaptcha-1.0.0-py3-none-any.whl.
File metadata
- Download URL: django_arcaptcha-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c531721060deda46ff9958774f913db40111d2415fa3e40f8b9e8af7d37c1dd4
|
|
| MD5 |
4674840f5c28a6cb9bea35e113800cd3
|
|
| BLAKE2b-256 |
a8eb28c3286267d6dc32a2d716539aeb3de8ad5e44b4b0f4432f189564d031e0
|
Provenance
The following attestation bundles were made for django_arcaptcha-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on rassoulshah/django-arcaptcha
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_arcaptcha-1.0.0-py3-none-any.whl -
Subject digest:
c531721060deda46ff9958774f913db40111d2415fa3e40f8b9e8af7d37c1dd4 - Sigstore transparency entry: 1439972202
- Sigstore integration time:
-
Permalink:
rassoulshah/django-arcaptcha@a2cc4020a859a2b87462657f736264b33442729e -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/rassoulshah
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a2cc4020a859a2b87462657f736264b33442729e -
Trigger Event:
push
-
Statement type: