tracktolib 0.65.0__py3-none-any.whl → 0.65.1__py3-none-any.whl
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.
tracktolib/notion/fetch.py
CHANGED
|
@@ -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":
|
|
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(
|
|
239
|
-
|
|
240
|
-
|
|
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
|
-
|
|
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:
|
tracktolib/notion/models.py
CHANGED
|
@@ -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
|
|
@@ -3,8 +3,8 @@ tracktolib/api.py,sha256=ZLMgjH3Y8r3MpXc8m3IuZbzTj3fgrZKZORtSVgbuP-M,10221
|
|
|
3
3
|
tracktolib/http_utils.py,sha256=c10JGmHaBw3VSDMYhz2dvVw2lo4PUAq1xMub74I7xDc,2625
|
|
4
4
|
tracktolib/logs.py,sha256=D2hx6urXl5l4PBGP8mCpcT4GX7tJeFfNY-7oBfHczBU,2191
|
|
5
5
|
tracktolib/notion/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
tracktolib/notion/fetch.py,sha256=
|
|
7
|
-
tracktolib/notion/models.py,sha256=
|
|
6
|
+
tracktolib/notion/fetch.py,sha256=2GS6L0Xv5UJZhQdqwrUJM11ors5hAH5WdFpuLWhXWTQ,13343
|
|
7
|
+
tracktolib/notion/models.py,sha256=FbTJcK0eA-4phpfjUxyAW7cs5jHZQxB6qqZ75ZcJ7uw,5608
|
|
8
8
|
tracktolib/pg/__init__.py,sha256=Ul_hgwvTXZvQBt7sHKi4ZI-0DDpnXmoFtmVkGRy-1J0,366
|
|
9
9
|
tracktolib/pg/query.py,sha256=zstc-QkBby7e6LybS8ed0d_6QLQNujY2H0lLNXFLNQ8,19366
|
|
10
10
|
tracktolib/pg/utils.py,sha256=ygQn63EBDaEGB0p7P2ibellO2mv-StafanpXKcCUiZU,6324
|
|
@@ -15,6 +15,6 @@ tracktolib/s3/minio.py,sha256=wMEjkSes9Fp39fD17IctALpD6zB2xwDRQEmO7Vzan3g,1387
|
|
|
15
15
|
tracktolib/s3/s3.py,sha256=0HbSAPoaup5-W4LK54zRCjrQ5mr8OWR-N9WjW99Q4aw,5937
|
|
16
16
|
tracktolib/tests.py,sha256=gKE--epQjgMZGXc5ydbl4zjOdmwztJS42UMV0p4hXEA,399
|
|
17
17
|
tracktolib/utils.py,sha256=ysTBF9V35fVXQVBPk0kfE_84SGRxzrayqmg9RbtoJq4,5761
|
|
18
|
-
tracktolib-0.65.
|
|
19
|
-
tracktolib-0.65.
|
|
20
|
-
tracktolib-0.65.
|
|
18
|
+
tracktolib-0.65.1.dist-info/WHEEL,sha256=z-mOpxbJHqy3cq6SvUThBZdaLGFZzdZPtgWLcP2NKjQ,79
|
|
19
|
+
tracktolib-0.65.1.dist-info/METADATA,sha256=Kr8EquD4NLUsi7Hyadl-Ij2JRB48rnzItX2o0bcLv0Y,3719
|
|
20
|
+
tracktolib-0.65.1.dist-info/RECORD,,
|
|
File without changes
|