Sign inGet Started

Python SDK

Send email with Flask

Use Parcel Wing from Flask routes with server-side API key handling.

Install the SDK

The official SDK is published as parcelwing.

Terminal

pip install parcelwing

Route

Create a JSON endpoint that sends a template email and returns structured Parcel Wing errors.

app.py

import os
 
from flask import Flask, jsonify, request
from parcelwing import ParcelWing, ParcelWingError
 
app = Flask(__name__)
parcel_wing = ParcelWing(api_key=os.environ["PARCEL_WING_API_KEY"])
 
@app.post("/send-welcome")
def send_welcome():
data = request.get_json() or {}
 
try:
emails = parcel_wing.emails.send(
from_="Acme <[email protected]>",
to=data["email"],
template_alias="welcome_email",
template_params={
"first_name": data.get("first_name") or "friend",
},
)
return jsonify({"id": emails[0]["id"]})
except ParcelWingError as error:
return jsonify({
"code": error.code,
"request_id": error.request_id,
}), error.status

Production notes

  • Keep PARCEL_WING_API_KEY in server-side environment variables.
  • Validate and rate limit public form endpoints before sending email.
  • Use templates instead of building repeated HTML in route handlers.