Send an email with FastAPI (Python)
Send emails inside FastAPI with the Publiq Python SDK (no external dependencies).
Install with pip install publiq and set PUBLIQ_API_KEY:
from fastapi import FastAPI
from publiq import Publiq
app = FastAPI()
publiq = Publiq()
@app.post("/send")
def send(to: str):
email = publiq.emails.send({
"from": "you@yourdomain.com",
"to": to,
"templateKey": "welcome-email",
"variables": {"first_name": "Ana"},
})
return {"id": email["id"]}Best practices
- Always call Publiq from the server — never expose the API key on the client.
- Create the client instance once and reuse it across requests.
- Prefer
templateKeyover inline HTML to keep content versioned. - Handle
PubliqError(status/code); the SDK already retries transient errors with backoff. - Send from a verified domain — see Domains.