DisposableGuard

Django

import os, requests
from functools import wraps
from django.http import JsonResponse

def block_disposable(view_func):
    @wraps(view_func)
    def wrapper(request, *args, **kwargs):
        email = request.POST.get('email') or request.GET.get('email')
        if not email:
            return view_func(request, *args, **kwargs)

        try:
            r = requests.get(
                "https://api.disposableguard.com/v1/check",
                params={"email": email},
                headers={"Authorization": f"Bearer {os.environ['DG_KEY']}"},
                timeout=5,
            )
            if r.status_code == 200 and r.json().get("is_disposable"):
                return JsonResponse(
                    {"error": "Please use a real email address."},
                    status=400,
                )
        except requests.RequestException:
            pass  # fail-open

        return view_func(request, *args, **kwargs)
    return wrapper

# Usage:
# @block_disposable
# def signup(request):
#     ...

Notes

Requires the `requests` library. Install with `pip install requests`. The decorator fails open on network errors.