mailgun
Python SDK for Mailgun
What it is and what it does
Mailgun is the official Python SDK for Mailgun's email delivery platform. It wraps Mailgun's REST API to let you send transactional emails, manage sender domains, configure webhooks, retrieve delivery events, and access suppression lists—all from Python code. The SDK supports both synchronous (requests-based) and asynchronous (httpx/httpx2-based) clients, so you can integrate it into blocking or async applications.
The package handles common email workflows: sending plain or templated messages with attachments, scheduling delivery, tracking bounces and complaints, managing mailing lists, and querying delivery metrics and logs. It includes features like memory-safe attachment streaming, fluent message builders, strict payload validation, and development-mode credential redaction. The SDK is actively maintained, compatible with Python 3.11+, and carries an Apache-2.0 license.
Use it for:
- Send transactional emails (password resets, order confirmations) from a web application using the synchronous client.
- Build an async email notification system that queries delivery events and bounce data via streaming pagination.
- Manage email domain configuration, DKIM keys, and tracking settings programmatically.
- Implement a mailing list with suppression rules (bounces, unsubscribes, complaints) integrated into your application.
- Monitor email delivery metrics and logs to track campaign performance and diagnose delivery issues.
- Schedule emails for future delivery and attach files without loading entire payloads into memory.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Official Python SDK for the Mailgun email service API, providing synchronous and asynchronous clients to send messages, manage domains, webhooks, templates, and access email delivery metrics.
Yes. This is the official Mailgun SDK with active maintenance, low install friction, no known vulnerabilities, and broad API coverage. Install it if you use Mailgun for email delivery and want a well-supported, type-hinted Python client. The Alpha status reflects ongoing development, not instability—recent releases and active commits show it is production-ready.
Install
mailgun on PyPI
pip
pip install mailgunuv
uv add mailgunpoetry
poetry add mailgunInstalling mailgun
Before you install
Active maintenance with a recent release (10 days old). Low install friction—pure Python wheel with three HTTP client options (requests, httpx, httpx2). Requires Python 3.11+.
License in practice
Apache-2.0 permissive license allows commercial and private use with minimal restrictions.
Quickstart
pip install mailgun
from mailgun import Mailgun
client = Mailgun(domain='example.com', api_key='your-api-key')
response = client.messages.send(to='user@example.com', subject='Hello', text='Test message')
Requires Python 3.11 or later. Mailgun API credentials (domain and API key) must be provided.
Verify before relying
- Whether async support via httpx2 is production-ready or still experimental given the Alpha development status.
- Performance characteristics when handling large attachment streams with ChunkedStreamer.
- Exact retry and timeout defaults for exactly-once delivery semantics.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.11) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — httpx2, httpx, requests |
| Maintenance | actively maintained — 10 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 367,377/month — #7,197 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: mailgun-1.9.0-py3-none-any.whl
Keywords: email python-wrapper, mailgun, Mailgun API Python Wrapper, mailgun-api, Python SDK for Mailgun, transactional-emails, wrapper
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
django-anymailSends and receives email in Django through…
permissive · top 5,000 on PyPI
mailtrapOfficial Python client for Mailtrap's email…
permissive · top 15,000 on PyPI
odg-clientodg-client is a Python client library for…
unclear · top 15,000 on PyPI
mailmanMailman is a mailing list management system…
copyleft · top 15,000 on PyPI
mailjet-restA Python wrapper for the Mailjet Email API that…
permissive · top 5,000 on PyPI
postmarkerPostmarker is a Python client library for the…
permissive · top 5,000 on PyPI
brevo-pythonOfficial Python SDK for the Brevo API,…
unclear · top 15,000 on PyPI
django-post_officeDjango Post Office queues and sends emails…
permissive · top 15,000 on PyPI
zerobouncesdkPython SDK for the ZeroBounce email validation…
permissive · top 15,000 on PyPI
yagmailSimplifies sending emails via Gmail or any SMTP…
permissive · top 15,000 on PyPI