Todoist API Python SDK

4.0.0 · active · verified Fri Apr 17

The official Python SDK for interacting with the Todoist API. It provides synchronous and asynchronous clients to manage tasks, projects, labels, filters, and more. The current stable version is 4.0.0, and it generally receives updates aligned with API changes and new features from Todoist.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes the Todoist API client using an API token (preferably from an environment variable). It then fetches all projects and creates a new task, demonstrating basic read and write operations. Remember to replace 'YOUR_API_TOKEN_HERE' or set the TODOIST_API_TOKEN environment variable.

import os
from todoist_api_python.api import TodoistAPI

# Get your Todoist API token from environment variables or provide directly
api_token = os.environ.get('TODOIST_API_TOKEN', 'YOUR_API_TOKEN_HERE')

if not api_token or api_token == 'YOUR_API_TOKEN_HERE':
    print("Warning: TODOIST_API_TOKEN environment variable not set. Using placeholder.")
    # In a real application, you would raise an error or exit.

api = TodoistAPI(api_token)

try:
    # Fetch all active projects
    projects = api.get_projects()
    print(f"Successfully fetched {len(projects)} projects:")
    for project in projects[:3]: # Print first 3 projects
        print(f"- {project.name} (ID: {project.id})")

    # Create a new task
    new_task = api.add_task(
        content="Buy groceries",
        project_id=projects[0].id if projects else None, # Assign to first project if available
        due_string="tomorrow",
        priority=4
    )
    print(f"\nCreated new task: {new_task.content} (ID: {new_task.id})")

except Exception as error:
    print(f"An error occurred: {error}")

view raw JSON →