Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,11 @@ The SDK provides structured types to help you work with API responses more effec

Here is an example of how to use these types with the SDK to deserialize API responses:
```python
from monday_sdk import MondayClient, MondayApiResponse
import dacite
from monday_sdk import MondayClient

client = MondayClient(token="your_token")

# Fetch the raw response data
response_data = client.boards.fetch_all_items_by_board_id(board_id="your_board_id")

# Deserialize the response data into typed objects
monday_response = dacite.from_dict(data_class=MondayApiResponse, data=response_data)

# Access specific fields using the deserialized objects
first_board = monday_response.data.boards[0]
first_item_name = first_board.items_page.items[0].name

items = client.boards.fetch_all_items_by_board_id(board_id="your_board_id")
first_item_name = items[0].name
print(f"First item name: {first_item_name}")
```
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.
9 changes: 2 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name="monday-api-python-sdk", # Required
version="1.1.3", # Required
version="1.2.3", # Required
description="A Python SDK for interacting with Monday's GraphQL API", # Optional
long_description=long_description, # Optional
long_description_content_type="text/markdown", # Optional (see note above)
Expand All @@ -24,12 +24,7 @@
author_email="michaelim@monday.com",
license_files=("LICENSE",),
classifiers=[ # Optional
# How mature is this project? Common values are
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
"Development Status :: 3 - Alpha",
# Indicate who your project is intended for
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Topic :: Software Development :: Build Tools",
# Pick your license as you wish
Expand Down
43 changes: 40 additions & 3 deletions src/monday_sdk/modules/updates.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import List
from datetime import datetime
from typing import List, Optional

from ..query_templates import create_update_query, delete_update_query, get_update_query, get_updates_for_item_query, get_updates_for_board
from ..types import MondayApiResponse, Update
from ..graphql_handler import MondayGraphQL


class UpdateModule(MondayGraphQL):
def create_update(self, item_id, update_value) -> MondayApiResponse:
query = create_update_query(item_id, update_value)
Expand All @@ -22,7 +22,44 @@ def fetch_updates_for_item(self, item_id, limit=100) -> MondayApiResponse:
query = get_updates_for_item_query(item_id=item_id, limit=limit)
return self.execute(query)

def fetch_board_updates(self, board_id, limit=100, page=1) -> List[Update]:
def fetch_board_updates_page(self, board_id, limit=100, page=1) -> List[Update]:
query = get_updates_for_board(board_id, limit, page)
response: MondayApiResponse = self.execute(query)
return response.data.boards[0].updates

def fetch_board_updates(
self,
board_ids: str,
updated_after: Optional[str] = None,
updated_before: Optional[str] = None,
) -> List[Update]:
"""
Fetches all updates from a board (with optional date filtering).
- Paginates through all pages until no more updates.
- If from_date or to_date are provided, filters out updates outside that window.
"""
start_dt = datetime.fromisoformat(updated_after) if updated_after else None
end_dt = datetime.fromisoformat(updated_before) if updated_before else None

all_updates = []
page = 1

while True:
updates = self.fetch_board_updates_page(board_ids, page=page)
if not updates:
break

if start_dt or end_dt:
updates = [
u for u in updates
if (
u.updated_at
and (start_dt is None or datetime.fromisoformat(u.updated_at) >= start_dt)
and (end_dt is None or datetime.fromisoformat(u.updated_at) <= end_dt)
)
]

all_updates.extend(updates)
page += 1

return all_updates
1 change: 1 addition & 0 deletions src/monday_sdk/query_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ def get_updates_for_board(board_id, limit: int, page=1):
id,
text_body,
item_id,
updated_at,
created_at,
creator {
name,
Expand Down
1 change: 1 addition & 0 deletions src/monday_sdk/types/api_response_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Update:
text_body: Optional[str] = field(default=None)
item_id: Optional[str] = field(default=None)
created_at: Optional[str] = field(default=None)
updated_at: Optional[str] = field(default=None)
creator: Optional[User] = field(default=None)


Expand Down