Skip to main content

Zero-dependency Python client for the Posthorn HTTP API

Project description

python-posthorn

Zero-dependency Python client for Posthorn's HTTP API.

Install locally

pip install -e ./python-posthorn

Basic usage

from python_posthorn import PosthornClient

client = PosthornClient(
    "http://localhost:8888",
    "your-api-key",
    default_path="/api/transactional",
)

response = client.send({"message": "hello"})
print(response)

[!NOTE] The endpoint path and required payload fields are configured per deployment and not fixed by this client. For example, the deployment at example.com:8080 exposes its send endpoint at /api/send and requires both message and subject_line:

client = PosthornClient(
    "http://example.com:8080",
    "your-api-key",
    default_path="/api/send",
)

response = client.send({"message": "hello", "subject_line": "Greetings"})

Check with the operator of your Posthorn instance for its configured path and required fields.

Setting the recipient

In API-key mode, each endpoint has a configured recipient (to) list — the payload does not need a to or email field for that. To send to a different recipient for a single request, set the reserved to_override field to a string or a list of email addresses:

response = client.send({
    "message": "hello",
    "subject_line": "Greetings",
    "to_override": "alice@example.com",
})

to_override only overrides recipients; the sender identity is fixed by the endpoint configuration and cannot be overridden per-request.

Features

  • GET /healthz
  • GET /metrics
  • authenticated JSON send requests
  • Idempotency-Key support
  • typed 200 success and dry-run responses
  • typed 422 validation errors
  • explicit exception classes for 401, 409, 429, and 502

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

python_posthorn-0.6.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file python_posthorn-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_posthorn-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2711f61c16d9f621e673bc69fb3bc0133f22d30b7b89c88e7a37a374cbf69a05
MD5 df94f90788d3b36d8f8b858abb1fa7cf
BLAKE2b-256 3f6f37a68c2a80bb1a34107ffa2fc08967ece514af660556cb9a3f499566a8d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_posthorn-0.6.0-py3-none-any.whl:

Publisher: pypi-publish.yml on monperrus/python-posthorn

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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