FastAPI
Use the Posthawk Python SDK with FastAPI.
SDK
@app.post("/send")Send emails from a FastAPI endpoint.
Example
python
from fastapi import FastAPI, HTTPException
from posthawk import Posthawk
import os
app = FastAPI()
client = Posthawk(os.environ["POSTHAWK_API_KEY"])
@app.post("/send")
async def send_email(to: str, subject: str, html: str):
result = client.emails.send(
from_email="hello@yourdomain.com",
to=to, subject=subject, html=html,
)
if result.error:
raise HTTPException(status_code=result.error.status_code, detail=result.error.message)
return {"job_id": result.data.job_id}