Skip to main content

Installation

To install the ActivitySmith Python SDK, you can use pip:
Python
pip install activitysmith

Usage

  1. Create an API key
  2. Set the API key as an environment variable named ACTIVITYSMITH_API_KEY or pass it as a parameter to the ActivitySmith class.
Here’s an example of how to use the SDK with error handling:
Python
import os
from activitysmith import ActivitySmith

activitysmith = ActivitySmith(api_key=os.environ.get("ACTIVITYSMITH_API_KEY", "YOUR-API-KEY"))

Send a Push Notification

Use activitysmith.notifications.send with a push payload. title is required; message and subtitle are optional. Push Notification
Python
response = activitysmith.notifications.send(
    {
        "title": "New subscription 💸",
        "message": "Customer upgraded to Pro plan",
    }
)

print(response.success)
print(response.devices_notified)

Start a Live Activity

Start a Live Activity with activitysmith.live_activities.start. For segmented_progress, include title, number_of_steps, current_step, and type. For progress, include title, type: "progress", and either percentage or value plus upper_limit. Start Live Activity
Python
start = activitysmith.live_activities.start(
    {
        "content_state": {
            "title": "Nightly database backup",
            "subtitle": "create snapshot",
            "number_of_steps": 3,
            "current_step": 1,
            "type": "segmented_progress",
            "color": "yellow",
        }
    }
)

activity_id = start.activity_id
Progress type
Python
start = activitysmith.live_activities.start(
    {
        "content_state": {
            "title": "EV Charging",
            "subtitle": "Added 30 mi range",
            "percentage": 15,
            "type": "progress",
            "color": "lime",
        }
    }
)

activity_id = start.activity_id

Update a Live Activity

Update a Live Activity with activitysmith.live_activities.update. Segmented updates require title and current_step. Progress updates require title plus percentage or value with upper_limit. Update Live Activity
Python
update = activitysmith.live_activities.update(
    {
        "activity_id": activity_id,
        "content_state": {
            "title": "Nightly database backup",
            "subtitle": "upload archive",
            "current_step": 2,
        }
    }
)

print(update.devices_notified)
Progress type
Python
update = activitysmith.live_activities.update(
    {
        "activity_id": activity_id,
        "content_state": {
            "title": "EV Charging",
            "subtitle": "Added 120 mi range",
            "percentage": 60,
        }
    }
)

print(update.devices_notified)

End a Live Activity

End a Live Activity with activitysmith.live_activities.end. You can optionally set auto_dismiss_minutes in the content_state. End Live Activity
Python
end = activitysmith.live_activities.end(
    {
        "activity_id": activity_id,
        "content_state": {
            "title": "Nightly database backup",
            "subtitle": "verify restore",
            "current_step": 3,
            "auto_dismiss_minutes": 2,
        }
    }
)

print(end.success)
Progress type
Python
end = activitysmith.live_activities.end(
    {
        "activity_id": activity_id,
        "content_state": {
            "title": "EV Charging",
            "subtitle": "Added 200 mi range",
            "percentage": 100,
            "auto_dismiss_minutes": 2,
        }
    }
)

print(end.success)

Channels

You can target specific channels when sending a push or starting a Live Activity.
Python
activitysmith.notifications.send(
    {
        "title": "New subscription 💸",
        "message": "Customer upgraded to Pro plan",
        "channels": ["ios-builds", "engineering"],
    }
)

activitysmith.live_activities.start(
    {
        "channels": ["ios-builds"],
        "content_state": {
            "title": "Nightly database backup",
            "number_of_steps": 3,
            "current_step": 1,
            "type": "segmented_progress",
        },
    }
)

Error Handling

The SDK raises exceptions for non-2xx responses. Rate limit errors use the error and message fields, and Live Activity limits include limit and active. See Rate Limits for details.

Additional Resources