|
1 | 1 | # Todoist API Python Client
|
2 | 2 |
|
3 |
| -This is the official Python API client for the Todoist REST API. |
| 3 | +This is the official Python SDK for the Todoist API. |
4 | 4 |
|
5 |
| -### Installation |
| 5 | +## Installation |
6 | 6 |
|
7 |
| -The repository can be included as a dependency in `pyproject.toml`. |
8 |
| -It is best to integrate to a release tag to ensure a stable dependency: |
| 7 | +```bash |
| 8 | +pip install todoist-api-python |
| 9 | +``` |
| 10 | + |
| 11 | +Or add the project as a dependency in `pyproject.toml`: |
9 | 12 |
|
10 | 13 | ```toml
|
11 | 14 | dependencies = [
|
12 |
| - ... |
13 | 15 | "todoist-api-python>=3.0.0,<4",
|
14 |
| - ... |
15 | 16 | ]
|
16 | 17 | ```
|
17 | 18 |
|
18 | 19 | ### Supported Python Versions
|
19 | 20 |
|
20 | 21 | While we only actively test under Python 3.13, we strive to support all versions from Python 3.9 and above.
|
21 | 22 |
|
22 |
| -### Usage |
| 23 | +## Usage |
23 | 24 |
|
24 |
| -An example of initializing the API client and fetching a user's tasks: |
| 25 | +Here's an example of initializing the API client, fetching a task, and paginating through its comments: |
25 | 26 |
|
26 | 27 | ```python
|
27 |
| -from todoist_api_python.api_async import TodoistAPIAsync |
28 | 28 | from todoist_api_python.api import TodoistAPI
|
29 | 29 |
|
30 |
| -# Fetch tasks synchronously |
31 |
| -def get_tasks_sync(): |
32 |
| - api = TodoistAPI("my token") |
33 |
| - try: |
34 |
| - tasks = api.get_tasks() |
35 |
| - print(tasks) |
36 |
| - except Exception as error: |
37 |
| - print(error) |
38 |
| - |
39 |
| -# Fetch tasks asynchronously |
40 |
| -async def get_tasks_async(): |
41 |
| - api = TodoistAPIAsync("YOURTOKEN") |
42 |
| - try: |
43 |
| - tasks = await api.get_tasks() |
44 |
| - print(tasks) |
45 |
| - except Exception as error: |
46 |
| - print(error) |
47 |
| -``` |
48 |
| - |
49 |
| -Example of paginating through a completed project tasks: |
50 |
| - |
51 |
| -```python |
52 |
| -def get_all_completed_items(original_params: dict): |
53 |
| - params = original_params.copy() |
54 |
| - results = [] |
55 |
| - |
56 |
| - while True: |
57 |
| - response = api.get_completed_items(**(params | {"limit": 100})) |
58 |
| - results.append(response.items) |
59 |
| - |
60 |
| - if not response.has_more: |
61 |
| - break |
62 |
| - |
63 |
| - params["cursor"] = response.next_cursor |
| 30 | +api = TodoistAPI("YOUR_API_TOKEN") |
64 | 31 |
|
65 |
| - # flatten the results |
66 |
| - return [item for sublist in results for item in sublist] |
| 32 | +task = api.get_task("6X4Vw2Hfmg73Q2XR") |
| 33 | +print(f"Task: {task.content}") |
67 | 34 |
|
68 |
| -items = get_all_completed_items({"project_id": 123}) |
| 35 | +comments_iter = api.get_comments(task_id=task.id) |
| 36 | +for comments in comments_iter: |
| 37 | + for comment in comments: |
| 38 | + print(f"Comment: {comment.content}") |
69 | 39 | ```
|
70 | 40 |
|
71 |
| -### Documentation |
| 41 | +## Documentation |
72 | 42 |
|
73 |
| -For more detailed reference documentation, have a look at the [API documentation with Python examples](https://developer.todoist.com/rest/v2/?python). |
| 43 | +For more detailed reference documentation, have a look at the [SDK documentation](https://doist.github.io/todoist-api-python/) and the [API documentation](https://developer.todoist.com). |
74 | 44 |
|
75 |
| -### Development |
| 45 | +## Development |
76 | 46 |
|
77 | 47 | To install Python dependencies:
|
78 | 48 |
|
@@ -104,10 +74,10 @@ A new update is automatically released by GitHub Actions, by creating a release
|
104 | 74 |
|
105 | 75 | Users of the API client can then update to the new version in their `pyproject.toml` file.
|
106 | 76 |
|
107 |
| -### Feedback |
| 77 | +## Feedback |
108 | 78 |
|
109 |
| -Any feedback, such as bugs, questions, comments, etc. can be reported as *Issues* in this repository, and will be handled by Doist. |
| 79 | +Any feedback, bugs, questions, comments, etc., can be reported as *Issues* in this repository. |
110 | 80 |
|
111 | 81 | ### Contributions
|
112 | 82 |
|
113 |
| -We would love contributions in the form of *Pull requests* in this repository. |
| 83 | +We would love contributions! *Pull requests* are welcome. |
0 commit comments