notionhelper 0.4.4__py3-none-any.whl → 0.4.5__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.
notionhelper/helper.py
CHANGED
|
@@ -67,6 +67,9 @@ class NotionHelper:
|
|
|
67
67
|
|
|
68
68
|
update_data_source(data_source_id, properties=None, title=None, icon=None, in_trash=None, parent=None):
|
|
69
69
|
Updates the attributes of a specified data source.
|
|
70
|
+
|
|
71
|
+
move_page_to_trash(page_id):
|
|
72
|
+
Moves a Notion page to trash by setting in_trash to True.
|
|
70
73
|
"""
|
|
71
74
|
|
|
72
75
|
def __init__(self, notion_token: str):
|
|
@@ -397,10 +400,92 @@ class NotionHelper:
|
|
|
397
400
|
return self._make_request("POST", url, payload)
|
|
398
401
|
|
|
399
402
|
def append_page_body(self, page_id: str, blocks: List[Dict[str, Any]]) -> Dict[str, Any]:
|
|
400
|
-
"""Appends blocks of text to the body of a Notion page.
|
|
403
|
+
"""Appends blocks of text to the body of a Notion page.
|
|
404
|
+
|
|
405
|
+
Args:
|
|
406
|
+
page_id: The ID of the Notion page (with or without dashes)
|
|
407
|
+
blocks: List of block objects to append. Each block must have a "type"
|
|
408
|
+
and a corresponding nested object. See examples below.
|
|
409
|
+
|
|
410
|
+
Returns:
|
|
411
|
+
Dict containing the API response
|
|
412
|
+
|
|
413
|
+
Raises:
|
|
414
|
+
ValueError: If blocks is not a list or is empty
|
|
415
|
+
requests.exceptions.HTTPError: If the request fails
|
|
416
|
+
|
|
417
|
+
Examples:
|
|
418
|
+
# Append a paragraph
|
|
419
|
+
blocks = [{
|
|
420
|
+
"object": "block",
|
|
421
|
+
"type": "paragraph",
|
|
422
|
+
"paragraph": {
|
|
423
|
+
"rich_text": [{
|
|
424
|
+
"type": "text",
|
|
425
|
+
"text": {"content": "Hello, world!"}
|
|
426
|
+
}]
|
|
427
|
+
}
|
|
428
|
+
}]
|
|
429
|
+
|
|
430
|
+
# Append a heading
|
|
431
|
+
blocks = [{
|
|
432
|
+
"object": "block",
|
|
433
|
+
"type": "heading_2",
|
|
434
|
+
"heading_2": {
|
|
435
|
+
"rich_text": [{
|
|
436
|
+
"type": "text",
|
|
437
|
+
"text": {"content": "My Heading"}
|
|
438
|
+
}]
|
|
439
|
+
}
|
|
440
|
+
}]
|
|
441
|
+
"""
|
|
442
|
+
# Validate input
|
|
443
|
+
if not isinstance(blocks, list):
|
|
444
|
+
raise ValueError(f"blocks must be a list, got {type(blocks).__name__}")
|
|
445
|
+
|
|
446
|
+
if len(blocks) == 0:
|
|
447
|
+
raise ValueError("blocks list cannot be empty")
|
|
448
|
+
|
|
449
|
+
# Validate each block has required structure
|
|
450
|
+
for i, block in enumerate(blocks):
|
|
451
|
+
if not isinstance(block, dict):
|
|
452
|
+
raise ValueError(f"Block at index {i} must be a dict, got {type(block).__name__}")
|
|
453
|
+
|
|
454
|
+
if "type" not in block:
|
|
455
|
+
raise ValueError(f"Block at index {i} missing required 'type' field. Block: {block}")
|
|
456
|
+
|
|
457
|
+
block_type = block["type"]
|
|
458
|
+
if block_type not in block:
|
|
459
|
+
raise ValueError(
|
|
460
|
+
f"Block at index {i} of type '{block_type}' must have a '{block_type}' property. "
|
|
461
|
+
f"Example: {{'type': '{block_type}', '{block_type}': {{'rich_text': [...]}}}}"
|
|
462
|
+
)
|
|
463
|
+
|
|
401
464
|
payload = {"children": blocks}
|
|
402
465
|
url = f"https://api.notion.com/v1/blocks/{page_id}/children"
|
|
403
|
-
|
|
466
|
+
|
|
467
|
+
try:
|
|
468
|
+
return self._make_request("PATCH", url, payload)
|
|
469
|
+
except requests.exceptions.HTTPError as e:
|
|
470
|
+
if e.response.status_code == 400:
|
|
471
|
+
print(f"\n❌ Bad Request (400) - The block structure is invalid.")
|
|
472
|
+
print(f"First block in your request: {json.dumps(blocks[0], indent=2)}")
|
|
473
|
+
print(f"\nExpected structure example:")
|
|
474
|
+
print(json.dumps({
|
|
475
|
+
"object": "block",
|
|
476
|
+
"type": "paragraph",
|
|
477
|
+
"paragraph": {
|
|
478
|
+
"rich_text": [{
|
|
479
|
+
"type": "text",
|
|
480
|
+
"text": {"content": "Your text here"}
|
|
481
|
+
}]
|
|
482
|
+
}
|
|
483
|
+
}, indent=2))
|
|
484
|
+
elif e.response.status_code == 404:
|
|
485
|
+
print(f"\n❌ Page not found (404). Make sure:")
|
|
486
|
+
print(f" 1. The page ID is correct: {page_id}")
|
|
487
|
+
print(f" 2. The page (or parent database) is shared with your integration")
|
|
488
|
+
raise
|
|
404
489
|
|
|
405
490
|
def get_data_source_page_ids(self, data_source_id: str) -> List[str]:
|
|
406
491
|
"""Returns the IDs of all pages in a given data source.
|
|
@@ -768,3 +853,27 @@ class NotionHelper:
|
|
|
768
853
|
}
|
|
769
854
|
response = requests.patch(update_url, headers=headers, json=data)
|
|
770
855
|
return response.json()
|
|
856
|
+
|
|
857
|
+
def move_page_to_trash(self, page_id: str) -> Dict[str, Any]:
|
|
858
|
+
"""Moves a Notion page to trash by setting in_trash to True.
|
|
859
|
+
|
|
860
|
+
Parameters
|
|
861
|
+
----------
|
|
862
|
+
page_id : str
|
|
863
|
+
The unique identifier of the Notion page to move to trash.
|
|
864
|
+
|
|
865
|
+
Returns
|
|
866
|
+
-------
|
|
867
|
+
dict
|
|
868
|
+
A dictionary representing the updated page object with in_trash set to True.
|
|
869
|
+
|
|
870
|
+
Examples
|
|
871
|
+
--------
|
|
872
|
+
>>> helper = NotionHelper(token="your_token")
|
|
873
|
+
>>> result = helper.move_page_to_trash("page_id_here")
|
|
874
|
+
>>> print(result['in_trash'])
|
|
875
|
+
True
|
|
876
|
+
"""
|
|
877
|
+
payload = {"in_trash": True}
|
|
878
|
+
url = f"https://api.notion.com/v1/pages/{page_id}"
|
|
879
|
+
return self._make_request("PATCH", url, payload)
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: notionhelper
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.5
|
|
4
4
|
Summary: NotionHelper is a Python library that simplifies interactions with the Notion API, enabling easy management of databases, pages, and files within Notion workspaces.
|
|
5
5
|
Author-email: Jan du Plessis <drjanduplessis@icloud.com>
|
|
6
6
|
Requires-Python: >=3.10
|
|
7
7
|
Requires-Dist: mimetype>=0.1.5
|
|
8
|
-
Requires-Dist: notebook>=7.4.5
|
|
9
8
|
Requires-Dist: notion-client>=2.4.0
|
|
10
9
|
Requires-Dist: pandas>=2.3.1
|
|
11
10
|
Requires-Dist: requests>=2.32.4
|
|
@@ -27,7 +26,7 @@ Description-Content-Type: text/markdown
|
|
|
27
26
|
|
|
28
27
|
# NotionHelper
|
|
29
28
|
|
|
30
|
-

|
|
31
30
|
|
|
32
31
|
`NotionHelper` is a Python library that provides a convenient interface for interacting with the Notion API, specifically designed to leverage the **Notion API Version 2025-09-03**. It simplifies common tasks such as managing databases, data sources, pages, and file uploads, allowing you to integrate Notion's powerful features into your applications with ease.
|
|
33
32
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
notionhelper/__init__.py,sha256=lidq1uQioToT1ePIu02XktGYTPMp_uY5Btw63GlNqOo,117
|
|
2
|
+
notionhelper/helper.py,sha256=yQfjjRke-MzDTGkXhlyBV6-9EZe1DcLlI02b946iDYE,37201
|
|
3
|
+
notionhelper/ml_logger.py,sha256=d8KwboWwskn2Xa9cYWvqPKqcoNYywHb_MCoKgx5WCpw,8652
|
|
4
|
+
notionhelper-0.4.5.dist-info/METADATA,sha256=B0H7DBdgkx7LafBiMosqolu_FDdhefgQbwJhJzw4o3w,21136
|
|
5
|
+
notionhelper-0.4.5.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
6
|
+
notionhelper-0.4.5.dist-info/RECORD,,
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
notionhelper/__init__.py,sha256=lidq1uQioToT1ePIu02XktGYTPMp_uY5Btw63GlNqOo,117
|
|
2
|
-
notionhelper/helper.py,sha256=6-iJU2y9YlGinadvnRWFeq0rvh5fbYYHsYDkS4bkhHk,33075
|
|
3
|
-
notionhelper/ml_logger.py,sha256=d8KwboWwskn2Xa9cYWvqPKqcoNYywHb_MCoKgx5WCpw,8652
|
|
4
|
-
notionhelper-0.4.4.dist-info/METADATA,sha256=fb1VhtTRAPK7yTQsE2mcv8ZAVcKXstzzMp8Jqi_xC_8,21227
|
|
5
|
-
notionhelper-0.4.4.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
6
|
-
notionhelper-0.4.4.dist-info/RECORD,,
|
|
File without changes
|