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.1.tar.gz (41.1 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.1-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyrx_synapse-0.1.1.tar.gz
  • Upload date:
  • Size: 41.1 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.1.tar.gz
Algorithm Hash digest
SHA256 9a8e030b5cc5cf7c480b3f9a626b7161902a07d67d2f086cf0b7e0a1d1ec5745
MD5 3452a6a753fc73579ae317152cd33bc5
BLAKE2b-256 3ad718b92cb7bdeb423a8e25286b80c8cad730fd3db40b0d110809afcf54ff03

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyrx_synapse-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1293407350d798f4c51702586b155a86c5fbf0c7f0f510042b81c7428b64134
MD5 60c7ca6632144c2550c9632e79f5a7d7
BLAKE2b-256 2cd7c86832cb22bc6e9ee0dc999c8df1d693a522e755b7e02295ec21e59a6af7

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