Skip to content

Commit f285c3f

Browse files
authored
pagination & incremental support for updates fetch (#15)
* updates fetch pagination and filtering * updates fetch pagination and filtering, improved * minor version bump * readme updates * retrieve updated_at
1 parent 41108fd commit f285c3f

File tree

5 files changed

+47
-23
lines changed

5 files changed

+47
-23
lines changed

README.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,11 @@ The SDK provides structured types to help you work with API responses more effec
102102

103103
Here is an example of how to use these types with the SDK to deserialize API responses:
104104
```python
105-
from monday_sdk import MondayClient, MondayApiResponse
106-
import dacite
105+
from monday_sdk import MondayClient
107106

108107
client = MondayClient(token="your_token")
109-
110-
# Fetch the raw response data
111-
response_data = client.boards.fetch_all_items_by_board_id(board_id="your_board_id")
112-
113-
# Deserialize the response data into typed objects
114-
monday_response = dacite.from_dict(data_class=MondayApiResponse, data=response_data)
115-
116-
# Access specific fields using the deserialized objects
117-
first_board = monday_response.data.boards[0]
118-
first_item_name = first_board.items_page.items[0].name
119-
108+
items = client.boards.fetch_all_items_by_board_id(board_id="your_board_id")
109+
first_item_name = items[0].name
120110
print(f"First item name: {first_item_name}")
121111
```
122112
By using these types, you can ensure type safety and better code completion support in your IDE, making your work with the Monday API more efficient and error-free.

setup.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
setup(
1717
name="monday-api-python-sdk", # Required
18-
version="1.1.3", # Required
18+
version="1.2.3", # Required
1919
description="A Python SDK for interacting with Monday's GraphQL API", # Optional
2020
long_description=long_description, # Optional
2121
long_description_content_type="text/markdown", # Optional (see note above)
@@ -24,12 +24,7 @@
2424
author_email="[email protected]",
2525
license_files=("LICENSE",),
2626
classifiers=[ # Optional
27-
# How mature is this project? Common values are
28-
# 3 - Alpha
29-
# 4 - Beta
30-
# 5 - Production/Stable
31-
"Development Status :: 3 - Alpha",
32-
# Indicate who your project is intended for
27+
"Development Status :: 5 - Production/Stable",
3328
"Intended Audience :: Developers",
3429
"Topic :: Software Development :: Build Tools",
3530
# Pick your license as you wish

src/monday_sdk/modules/updates.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from typing import List
1+
from datetime import datetime
2+
from typing import List, Optional
23

34
from ..query_templates import create_update_query, delete_update_query, get_update_query, get_updates_for_item_query, get_updates_for_board
45
from ..types import MondayApiResponse, Update
56
from ..graphql_handler import MondayGraphQL
67

7-
88
class UpdateModule(MondayGraphQL):
99
def create_update(self, item_id, update_value) -> MondayApiResponse:
1010
query = create_update_query(item_id, update_value)
@@ -22,7 +22,44 @@ def fetch_updates_for_item(self, item_id, limit=100) -> MondayApiResponse:
2222
query = get_updates_for_item_query(item_id=item_id, limit=limit)
2323
return self.execute(query)
2424

25-
def fetch_board_updates(self, board_id, limit=100, page=1) -> List[Update]:
25+
def fetch_board_updates_page(self, board_id, limit=100, page=1) -> List[Update]:
2626
query = get_updates_for_board(board_id, limit, page)
2727
response: MondayApiResponse = self.execute(query)
2828
return response.data.boards[0].updates
29+
30+
def fetch_board_updates(
31+
self,
32+
board_ids: str,
33+
updated_after: Optional[str] = None,
34+
updated_before: Optional[str] = None,
35+
) -> List[Update]:
36+
"""
37+
Fetches all updates from a board (with optional date filtering).
38+
- Paginates through all pages until no more updates.
39+
- If from_date or to_date are provided, filters out updates outside that window.
40+
"""
41+
start_dt = datetime.fromisoformat(updated_after) if updated_after else None
42+
end_dt = datetime.fromisoformat(updated_before) if updated_before else None
43+
44+
all_updates = []
45+
page = 1
46+
47+
while True:
48+
updates = self.fetch_board_updates_page(board_ids, page=page)
49+
if not updates:
50+
break
51+
52+
if start_dt or end_dt:
53+
updates = [
54+
u for u in updates
55+
if (
56+
u.updated_at
57+
and (start_dt is None or datetime.fromisoformat(u.updated_at) >= start_dt)
58+
and (end_dt is None or datetime.fromisoformat(u.updated_at) <= end_dt)
59+
)
60+
]
61+
62+
all_updates.extend(updates)
63+
page += 1
64+
65+
return all_updates

src/monday_sdk/query_templates.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ def get_updates_for_board(board_id, limit: int, page=1):
552552
id,
553553
text_body,
554554
item_id,
555+
updated_at,
555556
created_at,
556557
creator {
557558
name,

src/monday_sdk/types/api_response_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Update:
4646
text_body: Optional[str] = field(default=None)
4747
item_id: Optional[str] = field(default=None)
4848
created_at: Optional[str] = field(default=None)
49+
updated_at: Optional[str] = field(default=None)
4950
creator: Optional[User] = field(default=None)
5051

5152

0 commit comments

Comments
 (0)