Skip to main content

Python SDK for Antonnia Apps API

Project description

Antonnia Events

Python SDK for Antonnia Events and Webhooks

Overview

The antonnia-events package provides type-safe event definitions for Antonnia webhook events. It's part of the Antonnia Python SDK ecosystem and works seamlessly with other Antonnia packages.

Installation

pip install antonnia-events

Note: This package has a dependency on antonnia-conversations for the underlying data types.

Quick Start

from antonnia.events import Event, MessageCreated, SessionCreated

# Parse webhook events
def handle_webhook(event_data: dict):
    event = Event.model_validate(event_data)
    
    if isinstance(event, MessageCreated):
        print(f"New message: {event.data.object.id}")
    elif isinstance(event, SessionCreated):
        print(f"New session: {event.data.object.id}")

Event Types

Available Events

  • MessageCreated - Fired when a new message is created
  • SessionCreated - Fired when a new session is created
  • SessionFinished - Fired when a session is finished
  • SessionTransferred - Fired when a session is transferred

Event Structure

All events inherit from EventBase and have this structure:

{
    "id": "event_123",
    "created_at": "2023-12-01T12:00:00Z",
    "type": "message.created",
    "data": {
        "object": {
            # The actual Message or Session object
        }
    }
}

Usage with Frameworks

FastAPI

from fastapi import FastAPI
from antonnia.events import Event

app = FastAPI()

@app.post("/webhook")
async def handle_webhook(event: Event):
    # Event is automatically validated and parsed
    return {"status": "received"}

Flask

from flask import Flask, request
from antonnia.events import Event

app = Flask(__name__)

@app.route("/webhook", methods=["POST"])
def handle_webhook():
    event = Event.model_validate(request.json)
    # Handle the event
    return {"status": "received"}

Type Safety

The package provides full type safety with discriminated unions:

from antonnia.events import Event, MessageCreated

def process_event(event: Event):
    # Type checker knows the event type based on isinstance check
    if isinstance(event, MessageCreated):
        # event.data.object is typed as Message
        message = event.data.object
        print(f"Message content: {message.content}")

Development

Installing for Development

pip install -e .[dev]

Running Tests

pytest

Code Formatting

black .
isort .

Type Checking

mypy .

License

MIT License - see LICENSE file for details.

Related Packages

Support

For support, please visit https://antonnia.com/support or create an issue in our GitHub repository.

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

antonnia_apps-1.0.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

antonnia_apps-1.0.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file antonnia_apps-1.0.1.tar.gz.

File metadata

  • Download URL: antonnia_apps-1.0.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for antonnia_apps-1.0.1.tar.gz
Algorithm Hash digest
SHA256 77846d6cfea8c8f57d53435ace930fc5d17d381f10a027cf278da53e33f16503
MD5 b1456f9c0abd7fdfc91c1f7d9a913923
BLAKE2b-256 5853ff01efdaf8b9f5686b97e0ebe01f5d424d052b8bed6eecac98395e9df4b0

See more details on using hashes here.

File details

Details for the file antonnia_apps-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: antonnia_apps-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for antonnia_apps-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dea965d95562b3cc8c2c03dd1ea6a8695a254df241c0bcf20862a4daa8a29e6a
MD5 3ce797c810ae5bcd4b900ad40b031dc2
BLAKE2b-256 3d8d1fde52029a29959df2628354e55cb3c342d3893e12903b0fc1c6838fc478

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