Skip to main content

Installation

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

from activitysmith import ActivitySmith

activitysmith = ActivitySmith(api_key="YOUR-API-KEY")

Usage

  1. Get an API key from ActivitySmith
  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"))

try:
    response = activitysmith.notifications.send_push_notification(
        push_notification_request={
            "title": "Build Failed 🚨",
            "message": "CI pipeline failed on main branch",
        }
    )
    print("Notified:", response.devices_notified)
except Exception as err:
    print("Request failed:", err)

Send a Push Notification

Use activitysmith.notifications.send_push_notification with a push_notification_request payload. title is required; message and subtitle are optional.
Python
response = activitysmith.notifications.send_push_notification(
    push_notification_request={
        "title": "Build Failed 🚨",
        "message": "CI pipeline failed on main branch",
    }
)

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

Start a Live Activity

Start a Live Activity with activitysmith.live_activities.start_live_activity. For a segmented progress activity, include title, number_of_steps, current_step, and type.
Python
start = activitysmith.live_activities.start_live_activity(
    live_activity_start_request={
        "content_state": {
            "title": "ActivitySmith API Deployment",
            "subtitle": "start",
            "number_of_steps": 4,
            "current_step": 1,
            "type": "segmented_progress",
            "color": "yellow",
        }
    }
)

activity_id = start.activity_id

Update a Live Activity

Update a Live Activity with activitysmith.live_activities.update_live_activity. The content_state requires at least title and current_step.
Python
update = activitysmith.live_activities.update_live_activity(
    live_activity_update_request={
        "activity_id": activity_id,
        "content_state": {
            "title": "ActivitySmith API Deployment",
            "subtitle": "npm i & pm2",
            "current_step": 3,
        }
    }
)

print(update.devices_notified)

End a Live Activity

End a Live Activity with activitysmith.live_activities.end_live_activity. You can optionally set auto_dismiss_minutes in the content_state.
Python
end = activitysmith.live_activities.end_live_activity(
    live_activity_end_request={
        "activity_id": activity_id,
        "content_state": {
            "title": "ActivitySmith API Deployment",
            "subtitle": "done",
            "current_step": 4,
            "auto_dismiss_minutes": 3,
        }
    }
)

print(end.success)

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.