tracktolib 0.65.0__tar.gz → 0.65.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tracktolib
3
- Version: 0.65.0
3
+ Version: 0.65.1
4
4
  Summary: Utility library for python
5
5
  Keywords: utility
6
6
  Author-email: julien.brayere@tracktor.fr
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "tracktolib"
3
- version = "0.65.0"
3
+ version = "0.65.1"
4
4
  authors = [
5
5
  { email = "julien.brayere@tracktor.fr" }
6
6
  ]
@@ -96,7 +96,7 @@ pythonPlatform = "Linux"
96
96
 
97
97
  [tool.commitizen]
98
98
  name = "cz_conventional_commits"
99
- version = "0.65.0"
99
+ version = "0.65.1"
100
100
  tag_format = "$version"
101
101
  version_files = [
102
102
  "pyproject.toml:version"
@@ -1,5 +1,5 @@
1
1
  import os
2
- from typing import Any
2
+ from typing import Any, Literal
3
3
 
4
4
  try:
5
5
  import niquests
@@ -20,6 +20,19 @@ from .models import (
20
20
  UserListResponse,
21
21
  )
22
22
 
23
+ # API version constants
24
+ API_VERSION_2022_06_28 = "2022-06-28"
25
+ API_VERSION_2025_09_03 = "2025-09-03"
26
+ DEFAULT_API_VERSION = API_VERSION_2025_09_03
27
+
28
+ ApiVersion = Literal["2022-06-28", "2025-09-03"]
29
+
30
+
31
+ def _use_data_source_api(api_version: str) -> bool:
32
+ """Check if the API version uses data_source endpoints (2025-09-03+)."""
33
+ return api_version >= "2025-09-03"
34
+
35
+
23
36
  __all__ = (
24
37
  # Auth helpers
25
38
  "get_notion_headers",
@@ -181,6 +194,19 @@ async def fetch_page(session: niquests.AsyncSession, page_id: str) -> Page:
181
194
  return response.json() # type: ignore[return-value]
182
195
 
183
196
 
197
+ def _convert_parent_for_api_version(parent: dict[str, Any], api_version: str) -> dict[str, Any]:
198
+ """Convert parent dict between database_id and data_source_id based on API version."""
199
+ if _use_data_source_api(api_version):
200
+ # Convert database_id to data_source_id for new API
201
+ if "database_id" in parent:
202
+ return {"data_source_id": parent["database_id"]}
203
+ else:
204
+ # Convert data_source_id to database_id for old API
205
+ if "data_source_id" in parent:
206
+ return {"database_id": parent["data_source_id"]}
207
+ return parent
208
+
209
+
184
210
  async def create_page(
185
211
  session: niquests.AsyncSession,
186
212
  *,
@@ -189,10 +215,18 @@ async def create_page(
189
215
  children: list[dict[str, Any]] | None = None,
190
216
  icon: dict[str, Any] | None = None,
191
217
  cover: dict[str, Any] | None = None,
218
+ api_version: ApiVersion | None = None,
192
219
  ) -> Page:
193
- """Create a new page."""
220
+ """Create a new page.
221
+
222
+ For API version 2025-09-03+, parent should use {"data_source_id": "..."}.
223
+ For older API versions, parent should use {"database_id": "..."}.
224
+ The function will automatically convert between the two formats.
225
+ """
226
+ _api_version = api_version or session.headers.get("Notion-Version", DEFAULT_API_VERSION)
227
+ converted_parent = _convert_parent_for_api_version(parent, _api_version)
194
228
  payload: dict[str, Any] = {
195
- "parent": parent,
229
+ "parent": converted_parent,
196
230
  "properties": properties,
197
231
  }
198
232
  if children:
@@ -235,9 +269,24 @@ async def update_page(
235
269
  # Databases endpoints
236
270
 
237
271
 
238
- async def fetch_database(session: niquests.AsyncSession, database_id: str) -> Database:
239
- """Retrieve a database by ID."""
240
- response = await session.get(f"{NOTION_API_URL}/v1/databases/{database_id}")
272
+ async def fetch_database(
273
+ session: niquests.AsyncSession,
274
+ database_id: str,
275
+ *,
276
+ api_version: ApiVersion | None = None,
277
+ ) -> Database:
278
+ """Retrieve a database/data source by ID.
279
+
280
+ For API version 2025-09-03+, uses /v1/data_sources/{id} endpoint.
281
+ For older API versions, uses /v1/databases/{id} endpoint.
282
+ """
283
+ _api_version = api_version or session.headers.get("Notion-Version", DEFAULT_API_VERSION)
284
+ if _use_data_source_api(_api_version):
285
+ endpoint = f"{NOTION_API_URL}/v1/data_sources/{database_id}"
286
+ else:
287
+ endpoint = f"{NOTION_API_URL}/v1/databases/{database_id}"
288
+
289
+ response = await session.get(endpoint)
241
290
  response.raise_for_status()
242
291
  return response.json() # type: ignore[return-value]
243
292
 
@@ -250,8 +299,14 @@ async def query_database(
250
299
  sorts: list[dict[str, Any]] | None = None,
251
300
  start_cursor: str | None = None,
252
301
  page_size: int | None = None,
302
+ api_version: ApiVersion | None = None,
253
303
  ) -> PageListResponse:
254
- """Query a database."""
304
+ """Query a database/data source.
305
+
306
+ For API version 2025-09-03+, uses /v1/data_sources/{id}/query endpoint.
307
+ For older API versions, uses /v1/databases/{id}/query endpoint.
308
+ """
309
+ _api_version = api_version or session.headers.get("Notion-Version", DEFAULT_API_VERSION)
255
310
  payload: dict[str, Any] = {}
256
311
  if filter:
257
312
  payload["filter"] = filter
@@ -262,7 +317,12 @@ async def query_database(
262
317
  if page_size:
263
318
  payload["page_size"] = page_size
264
319
 
265
- response = await session.post(f"{NOTION_API_URL}/v1/databases/{database_id}/query", json=payload or None)
320
+ if _use_data_source_api(_api_version):
321
+ endpoint = f"{NOTION_API_URL}/v1/data_sources/{database_id}/query"
322
+ else:
323
+ endpoint = f"{NOTION_API_URL}/v1/databases/{database_id}/query"
324
+
325
+ response = await session.post(endpoint, json=payload or None)
266
326
  response.raise_for_status()
267
327
  return response.json() # type: ignore[return-value]
268
328
 
@@ -312,6 +372,23 @@ async def fetch_append_block_children(
312
372
  # Search endpoint
313
373
 
314
374
 
375
+ def _convert_search_filter_for_api_version(filter: dict[str, Any], api_version: str) -> dict[str, Any]:
376
+ """Convert search filter value between 'database' and 'data_source' based on API version."""
377
+ if "value" not in filter:
378
+ return filter
379
+
380
+ filter_copy = filter.copy()
381
+ if _use_data_source_api(api_version):
382
+ # Convert 'database' to 'data_source' for new API
383
+ if filter_copy.get("value") == "database":
384
+ filter_copy["value"] = "data_source"
385
+ else:
386
+ # Convert 'data_source' to 'database' for old API
387
+ if filter_copy.get("value") == "data_source":
388
+ filter_copy["value"] = "database"
389
+ return filter_copy
390
+
391
+
315
392
  async def fetch_search(
316
393
  session: niquests.AsyncSession,
317
394
  *,
@@ -320,13 +397,20 @@ async def fetch_search(
320
397
  sort: dict[str, Any] | None = None,
321
398
  start_cursor: str | None = None,
322
399
  page_size: int | None = None,
400
+ api_version: ApiVersion | None = None,
323
401
  ) -> SearchResponse:
324
- """Search pages and databases."""
402
+ """Search pages and databases/data sources.
403
+
404
+ For API version 2025-09-03+, filter value 'database' is automatically
405
+ converted to 'data_source'. For older versions, 'data_source' is
406
+ converted to 'database'.
407
+ """
408
+ _api_version = api_version or session.headers.get("Notion-Version", DEFAULT_API_VERSION)
325
409
  payload: dict[str, Any] = {}
326
410
  if query:
327
411
  payload["query"] = query
328
412
  if filter:
329
- payload["filter"] = filter
413
+ payload["filter"] = _convert_search_filter_for_api_version(filter, _api_version)
330
414
  if sort:
331
415
  payload["sort"] = sort
332
416
  if start_cursor:
@@ -126,12 +126,19 @@ class PageParent(TypedDict):
126
126
 
127
127
 
128
128
  class DatabaseParent(TypedDict):
129
- """Database parent."""
129
+ """Database parent (deprecated in API 2025-09-03, use DataSourceParent)."""
130
130
 
131
131
  type: Literal["database_id"]
132
132
  database_id: str
133
133
 
134
134
 
135
+ class DataSourceParent(TypedDict):
136
+ """Data source parent (API 2025-09-03+)."""
137
+
138
+ type: Literal["data_source_id"]
139
+ data_source_id: str
140
+
141
+
135
142
  class WorkspaceParent(TypedDict):
136
143
  """Workspace parent."""
137
144
 
@@ -146,7 +153,7 @@ class BlockParent(TypedDict):
146
153
  block_id: str
147
154
 
148
155
 
149
- Parent = PageParent | DatabaseParent | WorkspaceParent | BlockParent
156
+ Parent = PageParent | DatabaseParent | DataSourceParent | WorkspaceParent | BlockParent
150
157
 
151
158
 
152
159
  # Page types
File without changes