Skip to content

Tasks

Create and manage monitoring tasks with the Python SDK.

Create Task

The name, search_query, and condition_description are the core parameters:

python
task = client.tasks.create(
    name="iPhone Release Monitor",
    search_query="When is the iPhone 17 being released?",
    condition_description="Apple has announced a specific release date",
)

With all options:

python
from torale.tasks import TaskState

task = client.tasks.create(
    name="iPhone Release Monitor",
    search_query="When is the iPhone 17 being released?",
    condition_description="Apple has announced a specific release date",
    notifications=[
        {"type": "email", "address": "[email protected]"},
        {"type": "webhook", "url": "https://myapp.com/alert"},
    ],
    state=TaskState.ACTIVE,  # or "active" (default)
)

Create Parameters

ParameterTypeRequiredDefaultDescription
namestrYes-Task name
search_querystrYes-Query to monitor
condition_descriptionstrYes-Condition that triggers notification
notificationslist[dict]No[]Notification channels
statestr or TaskStateNo"active""active" or "paused"

Notification Config

Each notification dict has a type field and type-specific fields:

python
# Email notification
{"type": "email", "address": "[email protected]"}

# Webhook notification
{"type": "webhook", "url": "https://myapp.com/alert", "method": "POST", "headers": {"X-Custom": "value"}}

Fluent Builder API

For a more readable syntax, use the fluent builder:

python
# Via client instance
task = (client.monitor("When is iPhone 17 being released?")
    .when("Apple has announced a specific release date")
    .notify(email="[email protected]", webhook="https://myapp.com/alert")
    .named("iPhone Release Monitor")
    .create())

# Create in paused state
task = (client.monitor("Bitcoin price")
    .when("price exceeds $100,000")
    .paused()
    .create())

Or use the standalone monitor() function:

python
from torale import monitor

task = (monitor("Bitcoin price")
    .when("price exceeds $100,000")
    .notify(webhook="https://myapp.com/crypto")
    .create())

The standalone monitor() creates a default Torale client automatically (using env vars or config file for authentication).

Builder Methods

MethodDescription
.when(condition)Set the condition description (required)
.notify(email=..., webhook=...)Add notification channels
.named(name)Set a custom task name
.paused()Create task in paused state
.create()Build and create the task

List Tasks

python
# Get all tasks
tasks = client.tasks.list()

# Filter active only
active_tasks = client.tasks.list(active=True)

# Filter paused only
paused_tasks = client.tasks.list(active=False)

Get Task

python
task = client.tasks.get("task-id")

print(f"Name: {task.name}")
print(f"State: {task.state}")
print(f"Search Query: {task.search_query}")
print(f"Created: {task.created_at}")
print(f"Next Run: {task.next_run}")

Task Fields

Key fields on the returned Task object:

FieldTypeDescription
idUUIDTask ID
namestrTask name
stateTaskState"active", "paused", or "completed"
search_querystrSearch query
condition_descriptionstrTrigger condition
notificationslist[NotificationConfig]Notification channels
created_atdatetimeCreation timestamp
next_rundatetime or NoneNext scheduled execution
last_executionTaskExecution or NoneMost recent execution

Update Task

Only pass the fields you want to change:

python
# Pause task
task = client.tasks.update("task-id", state="paused")

# Resume task
task = client.tasks.update("task-id", state="active")

# Update search query and condition
task = client.tasks.update(
    "task-id",
    search_query="New search query",
    condition_description="New condition",
)

Delete Task

python
client.tasks.delete("task-id")

Execute Immediately

Trigger a manual execution (test run):

python
execution = client.tasks.execute("task-id")
print(f"Status: {execution.status}")

View Executions

python
# Get execution history
executions = client.tasks.executions("task-id")

for execution in executions:
    print(f"Status: {execution.status}")
    print(f"Started: {execution.started_at}")
    if execution.notification:
        print(f"Notification: {execution.notification}")

# Limit results
recent = client.tasks.executions("task-id", limit=5)

View Notifications

Get only executions where the condition was met:

python
notifications = client.tasks.notifications("task-id")

for notif in notifications:
    print(f"Time: {notif.started_at}")
    print(f"Notification: {notif.notification}")
    if notif.grounding_sources:
        print(f"Sources: {len(notif.grounding_sources)}")

Next Steps

Released under the MIT License.