Svix Python Library

1.90.0 · active · verified Fri Apr 10

The Svix Python library provides a robust client for interacting with the Svix webhooks API, enabling developers to send, receive, and verify webhooks. It abstracts away complexities like retries, scaling, and security, offering both synchronous and asynchronous interfaces. The library supports Python 3.6+ and includes PEP 484 type hints. Svix aims to simplify webhook infrastructure, allowing applications to integrate webhook capabilities rapidly. It is actively maintained with regular updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Svix client (both synchronous and asynchronous), create an application, and send a message. Replace `SVIX_AUTH_TOKEN` with your actual authentication token, typically obtained from the Svix dashboard.

import os
from svix.api import Svix, ApplicationIn, MessageIn

AUTH_TOKEN = os.environ.get('SVIX_AUTH_TOKEN', 'auth-token-placeholder') # Replace with your actual token or env var

async def main_async():
    svix_async = SvixAsync(AUTH_TOKEN)
    print("Creating application (async)...")
    app = await svix_async.application.create(ApplicationIn(name="My Async App"))
    print(f"Application created: {app.id}")
    
    print("Sending message (async)...")
    message = await svix_async.message.create(app.id, MessageIn(event_type="user.created", payload={'user_id': '123'}))
    print(f"Message sent: {message.id}")

def main_sync():
    svix_sync = Svix(AUTH_TOKEN)
    print("Creating application (sync)...")
    app = svix_sync.application.create(ApplicationIn(name="My Sync App"))
    print(f"Application created: {app.id}")
    
    print("Sending message (sync)...")
    message = svix_sync.message.create(app.id, MessageIn(event_type="user.created", payload={'user_id': '456'}))
    print(f"Message sent: {message.id}")

if __name__ == '__main__':
    # Example for synchronous usage
    main_sync()

    # Example for asynchronous usage (requires an async event loop)
    # import asyncio
    # asyncio.run(main_async())

view raw JSON →