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
Metadata
Release files for django-arcaptcha 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_arcaptcha-1.0.0.tar.gz | 9.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_arcaptcha-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.8 kB
Release files / django_arcaptcha-1.0.0.tar.gz
| Download URL | django_arcaptcha-1.0.0.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b3521699ee6950b1db994801e154b86d3338844d82552ab9b99a2a26de063a92
|
|
BLAKE2b-256 checksum How to use checksums |
bb55504393f979e9dabc65bca6bafe0fd38b9749d2a8dede4a3b5946b9db36f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 5, 2026.
Transparency logRelease files / django_arcaptcha-1.0.0-py3-none-any.whl
| Download URL | django_arcaptcha-1.0.0-py3-none-any.whl |
|---|---|
| Size | 9.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c531721060deda46ff9958774f913db40111d2415fa3e40f8b9e8af7d37c1dd4
|
|
BLAKE2b-256 checksum How to use checksums |
a8eb28c3286267d6dc32a2d716539aeb3de8ad5e44b4b0f4432f189564d031e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 5, 2026.
Transparency log