Todoist API Python SDK
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
-
ImportError: cannot import name 'TodoistAPI' from 'todoist_api_python'
cause Attempting to import `TodoistAPI` directly from the top-level package, which was the pattern in v2.x.x.fixUpdate the import statement to `from todoist_api_python.api import TodoistAPI` as per v3.0.0 and later. -
TypeError: TodoistAPI() missing 1 required positional argument: 'token'
cause The `TodoistAPI` client was initialized without providing the API token.fixProvide your Todoist API token as the first argument when initializing the client, e.g., `api = TodoistAPI('YOUR_API_TOKEN')` or `api = TodoistAPI(os.environ.get('TODOIST_API_TOKEN'))`. -
This app requires Python 3.10.0 or later.
cause Running `todoist-api-python` version 4.0.0 or higher with a Python interpreter older than 3.10.fixUpgrade your Python environment to 3.10 or newer. Alternatively, if you cannot upgrade Python, install an older version of the library (e.g., `pip install todoist-api-python<4.0.0`). -
AttributeError: 'TodoistAPI' object has no attribute 'add_item'
cause Attempting to use old method names from v2.x.x, specifically `add_item` which was renamed in v3.0.0.fixUpdate the method call to the new naming convention. `add_item` is now `create_task`. Similarly, `update_item` is `update_task`, and `add_project` is `create_project`, etc.
Warnings
- breaking Major architectural changes in v3.0.0, including switching from `requests` to `httpx` as the internal HTTP client, moving API classes to `todoist_api_python.api`, and renaming most `add_*` methods to `create_*` and `update_item` to `update_task`.
- breaking Version 4.0.0 and above require Python 3.10 or higher. Previous versions (3.x.x) required Python 3.8+.
- gotcha The SDK provides both synchronous (`TodoistAPI`) and asynchronous (`TodoistAPIAsync`) clients. Ensure you use the correct client for your application's concurrency model. The async client methods must be awaited within an `async def` function.
- gotcha The `project_id` parameter when creating a task (using `add_task` or `create_task`) can be `None` to add the task to the user's inbox, or a string ID for a specific project. If providing an invalid ID, the API will silently add it to the inbox.
Install
-
pip install todoist-api-python
Imports
- TodoistAPI
from todoist_api_python import TodoistAPI
from todoist_api_python.api import TodoistAPI
- TodoistAPIAsync
from todoist_api_python import TodoistAPIAsync
from todoist_api_python.api import TodoistAPIAsync
Quickstart
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}")