Common patterns for working with pytaskwarrior.
from taskwarrior import TaskWarrior, TaskInputDTO
tw = TaskWarrior()
task = TaskInputDTO(description="Buy groceries")
added = tw.add_task(task)
print(f"Created: {added.uuid}")from taskwarrior import TaskInputDTO, Priority
task = TaskInputDTO(
description="Finish report",
priority=Priority.HIGH,
tags=["work", "urgent"],
)
tw.add_task(task)task = TaskInputDTO(
description="Submit proposal",
due="friday", # TaskWarrior date expression
project="sales",
)
tw.add_task(task)TaskWarrior supports many date expressions:
tomorrow,yesterday,todaymonday,friday(next occurrence)eom(end of month),eoy(end of year)now + 2weeks,today + 3days
tasks = tw.get_tasks()
for task in tasks:
print(f"[{task.priority or '-'}] {task.description}")# By project
work_tasks = tw.get_tasks("project:work")
# By tag
urgent = tw.get_tasks("+urgent")
# Tags - helpers
# Get all tags in the system
all_tags = tw.get_tags() # e.g. ['work', 'urgent']
# Get tags following the context convention (start with '@')
context_tags = tw.get_context_tags() # e.g. ['@home', '@work']
# Complex filter
overdue = tw.get_tasks("due.before:today status:pending")# By ID (integer)
task = tw.get_task(1)
# By UUID
task = tw.get_task("abc123-def456-...")from taskwarrior import task_output_to_input, Priority
# Get the task
task = tw.get_task(uuid)
# Convert to input DTO
input_dto = task_output_to_input(task)
# Make changes
input_dto.priority = Priority.HIGH
input_dto.tags.append("reviewed")
# Save
tw.modify_task(input_dto, uuid)# Start working on a task (sets start time)
tw.start_task(uuid)
# Stop working (clears start time)
tw.stop_task(uuid)
# Mark as complete
tw.done_task(uuid)
# Delete (soft delete, can be undone)
tw.delete_task(uuid)
# Purge (permanent deletion)
tw.purge_task(uuid)Add notes to tasks:
task = tw.add_task(TaskInputDTO(description="Research topic"))
tw.annotate_task(task.uuid, "Found good article at example.com")
tw.annotate_task(task.uuid, "Discussed with team")
# Retrieve annotations
task = tw.get_task(task.uuid)
for ann in task.annotations:
print(f"{ann.entry}: {ann.description}")Use TaskWarrior's date calculation engine:
# Calculate a date expression
result = tw.task_calc("today + 2weeks")
print(result) # "2026-02-14T00:00:00"
# Validate a date expression
if tw.date_validator("next monday"):
print("Valid date expression")