Python SDK
Send email with Django
Use Parcel Wing from Django settings, services, and views.
Install the SDK
The official SDK is published as parcelwing.
Terminal
pip install parcelwing
Settings
Load the API key and default sender from your Django settings module.
settings.py
# settings.pyPARCEL_WING_API_KEY = env("PARCEL_WING_API_KEY")PARCEL_WING_FROM_EMAIL = env("PARCEL_WING_FROM_EMAIL", default="Acme <[email protected]>")
Mail service
Wrap the SDK in a small service module so views, tasks, and signals share one sending interface.
mail.py
from django.conf import settingsfrom parcelwing import ParcelWing, ParcelWingErrorparcel_wing = ParcelWing(api_key=settings.PARCEL_WING_API_KEY)def send_welcome_email(email: str, first_name: str | None = None):try:emails = parcel_wing.emails.send(from_=settings.PARCEL_WING_FROM_EMAIL,to=email,template_alias="welcome_email",template_params={"first_name": first_name or "friend",},)return emails[0]except ParcelWingError as error:# Log error.request_id with your normal application logger.raise
View
Call your service from a view after validation, authorization, and any database writes.
views.py
from django.http import JsonResponsefrom django.views.decorators.http import require_POSTfrom .mail import send_welcome_email@require_POSTdef send_welcome(request):message = send_welcome_email(email=request.POST["email"],first_name=request.POST.get("first_name"),)return JsonResponse({"id": message["id"]})
Production notes
- Do not expose
PARCEL_WING_API_KEYin templates or JavaScript. - Prefer background jobs for slow or non-critical lifecycle email.
- Use saved templates for onboarding, receipts, invites, and account notifications.