How do I reject disposable emails in FastAPI?
Install disban with pip, call signup_decision(email) in the signup endpoint, and raise HTTPException(400) when the action is block or fix. The package uses only the Python standard library and needs no API key to start. The same function works in Flask, Django or any other Python code.
Install and try it
Python 3.8 or later.
pip install disban
python -c "from disban import is_disposable; print(is_disposable('someone@sharklasers.com'))"
# TrueFastAPI endpoint
signup_decision makes a blocking HTTP call, so declare the endpoint with def (FastAPI runs it in a worker thread) or wrap the call in run_in_threadpool from an async endpoint.
# main.py
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel, EmailStr
from disban import signup_decision
app = FastAPI()
class Signup(BaseModel):
email: EmailStr
@app.post("/signup")
def signup(body: Signup):
d = signup_decision(body.email)
if d["action"] == "block":
raise HTTPException(400, "Please use a permanent email address.")
if d["action"] == "fix":
raise HTTPException(400, "This email domain can't receive mail. Check the address.")
# d["hold"] is True for unknown domains or when Disban was unreachable
user = create_user(body.email, hold_credits=d["hold"])
return {"ok": True, "id": user.id}Production: add a free API key
The keyless endpoint allows 10 checks per hour and 30 per day per network; set DISBAN_API_KEY (free, 2,000 checks a month, no card) and the same code switches to the keyed API with full evidence.
disban signup # or: python -m disban signup
export DISBAN_API_KEY=dbn_...Handling unknown results and outages
signup_decision never locks real users out. If Disban is slow, rate-limited or unreachable it returns allow with hold set to True, so you can create the account but hold free credits or rewards until the email is confirmed.
Source for provider behavior: Disban API documentation. Product-policy guidance is Disban's interpretation.