Skip to main content

Official Python SDK for the Postscale email API

Project description

Postscale Python SDK

Official Python SDK for the Postscale email API.

Install

pip install postscale

Send Email

import os

from postscale import Postscale

postscale = Postscale(os.environ["POSTSCALE_API_KEY"])

result = postscale.emails.send({
    "from": "hello@example.com",
    "to": ["user@example.com"],
    "subject": "Welcome to Postscale",
    "html_body": "<strong>It works.</strong>",
})

if result.error:
    raise RuntimeError(f"{result.error.code}: {result.error.message}")

print(result.data["message_id"])

The SDK keeps Postscale API-native field names. Use html_body, text_body, template_id, and unsubscribe_scope; the MVP SDK does not add html or text aliases.

Attachments

from postscale import Postscale, attachment_from_file

postscale = Postscale()

result = postscale.emails.send({
    "from": "hello@example.com",
    "to": ["user@example.com"],
    "subject": "Invoice",
    "text_body": "Attached.",
    "attachments": [
        attachment_from_file("invoice.pdf", "application/pdf"),
    ],
})

Attachment helpers enforce the documented limits before sending: 10 attachments, 25 MB per attachment, and 50 MB total decoded attachment payload.

Webhook Verification

from postscale import verify_webhook_signature

verified = verify_webhook_signature(
    raw_body,
    request.headers.get("X-Postscale-Signature"),
    [current_secret, previous_secret],
)

if not verified.valid:
    return "invalid", 401

The verifier requires the Postscale signature format: t=<unix_seconds>,v1=<hex_hmac_sha256>, signed over <t>.<raw_body>. It supports multiple v1= signatures and multiple candidate secrets for rotation windows.

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

postscale-1.0.0.tar.gz (39.8 kB view details)

Uploaded Source

Built Distribution

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

postscale-1.0.0-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file postscale-1.0.0.tar.gz.

File metadata

  • Download URL: postscale-1.0.0.tar.gz
  • Upload date:
  • Size: 39.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for postscale-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fd78de8cb1be4f72fc81db4f7f03e8f54a25d4d9f009d9cef3b7e520ee090065
MD5 a4bc15994a88964fb8c41b2869d44f4b
BLAKE2b-256 28e04cf007816a6659d67a1ad5b580783e7611df3c18adcfac3e13f8330e2aef

See more details on using hashes here.

File details

Details for the file postscale-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: postscale-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for postscale-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3557b663cbc41a575f4816a8e9502563f90ed622302215888ee1d5a169980912
MD5 9e21312f49aad38717f7204ccdb78c22
BLAKE2b-256 d9c93769a8858a1a0097a77dd4ef6cb5a7d694865aff0a0b972d59d2d593ecbf

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