Skip to main content

Official Mailpush SDK for Python

Project description

Mailpush Python SDK

Official Python SDK for the Mailpush email API.

Installation

pip install mailpush

Quick Start

from mailpush import Mailpush, SendEmailRequest

client = Mailpush("mp_live_xxx")

response = client.emails.send(SendEmailRequest(
    from_address="hello@yourdomain.com",
    to="user@example.com",
    subject="Hello from Mailpush",
    html="<h1>Welcome!</h1>"
))

print(f"Email sent: {response.id}")

Features

  • Simple, intuitive API
  • Full type hints support
  • Automatic retries on rate limits
  • Support for attachments
  • Template support with variables

Sending Emails

Basic Email

from mailpush import Mailpush, SendEmailRequest

client = Mailpush("mp_live_xxx")

response = client.emails.send(SendEmailRequest(
    from_address="hello@yourdomain.com",
    to="user@example.com",
    subject="Welcome!",
    html="<h1>Hello World</h1>",
    text="Hello World"
))

With Multiple Recipients

response = client.emails.send(SendEmailRequest(
    from_address="hello@yourdomain.com",
    to=["user1@example.com", "user2@example.com"],
    cc="manager@example.com",
    bcc=["admin@example.com"],
    subject="Team Update",
    html="<p>Important update...</p>"
))

With Attachments

import base64
from mailpush import Mailpush, SendEmailRequest, Attachment

client = Mailpush("mp_live_xxx")

with open("report.pdf", "rb") as f:
    content = base64.b64encode(f.read()).decode()

response = client.emails.send(SendEmailRequest(
    from_address="hello@yourdomain.com",
    to="user@example.com",
    subject="Your Report",
    html="<p>Please find attached your report.</p>",
    attachments=[
        Attachment(
            filename="report.pdf",
            content=content,
            content_type="application/pdf"
        )
    ]
))

Using Templates

response = client.emails.send(SendEmailRequest(
    from_address="hello@yourdomain.com",
    to="user@example.com",
    template_id="welcome-template-id",
    variables={
        "name": "John",
        "company": "Acme Inc"
    }
))

Error Handling

from mailpush import (
    Mailpush,
    SendEmailRequest,
    AuthenticationError,
    ValidationError,
    RateLimitError,
    MailpushError
)

client = Mailpush("mp_live_xxx")

try:
    response = client.emails.send(SendEmailRequest(
        from_address="hello@yourdomain.com",
        to="user@example.com",
        subject="Test",
        html="<p>Hello</p>"
    ))
except AuthenticationError:
    print("Invalid API key")
except ValidationError as e:
    print(f"Validation failed: {e.details}")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")
except MailpushError as e:
    print(f"Error: {e.code} - {e}")

Configuration

Custom Base URL

client = Mailpush("mp_live_xxx", base_url="https://api.custom.com")

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mailpush-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mailpush-0.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file mailpush-0.1.0.tar.gz.

File metadata

  • Download URL: mailpush-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for mailpush-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7f231531c77f8dbe6465c797cbfa0cb0d8e96a3bb0be2f780dd210076fe6ce38
MD5 64f212fc69fbdc71a7e75b546cc3a470
BLAKE2b-256 58620bd14d2fc87205fe2eefe769782f51786505770968ba3a84aab2b9bb5a0d

See more details on using hashes here.

File details

Details for the file mailpush-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mailpush-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for mailpush-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb189e6ff4e98c04f6b56959a79f66e8db6bce04f1ac1b223c0e1bc8ece60686
MD5 ff263f1592271c24dae88af5f7132be7
BLAKE2b-256 d84ba48379a33515abb11270cc0d7dab3ea4f9c870b75b4fcc9f2232410b24c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page