Metadata-Version: 2.5
Name: abitechdev-antibot-django
Version: 0.1.1
Summary: Protege los formularios de Django contra bots con Turnstile o reCAPTCHA, validando el token en el servidor
Project-URL: Homepage, https://github.com/abitech-dev/abitech-antibot-django
Project-URL: Source, https://github.com/abitech-dev/abitech-antibot-django
Project-URL: Issues, https://github.com/abitech-dev/abitech-antibot-django/issues
Project-URL: Changelog, https://github.com/abitech-dev/abitech-antibot-django/blob/main/CHANGELOG.md
Author: Abimael Fernandez
License-Expression: MIT
License-File: LICENSE
Keywords: antibot,bots,captcha,cloudflare,django,recaptcha,turnstile
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.2
Classifier: Framework :: Django :: 6.0
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: Spanish
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Security
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: django>=4.2
Provides-Extra: drf
Requires-Dist: djangorestframework>=3.14; extra == 'drf'
Description-Content-Type: text/markdown

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/abitech-dev/abitech-antibot-django/main/docs/imagenes/logo-oscuro.svg">
    <img alt="AntiBot para Django" src="https://raw.githubusercontent.com/abitech-dev/abitech-antibot-django/main/docs/imagenes/logo-claro.svg" height="80">
  </picture>
</p>

<h1 align="center">AntiBot Django</h1>

<p align="center">Protege los formularios de Django contra bots con Turnstile o reCAPTCHA, validando el token en el servidor</p>

<p align="center">
  <a href="https://pypi.org/project/abitechdev-antibot-django/"><img alt="Versión en PyPI" src="https://img.shields.io/pypi/v/abitechdev-antibot-django?style=flat&color=1c6ccc&label=pypi"></a>
  <a href="https://github.com/abitech-dev/abitech-antibot-django/actions/workflows/ci.yml"><img alt="Integración continua" src="https://img.shields.io/github/actions/workflow/status/abitech-dev/abitech-antibot-django/ci.yml?branch=main&style=flat&label=integraci%C3%B3n%20continua"></a>
  <img alt="Django 4.2 a 6.0" src="https://img.shields.io/badge/django-4.2%20a%206.0-0c4b33?style=flat&logo=django&logoColor=white">
  <a href="https://github.com/abitech-dev/abitech-antibot-django/blob/main/LICENSE"><img alt="Licencia MIT" src="https://img.shields.io/badge/licencia-MIT-2ea043?style=flat"></a>
</p>

<p align="center">
  <a href="#inicio-rápido">Inicio rápido</a> &nbsp;|&nbsp;
  <a href="#uso">Uso</a> &nbsp;|&nbsp;
  <a href="#documentación">Documentación</a> &nbsp;|&nbsp;
  <a href="https://github.com/abitech-dev/abitech-antibot-django/blob/main/README.en.md">English</a>
</p>

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/abitech-dev/abitech-antibot-django/main/docs/diagramas/flujo-dark.svg">
  <img alt="El formulario envía el token, AntiBot lo verifica con el proveedor y la petición sigue a la vista o se rechaza con un error de validación" src="https://raw.githubusercontent.com/abitech-dev/abitech-antibot-django/main/docs/diagramas/flujo.svg">
</picture>

Los formularios públicos, como el registro, el inicio de sesión o el de
contacto, reciben envíos de bots. AntiBot valida en el servidor el token de
Cloudflare Turnstile o Google reCAPTCHA, y cambiar de proveedor es cambiar una
clave de `settings`.

## Qué resuelve

<table>
  <tr>
    <td width="50%" valign="top">
      <picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/abitech-dev/abitech-antibot-django/main/docs/iconos/proveedores-dark.svg"><img alt="Proveedores" src="https://raw.githubusercontent.com/abitech-dev/abitech-antibot-django/main/docs/iconos/proveedores.svg" width="28"></picture><br><strong>Un campo, tres proveedores</strong><br>Turnstile, reCAPTCHA v2 y v3 se validan igual, con <code>AntiBotField</code>.
    </td>
    <td width="50%" valign="top">
      <picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/abitech-dev/abitech-antibot-django/main/docs/iconos/formas-dark.svg"><img alt="Formas de uso" src="https://raw.githubusercontent.com/abitech-dev/abitech-antibot-django/main/docs/iconos/formas.svg" width="28"></picture><br><strong>DRF, formularios o código</strong><br>Un campo para Django REST Framework, otro para formularios y <code>verify()</code>.
    </td>
  </tr>
  <tr>
    <td width="50%" valign="top">
      <picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/abitech-dev/abitech-antibot-django/main/docs/iconos/politica-dark.svg"><img alt="Dominio y acción" src="https://raw.githubusercontent.com/abitech-dev/abitech-antibot-django/main/docs/iconos/politica.svg" width="28"></picture><br><strong>Dominio, acción y puntaje</strong><br>Rechaza el token resuelto en otro sitio, con otra acción o con puntaje bajo.
    </td>
    <td width="50%" valign="top">
      <picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/abitech-dev/abitech-antibot-django/main/docs/iconos/seguro-dark.svg"><img alt="Seguro por defecto" src="https://raw.githubusercontent.com/abitech-dev/abitech-antibot-django/main/docs/iconos/seguro.svg" width="28"></picture><br><strong>Falla cerrado</strong><br>Si el proveedor no responde, el token no pasa, y apagado no arranca en producción.
    </td>
  </tr>
  <tr>
    <td width="50%" valign="top">
      <picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/abitech-dev/abitech-antibot-django/main/docs/iconos/pruebas-dark.svg"><img alt="Pruebas" src="https://raw.githubusercontent.com/abitech-dev/abitech-antibot-django/main/docs/iconos/pruebas.svg" width="28"></picture><br><strong>Fácil de probar</strong><br><code>fake_verification()</code> responde en las pruebas sin llamar al proveedor.
    </td>
    <td width="50%" valign="top">
      <picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/abitech-dev/abitech-antibot-django/main/docs/iconos/versiones-dark.svg"><img alt="Versiones" src="https://raw.githubusercontent.com/abitech-dev/abitech-antibot-django/main/docs/iconos/versiones.svg" width="28"></picture><br><strong>De Django 4.2 a 6.0</strong><br>Sin dependencias, con tipos y probado en cada Django que promete.
    </td>
  </tr>
</table>

## Inicio rápido

```bash
pip install "abitechdev-antibot-django[drf]"
```

```python
INSTALLED_APPS = [..., "abitech_antibot"]

ANTIBOT = {
    "PROVIDER": "turnstile",
    "SECRET": os.environ["TURNSTILE_SECRET"],
    "HOSTNAMES": ["app.ejemplo.pe"],
}
```

```python
from abitech_antibot.drf import AntiBotField


class RegistroSerializer(serializers.Serializer):
    email = serializers.EmailField()

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields["cf-turnstile-response"] = AntiBotField(action="registro")
```

Si el token no es válido, el serializer devuelve el error en su campo como
cualquier otra validación.

## Uso

| Proveedor | `PROVIDER` | Comprueba |
| --- | --- | --- |
| Cloudflare Turnstile | `turnstile` | Token, dominio y acción |
| reCAPTCHA v2 | `recaptcha_v2` | Token y dominio |
| reCAPTCHA v3 | `recaptcha_v3` | Token, dominio, acción y puntaje |

En un formulario de Django, el campo de `abitech_antibot.forms` funciona igual.
`verify()` deja decidir en el código:

```python
from abitech_antibot import verify

resultado = verify(token, ip=request.META.get("REMOTE_ADDR"), action="login")
```

## Compatibilidad

| Django | Python |
| --- | --- |
| 6.0 | 3.12 a 3.14 |
| 5.2 | 3.10 a 3.14 |
| 4.2 | 3.10 a 3.12 |

## Documentación

| Quiero… | Documento |
| --- | --- |
| Ver todas las claves y las comprobaciones | [configuracion.md](https://github.com/abitech-dev/abitech-antibot-django/blob/main/docs/configuracion.md) |
| Proteger un serializer, un formulario o una vista | [uso.md](https://github.com/abitech-dev/abitech-antibot-django/blob/main/docs/uso.md) |
| Probar mi proyecto sin llamar al proveedor | [pruebas.md](https://github.com/abitech-dev/abitech-antibot-django/blob/main/docs/pruebas.md) |
| Saber por qué se publica así | [ADR 0001](https://github.com/abitech-dev/abitech-antibot-django/blob/main/docs/decisiones/0001-ramas-y-publicacion.md) |
| Ver los cambios por versión | [CHANGELOG.md](https://github.com/abitech-dev/abitech-antibot-django/blob/main/CHANGELOG.md) |

## Contribuir

Los pasos y lo que revisa la integración continua están en
[CONTRIBUTING.md](https://github.com/abitech-dev/abitech-antibot-django/blob/main/CONTRIBUTING.md). Para reportar una vulnerabilidad, sigue
[SECURITY.md](https://github.com/abitech-dev/abitech-antibot-django/blob/main/SECURITY.md).

## Licencia

Copyright © 2026 ABItech Perú. Licencia MIT, cuyo texto figura en
[LICENSE](https://github.com/abitech-dev/abitech-antibot-django/blob/main/LICENSE).
