Skip to main content

PYRX Synapse Python SDK — async + sync client for event tracking, contacts, and email

Project description

pyrx-synapse

Python SDK for the PYRX Synapse customer communications platform. Provides both synchronous and asynchronous clients for event tracking, contact management, email sending, and template management.

Install

pip install pyrx-synapse

Quick Start

Sync

from pyrx_synapse import Synapse

with Synapse(api_key="gck_live_xxx", workspace_id="ws_xxx") as client:
    # Track an event
    client.track(external_id="user_123", event_name="purchase", attributes={"amount": 99.99})

    # Identify a contact
    client.identify(external_id="user_123", email="jane@example.com", properties={"tier": "pro"})

    # Send a transactional email
    client.send(
        template_slug="welcome",
        to={"user_id": "user_123", "email": "jane@example.com"},
        attributes={"first_name": "Jane"},
    )

    # Manage contacts
    contacts = client.contacts.list(search="jane", page=1, per_page=50)
    contact = client.contacts.get(contact_id="uuid")
    client.contacts.update("user_123", {"properties": {"tier": "enterprise"}})
    client.contacts.delete("user_123")

    # Manage templates
    templates = client.templates.list()
    template = client.templates.get("welcome")
    preview = client.templates.preview("welcome", {"contact": {"first_name": "Jane"}, "event": {}})

Async

from pyrx_synapse import AsyncSynapse

async with AsyncSynapse(api_key="gck_live_xxx", workspace_id="ws_xxx") as client:
    await client.track(external_id="user_123", event_name="purchase")
    await client.identify(external_id="user_123", email="jane@example.com")
    await client.send(template_slug="welcome", to={"user_id": "u1", "email": "j@ex.com"})

Webhook Verification

from pyrx_synapse import verify_webhook

event = verify_webhook(
    payload=request.body,
    headers={
        "svix-id": request.headers["svix-id"],
        "svix-timestamp": request.headers["svix-timestamp"],
        "svix-signature": request.headers["svix-signature"],
    },
    secret="whsec_xxx",
)
print(event["type"])  # e.g. "contact.created"

Error Handling

from pyrx_synapse import (
    Synapse,
    SynapseAuthError,
    SynapseRateLimitError,
    SynapsePlanLimitError,
    SynapseValidationError,
    SynapseError,
)

with Synapse(api_key="gck_live_xxx", workspace_id="ws_xxx") as client:
    try:
        client.track(external_id="u1", event_name="purchase")
    except SynapseAuthError as e:
        print(f"Auth failed: {e.message}")          # 401 or 403
    except SynapseRateLimitError as e:
        print(f"Rate limited, retry after {e.retry_after}s")  # 429
    except SynapsePlanLimitError as e:
        print(f"Plan limit: {e.limit_type} ({e.current}/{e.maximum})")  # 403
    except SynapseValidationError as e:
        print(f"Validation: {e.errors}")             # 422
    except SynapseError as e:
        print(f"API error {e.status}: {e.message}")  # Other

Configuration

Parameter Default Description
api_key (required) Your API key (gck_live_... or gck_test_...)
workspace_id (required) Your workspace ID
base_url https://synapse-api.pyrx.tech API base URL
timeout 30.0 Request timeout in seconds
max_retries 3 Max retry attempts for retryable errors

Retryable status codes: 429, 500, 502, 503, 504. Backoff: exponential with jitter, capped at 30s. On 429, uses Retry-After header when present.

API Reference

See PYRX Synapse API docs.

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

pyrx_synapse-0.1.0.tar.gz (41.0 kB view details)

Uploaded Source

Built Distribution

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

pyrx_synapse-0.1.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyrx_synapse-0.1.0.tar.gz
  • Upload date:
  • Size: 41.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyrx_synapse-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9cc26eb3508977fbcc3aa6df8d7ab5dab14aaa9c6d9667bbeeb4663769905f83
MD5 fe99c3f771fe10ce7df91dbcd6d7820b
BLAKE2b-256 77ec51b6c9d041631f10b10f6a1c02374a5047ce7f425a2657ed6e940e40d3b3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyrx_synapse-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyrx_synapse-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 300c60e78fb4254641916be6096199964f80a0ab885957feefa0a6595d632a9d
MD5 53259c12180c5d09b4535a72081195d4
BLAKE2b-256 e9210c5291582718d0a56ef7590c942e3c734469a2b95b1e311a34b85fa4416f

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