Skip to main content

Official Primitive Python SDK for webhook handling and API access

Project description

primitivedotdev

Official Primitive Python SDK.

The default root module is intentionally small and centered on inbound/outbound email automations:

  • primitive.receive(...)
  • primitive.client(...)
  • client.send(...)
  • client.reply(...)
  • client.forward(...)

The generated HTTP API, raw webhook helpers, and lower-level types still remain available for advanced use cases.

Requirements

  • Python >=3.10

Installation

pip install primitivedotdev

Basic usage

Receive and reply

import primitive

client = primitive.client(api_key="prim_test")


def webhook_handler(body: bytes, headers: dict[str, str]) -> dict[str, object]:
    email = primitive.receive(
        body=body,
        headers=headers,
        secret="whsec_...",
    )

    client.reply(email, "Thank you for your email.")
    return {"ok": True}

Send a new email

import primitive

client = primitive.client(api_key="prim_test")

result = client.send(
    from_email="Support <support@example.com>",
    to="alice@example.com",
    subject="Hello",
    body_text="Hi there",
    # Use a unique key per logical send. Reusing a key returns the original
    # response from the first send, which is how retries are deduplicated.
    idempotency_key="customer-key-abc123",
    wait=True,
    wait_timeout_ms=5000,
)

print(result.id, result.status, result.queue_id, result.delivery_status)

send, reply, and forward keep the HTTP request open until Primitive's downstream SMTP transaction completes. In production, configure the client with a request timeout long enough for SMTP delivery, typically 30-60 seconds:

client = primitive.client(api_key="prim_test", timeout=60.0)

About wait mode

When wait=True, the call returns the first downstream SMTP outcome (or wait_timeout_ms, default 30000). Possible terminal delivery_status values:

  • delivered accepted by the receiving MTA
  • bounced rejected by the receiving MTA (the response is still 200 OK)
  • deferred temporary failure, the receiving MTA may retry
  • wait_timeout no outcome was observed in time. Treat as "outcome unknown." The send may still complete after the response returns.

Reply from a different address

reply() defaults the From address to the inbound recipient (the address that received the email). When your verified outbound domain differs from your inbound domain, pass from_email explicitly:

client.reply(
    email,
    "Thanks for your email.",
    from_email="notifications@outbound.example.com",
)

Forward an inbound email

client.forward(
    email,
    to="ops@example.com",
    body_text="Can you take this one?",
)

The normalized email object

primitive.receive(...) returns a normalized inbound email object:

email.sender.address
email.sender.name

email.received_by
email.received_by_all

email.reply_target.address
email.reply_subject
email.forward_subject

email.subject
email.text

email.thread.message_id
email.thread.references

email.raw

Advanced usage

Generated API module

Use primitive.api when you need the full generated HTTP API surface.

from primitive.api import create_client
from primitive.api.api.account.get_account import sync as get_account

client = create_client("prim_test")
account = get_account(client=client)

Lower-level webhook helpers

You can still use the raw helpers directly:

  • handle_webhook(...)
  • parse_webhook_event(...)
  • verify_webhook_signature(...)
  • validate_email_received_event(...)

Development

From sdks/sdk-python:

uv sync --dev
uv run python scripts/generate_schema_module.py
uv run python scripts/generate_models.py
uv run python scripts/generate_api_client.py
uv run pytest
uv run ruff check .
uv run basedpyright

Or from repo root sdks/:

make python-generate
make python-check
make python-build

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

primitivedotdev-0.8.0.tar.gz (98.1 kB view details)

Uploaded Source

Built Distribution

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

primitivedotdev-0.8.0-py3-none-any.whl (158.7 kB view details)

Uploaded Python 3

File details

Details for the file primitivedotdev-0.8.0.tar.gz.

File metadata

  • Download URL: primitivedotdev-0.8.0.tar.gz
  • Upload date:
  • Size: 98.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for primitivedotdev-0.8.0.tar.gz
Algorithm Hash digest
SHA256 fb2c72c6528cba23c5edc7682f945502b07b760ca693fa2ab07165e43a240d9e
MD5 125040cc56b00f0fb94069ac828056d4
BLAKE2b-256 18f1ecd180be8dade873e0e8cf62999c7664ea97fa8e0931809027309934730f

See more details on using hashes here.

Provenance

The following attestation bundles were made for primitivedotdev-0.8.0.tar.gz:

Publisher: python-release.yml on primitivedotdev/sdks

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

File details

Details for the file primitivedotdev-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: primitivedotdev-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 158.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for primitivedotdev-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 37bdae1632ddbd36398042e163c2f61b57c980167cc6aebef599df88e5d6196d
MD5 adf59a3bab0bbc0555230590107bb76d
BLAKE2b-256 d6730d58f0ec6742bec753aa27531be962a0d9a2ffa6b73c1517ce6d7ecd1d36

See more details on using hashes here.

Provenance

The following attestation bundles were made for primitivedotdev-0.8.0-py3-none-any.whl:

Publisher: python-release.yml on primitivedotdev/sdks

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