Skip to content

About

The first fully typed Python SDK for the Trigger.dev management API

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

triggerdev

PyPI CI Python 3.10+ License: MIT

The first fully typed Python SDK for the Trigger.dev management API. Built with Pydantic v2 models generated from the OpenAPI spec, covering 54 operations across 9 resource domains with both sync and async clients.

Installation

Requires Python 3.10 or later.

uv add triggerdev

Or with pip:

pip install triggerdev

Getting started

Set your Trigger.dev secret key as an environment variable:

export TRIGGER_SECRET_KEY="tr_dev_sk_..."

Then trigger your first task:

from triggerdev import Client

with Client() as client:
    result = client.tasks.trigger("my-task", payload={"user_id": 42})
    print(result.id)

You can also pass the API key explicitly:

client = Client(api_key="tr_dev_sk_...")

Async support

Every method is available on both the sync Client and the AsyncClient:

import asyncio
from triggerdev import AsyncClient

async def main():
    async with AsyncClient() as client:
        result = await client.tasks.trigger("my-task", payload={"user_id": 42})
        print(result.id)

asyncio.run(main())

Features

Trigger tasks

from triggerdev import Client

with Client() as client:
    # Trigger a single task
    result = client.tasks.trigger("send-welcome-email", payload={"user_id": 42})

    # Batch trigger the same task with multiple payloads
    result = client.tasks.batch_trigger("send-welcome-email", items=[
        {"payload": {"user_id": 1}},
        {"payload": {"user_id": 2}},
    ])

List and filter runs

from triggerdev import Client

with Client() as client:
    # List runs with status filter
    runs = client.runs.list(status=["QUEUED", "EXECUTING"])
    for run in runs.data:
        print(f"{run.id}: {run.status}")

    # Retrieve a specific run
    run = client.runs.retrieve("run_1234")
    print(run.task_identifier)

Manage schedules

from triggerdev import Client

with Client() as client:
    schedule = client.schedules.create(
        task="daily-report",
        cron="0 9 * * *",
        deduplication_key="daily-report-prod",
        timezone="America/New_York",
    )
    print(schedule.id)

Sessions

from triggerdev import Client
from triggerdev.types.sessions import CreateSessionRequestBody

with Client() as client:
    # Create a session
    session = client.sessions.create(
        body=CreateSessionRequestBody(
            task_identifier="my-task",
            payload={"key": "value"},
        ),
    )
    print(session.run_id)

    # List sessions with filters
    result = client.sessions.list(status=["RUNNING"], page_size=10)
    for s in result.data:
        print(f"{s.id}: {s.type}")

Webhooks

from triggerdev import Client

with Client() as client:
    # List webhook endpoints
    endpoints = client.webhooks.list_endpoints()
    for ep in endpoints.data:
        print(f"{ep.id}: {ep.status}")

    # List deliveries with status filter
    deliveries = client.webhooks.list_deliveries(status=["FAILED"])
    for d in deliveries.data:
        print(f"{d.id}: {d.status}")

    # Replay a failed delivery
    client.webhooks.replay_delivery(delivery_id="del_123")

Errors

from triggerdev import Client

with Client() as client:
    # List errors for a task
    result = client.errors.list(task_identifier=["my-task"])
    for error in result.data:
        print(f"{error.fingerprint}: {error.error_message} ({error.count}x)")

    # Resolve an error
    client.errors.resolve(error_id="err_123")

Bulk actions

from triggerdev import Client
from triggerdev.types.bulk_actions import BulkActionFilter, CancelByFilterBody

with Client() as client:
    # Cancel runs matching a filter
    action = client.bulk_actions.create(
        body=CancelByFilterBody(
            action="cancel",
            filter=BulkActionFilter(
                task_identifier="my-task",
                status="QUEUED",
            ),
        ),
    )
    print(f"Bulk action created: {action.id}")

Error handling

Every API error maps to a typed exception with automatic retries on transient failures:

from triggerdev import Client, AuthenticationError, NotFoundError, RateLimitError

with Client() as client:
    try:
        run = client.runs.retrieve("run_nonexistent")
    except NotFoundError as e:
        print(f"Not found: {e}")
    except AuthenticationError:
        print("Invalid API key")
    except RateLimitError:
        print("Rate limited, retry later")

Retries are automatic for transient errors (408, 429, 5xx) with exponential backoff and jitter. Configure with max_retries:

client = Client(max_retries=5)  # default is 2

API coverage

Resource Operations Methods
Tasks 3 trigger, batch_trigger, batch_trigger_multi
Runs 11 list, retrieve, result, replay, cancel, reschedule, update_metadata, add_tags, events, trace, trace_paged
Schedules 8 list, create, retrieve, update, delete, activate, deactivate, timezones
Sessions 5 create, list, retrieve, update, close
Batches 2 retrieve, results
Waitpoints 5 create_token, list_tokens, complete_token_callback, complete_token, retrieve_token
Webhooks 11 list/retrieve/enable/disable endpoints, rotate/set secrets, create/cancel waiters, list/retrieve/replay deliveries
Bulk Actions 4 list, create, retrieve, abort
Errors 5 list, retrieve, resolve, ignore, unresolve

Total: 54 operations across 9 resource domains (Tiers 1 and 2 of the Trigger.dev management API).

Requirements

  • Python 3.10+
  • httpx2 (installed automatically)
  • pydantic v2 (installed automatically)

Contributing

Contributions are welcome. See CONTRIBUTING.md for guidelines.

License

MIT

About

The first fully typed Python SDK for the Trigger.dev management API

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages