Skip to main content

PYostal: Postal API Client

This library helps you use the Postal API in Python 3.9 (and above) to send Emails, get Message Details & Deliveries and Implement Events to handle Server Webhooks.

It uses Requests the simple, yet elegant HTTP library to handle all the http sorcery.

Installing Requests and Supported Versions

PYostal is available on PyPI:

$ python -m pip install pyostal

PYostal officially supports Python 3.9+.

Usage

Using the Client

You will need an API Credential from your Postal Installation to use the API Client.

from pyostal.client import Client

# Create a new Postal client using the server key of your Postal Installation.
client = Client('https://postal.yourdomain.com', 'your-api-key')

# Optional: You can add any aditional Headers for your API installation
# (Maybe Authorization)
# You just add a dict with your headers:
headers = {
    'Authorization' => 'Basic RTYtaO54BGBtcG9yYWwyMDIw'
}

client = Client('https://postal.yourdomain.com', 'your-api-key', headers)

#Or you can add them manually to a Client Instance:
client.headers = headers

Sending an Email

Sending an email is simple. You can follow the example below:

# Create a dict with the message:
payload = {
    'to': ['mail@example.com'],
    'from_address': 'othermail@example.com',
    'reply_to': 'reply-to@example.com',
    'subject': 'This is a subject',
    'plain_body': 'This is a body'
}

#send it using the client. that's it
response = client.send(payload)

Or Create a new Email instance and add manually each of the Mail attributes

from pyostal.emails import Email

email = Email({
    'to': ['mail@example.com'],
    'bcc': ['test1@example.com', 'test2@example.com],
    'from_address': 'othermail@example.com',
    'reply_to': 'reply-to@example.com',
    'subject': 'This is a subject',
    'plain_body': 'This is a body'
})

email.add_cc('emailcc@example.com')
email.html_body = "<p>This is a HTML body</p>"

# Here we get a pyostal.response.Response instance
response = client.send(Email)

API Information

You can get more information about the Postal API and Payloads in the Postal Project Wiki

Author

Rafael Nevarez

Metadata

Release files for pyostal 0.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyostal 0.8.1
File Size Uploaded
pyostal-0.8.1.tar.gz 8.3 kB Details

Release files / pyostal-0.8.1.tar.gz

Download URL pyostal-0.8.1.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d05f8f8722a82327b501a627b5f6b5aea70a8d3c0f7dc381d40c4cc18df072ef
BLAKE2b-256 checksum
How to use checksums
d557bcfc429df3ce47b6d109ab4432f79cc87fe060510ea4a392dcb18f3bc2e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.12

Release history Release notifications | RSS feed

This release

0.8.1 This release

1 release file

0.8

1 release file

0.5

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page