Skip to content

Latest commit

 

History

History
133 lines (95 loc) · 3.3 KB

README.md

File metadata and controls

133 lines (95 loc) · 3.3 KB

triggerdev

PyPI CI Python 3.10+ License: MIT

The first fully typed Python SDK for the Trigger.dev management API. Built with Pydantic models generated from the OpenAPI spec, covering tasks, runs, and schedules.

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_...")

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:
    # Create a recurring schedule
    schedule = client.schedules.create(
        task="daily-report",
        cron="0 9 * * *",
        deduplication_key="daily-report-prod",
        timezone="America/New_York",
    )
    print(schedule.id)

    # List all schedules
    schedules = client.schedules.list()
    for s in schedules.data:
        print(f"{s.task}: {s.generator.expression}")

Error handling

Every API error maps to a typed exception:

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")

Requirements

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

Contributing

Contributions are welcome. See CONTRIBUTING.md for guidelines.

License

MIT