Skip to main content
This guide walks you through defining your first task, registering it on a worker, and triggering it from your application.

Prerequisites

You need a running Hatchet instance and an API token. The fastest way is to sign up on Hatchet Cloud — or run Hatchet locally:
curl -fsSL https://install.hatchet.run/install.sh | bash
hatchet server start
Once running, open the dashboard, navigate to Settings → API Tokens, and create a new token.

Step 1 — Install the SDK

pip install hatchet-sdk

Step 2 — Set your token

Set the HATCHET_CLIENT_TOKEN environment variable to the API token you created:
export HATCHET_CLIENT_TOKEN="<your-token-here>"
For a self-hosted instance, also set the server address:
export HATCHET_CLIENT_HOST_PORT="localhost:7077"

Step 3 — Define a task

workflows/first_task.py
from pydantic import BaseModel
from hatchet_sdk import Context, Hatchet

hatchet = Hatchet()

class SimpleInput(BaseModel):
    message: str

class SimpleOutput(BaseModel):
    transformed_message: str

@hatchet.task(name="first-task", input_validator=SimpleInput)
def first_task(input: SimpleInput, ctx: Context) -> SimpleOutput:
    print("first-task task called")
    return SimpleOutput(transformed_message=input.message.lower())

Step 4 — Start a worker

worker.py
from hatchet_sdk import Hatchet
from workflows.first_task import first_task

hatchet = Hatchet()

def main():
    worker = hatchet.worker(
        "first-worker",
        slots=10,
        workflows=[first_task],
    )
    worker.start()

if __name__ == "__main__":
    main()
Run the worker in a terminal:
python worker.py

Step 5 — Trigger the task

In a separate terminal (or from your application), trigger the task:
run.py
import asyncio
from workflows.first_task import SimpleInput, first_task

async def main():
    result = await first_task.aio_run(SimpleInput(message="Hello World!"))
    print("Transformed message:", result.transformed_message)

asyncio.run(main())
You should see the task execute in your worker terminal, and the result printed in your trigger terminal.

What’s next

Your first task

Deep dive into task options: retries, timeouts, concurrency, and more

DAG workflows

Chain tasks together into multi-step workflows with dependencies

Flow control

Rate limits and per-user concurrency to protect your system

Dashboard

Monitor and debug your tasks in the real-time web UI

Build docs developers (and LLMs) love