notion-database 2.0.dev0__py3-none-any.whl → 2.0.dev1__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.
Files changed (45) hide show
  1. notion_database/__init__.py +69 -3
  2. notion_database/api/blocks.py +141 -0
  3. notion_database/api/comments.py +73 -0
  4. notion_database/api/databases.py +209 -0
  5. notion_database/api/pages.py +183 -0
  6. notion_database/api/search.py +142 -0
  7. notion_database/api/users.py +78 -0
  8. notion_database/client.py +84 -0
  9. notion_database/const/__init__.py +46 -1
  10. notion_database/exceptions.py +51 -0
  11. notion_database/http/client.py +109 -0
  12. notion_database/models/__init__.py +20 -0
  13. notion_database/models/blocks.py +528 -0
  14. notion_database/models/filters.py +420 -0
  15. notion_database/models/icons.py +70 -0
  16. notion_database/models/properties.py +548 -0
  17. notion_database/models/rich_text.py +160 -0
  18. notion_database/models/sorts.py +75 -0
  19. notion_database-2.0.dev1.dist-info/METADATA +355 -0
  20. notion_database-2.0.dev1.dist-info/RECORD +26 -0
  21. {notion_database-2.0.dev0.dist-info → notion_database-2.0.dev1.dist-info}/WHEEL +1 -1
  22. {notion_database-2.0.dev0.dist-info → notion_database-2.0.dev1.dist-info}/top_level.txt +0 -1
  23. notion_database/NotionDatabase.py +0 -107
  24. notion_database/components/request.py +0 -58
  25. notion_database/const/query.py +0 -38
  26. notion_database/service/block.py +0 -43
  27. notion_database/service/children.py +0 -520
  28. notion_database/service/cover.py +0 -43
  29. notion_database/service/database.py +0 -179
  30. notion_database/service/icon.py +0 -61
  31. notion_database/service/page.py +0 -118
  32. notion_database/service/properties.py +0 -220
  33. notion_database/service/search.py +0 -78
  34. notion_database/utils/__init__.py +0 -0
  35. notion_database/utils/deprecate.py +0 -21
  36. notion_database-2.0.dev0.dist-info/METADATA +0 -132
  37. notion_database-2.0.dev0.dist-info/RECORD +0 -28
  38. tests/__init__.py +0 -1
  39. tests/test_children.py +0 -286
  40. tests/test_cover.py +0 -22
  41. tests/test_icon.py +0 -33
  42. tests/test_properties.py +0 -245
  43. /notion_database/{components → api}/__init__.py +0 -0
  44. /notion_database/{service → http}/__init__.py +0 -0
  45. {notion_database-2.0.dev0.dist-info → notion_database-2.0.dev1.dist-info/licenses}/LICENSE +0 -0
@@ -1,7 +1,73 @@
1
1
  """
2
- init NOTION_VERSION
2
+ notion-database – Python client for the Notion API
3
+
4
+ Quick start::
5
+
6
+ from notion_database import NotionClient, PropertyValue, BlockContent, Filter, Sort
7
+
8
+ client = NotionClient("secret_xxx")
9
+
10
+ # Query a database
11
+ results = client.databases.query(
12
+ "database-id",
13
+ filter=Filter.select("Status").equals("Active"),
14
+ sorts=[Sort.descending("CreatedAt")],
15
+ )
16
+
17
+ # Create a page
18
+ page = client.pages.create(
19
+ parent={"database_id": "database-id"},
20
+ properties={
21
+ "Name": PropertyValue.title("Hello, Notion!"),
22
+ },
23
+ children=[BlockContent.paragraph("Page created with notion-database 2.0")],
24
+ )
3
25
  """
4
- from notion_database.NotionDatabase import NotionDatabase
26
+ from notion_database.client import NotionClient
27
+ from notion_database.exceptions import (
28
+ NotionAPIError,
29
+ NotionConflictError,
30
+ NotionError,
31
+ NotionForbiddenError,
32
+ NotionInternalError,
33
+ NotionNotFoundError,
34
+ NotionRateLimitError,
35
+ NotionUnauthorizedError,
36
+ NotionValidationError,
37
+ )
38
+ from notion_database.models.blocks import BlockContent
39
+ from notion_database.models.filters import Filter
40
+ from notion_database.models.icons import Cover, Icon
41
+ from notion_database.models.properties import PropertySchema, PropertyValue
42
+ from notion_database.models.rich_text import RichText
43
+ from notion_database.models.sorts import Sort
5
44
 
45
+ NOTION_VERSION = "2022-06-28"
46
+ __version__ = "2.0.dev1"
6
47
 
7
- __all__ = ["NotionDatabase"]
48
+ __all__ = [
49
+ # Client
50
+ "NotionClient",
51
+ # Builders
52
+ "PropertyValue",
53
+ "PropertySchema",
54
+ "BlockContent",
55
+ "RichText",
56
+ "Filter",
57
+ "Sort",
58
+ "Icon",
59
+ "Cover",
60
+ # Exceptions
61
+ "NotionError",
62
+ "NotionAPIError",
63
+ "NotionValidationError",
64
+ "NotionUnauthorizedError",
65
+ "NotionForbiddenError",
66
+ "NotionNotFoundError",
67
+ "NotionConflictError",
68
+ "NotionRateLimitError",
69
+ "NotionInternalError",
70
+ # Constants
71
+ "NOTION_VERSION",
72
+ "__version__",
73
+ ]
@@ -0,0 +1,141 @@
1
+ """
2
+ Notion Blocks API – https://developers.notion.com/reference/block
3
+ """
4
+ from typing import Any, Dict, List, Optional
5
+
6
+ from notion_database.http.client import HttpClient
7
+
8
+
9
+ class BlocksAPI:
10
+ """1-to-1 mapping of the Notion Blocks REST endpoints.
11
+
12
+ All methods accept plain Python dicts / lists that match the Notion API
13
+ request body schema, and return the raw Notion API response dict.
14
+
15
+ Reference: https://developers.notion.com/reference/block
16
+ """
17
+
18
+ def __init__(self, http: HttpClient) -> None:
19
+ self._http = http
20
+
21
+ # ------------------------------------------------------------------
22
+ # GET /blocks/{block_id}
23
+ # ------------------------------------------------------------------
24
+
25
+ def retrieve(self, block_id: str) -> Dict:
26
+ """Retrieve a block by ID.
27
+
28
+ Args:
29
+ block_id: The ID of the block to retrieve.
30
+
31
+ Returns:
32
+ Notion block object.
33
+
34
+ Reference: https://developers.notion.com/reference/retrieve-a-block
35
+ """
36
+ return self._http.get(f"/blocks/{block_id}")
37
+
38
+ # ------------------------------------------------------------------
39
+ # GET /blocks/{block_id}/children
40
+ # ------------------------------------------------------------------
41
+
42
+ def retrieve_children(
43
+ self,
44
+ block_id: str,
45
+ *,
46
+ start_cursor: Optional[str] = None,
47
+ page_size: int = 100,
48
+ ) -> Dict:
49
+ """Retrieve the immediate children of a block or page.
50
+
51
+ Args:
52
+ block_id: The parent block or page ID.
53
+ start_cursor: Cursor for pagination.
54
+ page_size: Number of results per page (1-100).
55
+
56
+ Returns:
57
+ Notion list object with ``results``, ``has_more``, and
58
+ ``next_cursor`` fields.
59
+
60
+ Reference: https://developers.notion.com/reference/get-block-children
61
+ """
62
+ params: Dict[str, Any] = {"page_size": page_size}
63
+ if start_cursor is not None:
64
+ params["start_cursor"] = start_cursor
65
+ return self._http.get(f"/blocks/{block_id}/children", params=params)
66
+
67
+ def retrieve_all_children(self, block_id: str) -> List[Dict]:
68
+ """Retrieve **all** children of a block, automatically paginating.
69
+
70
+ Args:
71
+ block_id: The parent block or page ID.
72
+
73
+ Returns:
74
+ A flat list of all child block objects.
75
+ """
76
+ blocks: List[Dict] = []
77
+ cursor: Optional[str] = None
78
+ while True:
79
+ response = self.retrieve_children(block_id, start_cursor=cursor)
80
+ blocks.extend(response.get("results", []))
81
+ if not response.get("has_more"):
82
+ break
83
+ cursor = response.get("next_cursor")
84
+ return blocks
85
+
86
+ # ------------------------------------------------------------------
87
+ # PATCH /blocks/{block_id}/children
88
+ # ------------------------------------------------------------------
89
+
90
+ def append_children(self, block_id: str, children: List[Dict]) -> Dict:
91
+ """Append new block children to a block or page.
92
+
93
+ Args:
94
+ block_id: The parent block or page ID to append to.
95
+ children: List of block objects to append. Build with
96
+ :class:`~notion_database.models.blocks.BlockContent`.
97
+
98
+ Returns:
99
+ Notion list object containing the newly appended block objects.
100
+
101
+ Reference: https://developers.notion.com/reference/patch-block-children
102
+ """
103
+ return self._http.patch(f"/blocks/{block_id}/children", {"children": children})
104
+
105
+ # ------------------------------------------------------------------
106
+ # PATCH /blocks/{block_id}
107
+ # ------------------------------------------------------------------
108
+
109
+ def update(self, block_id: str, block: Dict) -> Dict:
110
+ """Update the content of a block.
111
+
112
+ The ``block`` dict should contain only the fields to change. Refer to
113
+ the Notion API docs for the per-type update schema.
114
+
115
+ Args:
116
+ block_id: The block to update.
117
+ block: Partial block object with the fields to change.
118
+
119
+ Returns:
120
+ Updated Notion block object.
121
+
122
+ Reference: https://developers.notion.com/reference/update-a-block
123
+ """
124
+ return self._http.patch(f"/blocks/{block_id}", block)
125
+
126
+ # ------------------------------------------------------------------
127
+ # DELETE /blocks/{block_id}
128
+ # ------------------------------------------------------------------
129
+
130
+ def delete(self, block_id: str) -> Dict:
131
+ """Delete (archive) a block.
132
+
133
+ Args:
134
+ block_id: The block to delete.
135
+
136
+ Returns:
137
+ Deleted Notion block object with ``archived: true``.
138
+
139
+ Reference: https://developers.notion.com/reference/delete-a-block
140
+ """
141
+ return self._http.delete(f"/blocks/{block_id}")
@@ -0,0 +1,73 @@
1
+ """
2
+ Notion Comments API – https://developers.notion.com/reference/comment-object
3
+ """
4
+ from typing import Any, Dict, List, Optional
5
+
6
+ from notion_database.http.client import HttpClient
7
+
8
+
9
+ class CommentsAPI:
10
+ """1-to-1 mapping of the Notion Comments REST endpoints.
11
+
12
+ Reference: https://developers.notion.com/reference/comment-object
13
+ """
14
+
15
+ def __init__(self, http: HttpClient) -> None:
16
+ self._http = http
17
+
18
+ def retrieve(
19
+ self,
20
+ block_id: str,
21
+ *,
22
+ start_cursor: Optional[str] = None,
23
+ page_size: int = 100,
24
+ ) -> Dict:
25
+ """Retrieve comments associated with a page or block.
26
+
27
+ Args:
28
+ block_id: The page or block ID to retrieve comments for.
29
+ start_cursor: Cursor for pagination.
30
+ page_size: Number of results per page (1-100).
31
+
32
+ Returns:
33
+ Notion list object with comment objects.
34
+
35
+ Reference: https://developers.notion.com/reference/retrieve-a-comment
36
+ """
37
+ params: Dict[str, Any] = {
38
+ "block_id": block_id,
39
+ "page_size": page_size,
40
+ }
41
+ if start_cursor is not None:
42
+ params["start_cursor"] = start_cursor
43
+ return self._http.get("/comments", params=params)
44
+
45
+ def create(
46
+ self,
47
+ parent: Dict,
48
+ rich_text: List[Dict],
49
+ *,
50
+ discussion_id: Optional[str] = None,
51
+ ) -> Dict:
52
+ """Create a new comment on a page or existing discussion thread.
53
+
54
+ Args:
55
+ parent: Parent object. For page-level comments:
56
+ ``{"page_id": "..."}``.
57
+ rich_text: The comment body as a rich-text array. Build with
58
+ :class:`~notion_database.models.rich_text.RichText`.
59
+ discussion_id: If set, adds the comment to an existing discussion
60
+ thread instead of creating a new one.
61
+
62
+ Returns:
63
+ Newly created Notion comment object.
64
+
65
+ Reference: https://developers.notion.com/reference/create-a-comment
66
+ """
67
+ body: Dict[str, Any] = {
68
+ "parent": parent,
69
+ "rich_text": rich_text,
70
+ }
71
+ if discussion_id is not None:
72
+ body["discussion_id"] = discussion_id
73
+ return self._http.post("/comments", body)
@@ -0,0 +1,209 @@
1
+ """
2
+ Notion Databases API – https://developers.notion.com/reference/database
3
+ """
4
+ from typing import Any, Dict, List, Optional
5
+
6
+ from notion_database.http.client import HttpClient
7
+
8
+
9
+ class DatabasesAPI:
10
+ """1-to-1 mapping of the Notion Databases REST endpoints.
11
+
12
+ All methods accept plain Python dicts / lists that match the Notion API
13
+ request body schema, and return the raw Notion API response dict.
14
+
15
+ Reference: https://developers.notion.com/reference/database
16
+ """
17
+
18
+ def __init__(self, http: HttpClient) -> None:
19
+ self._http = http
20
+
21
+ # ------------------------------------------------------------------
22
+ # GET /databases/{database_id}
23
+ # ------------------------------------------------------------------
24
+
25
+ def retrieve(self, database_id: str) -> Dict:
26
+ """Retrieve a database by ID.
27
+
28
+ Args:
29
+ database_id: The ID of the database to retrieve.
30
+
31
+ Returns:
32
+ Notion database object.
33
+
34
+ Reference: https://developers.notion.com/reference/retrieve-a-database
35
+ """
36
+ return self._http.get(f"/databases/{database_id}")
37
+
38
+ # ------------------------------------------------------------------
39
+ # POST /databases/{database_id}/query
40
+ # ------------------------------------------------------------------
41
+
42
+ def query(
43
+ self,
44
+ database_id: str,
45
+ *,
46
+ filter: Optional[Dict] = None,
47
+ sorts: Optional[List[Dict]] = None,
48
+ start_cursor: Optional[str] = None,
49
+ page_size: int = 100,
50
+ filter_properties: Optional[List[str]] = None,
51
+ ) -> Dict:
52
+ """Query a database and return a page of results.
53
+
54
+ Args:
55
+ database_id: The database to query.
56
+ filter: A filter object. Use :class:`~notion_database.models.filters.Filter`
57
+ to build one, or pass a raw dict matching the Notion API schema.
58
+ sorts: A list of sort objects. Use :class:`~notion_database.models.sorts.Sort`
59
+ to build them.
60
+ start_cursor: Cursor returned by a previous query for pagination.
61
+ page_size: Number of results per page (1-100). Defaults to 100.
62
+ filter_properties: List of property names/IDs to include in the
63
+ response page objects. Reduces response payload size.
64
+
65
+ Returns:
66
+ Notion list object with ``results``, ``has_more``, and
67
+ ``next_cursor`` fields.
68
+
69
+ Reference: https://developers.notion.com/reference/post-database-query
70
+ """
71
+ body: Dict[str, Any] = {"page_size": page_size}
72
+ if filter is not None:
73
+ body["filter"] = filter
74
+ if sorts is not None:
75
+ body["sorts"] = sorts
76
+ if start_cursor is not None:
77
+ body["start_cursor"] = start_cursor
78
+ if filter_properties is not None:
79
+ body["filter_properties"] = filter_properties
80
+ return self._http.post(f"/databases/{database_id}/query", body)
81
+
82
+ def query_all(
83
+ self,
84
+ database_id: str,
85
+ *,
86
+ filter: Optional[Dict] = None,
87
+ sorts: Optional[List[Dict]] = None,
88
+ filter_properties: Optional[List[str]] = None,
89
+ ) -> List[Dict]:
90
+ """Query a database and automatically paginate to return **all** pages.
91
+
92
+ Args:
93
+ database_id: The database to query.
94
+ filter: A filter object.
95
+ sorts: A list of sort objects.
96
+ filter_properties: Property names/IDs to include in page objects.
97
+
98
+ Returns:
99
+ A flat list of all matching Notion page objects.
100
+ """
101
+ pages: List[Dict] = []
102
+ cursor: Optional[str] = None
103
+ while True:
104
+ response = self.query(
105
+ database_id,
106
+ filter=filter,
107
+ sorts=sorts,
108
+ start_cursor=cursor,
109
+ filter_properties=filter_properties,
110
+ )
111
+ pages.extend(response.get("results", []))
112
+ if not response.get("has_more"):
113
+ break
114
+ cursor = response.get("next_cursor")
115
+ return pages
116
+
117
+ # ------------------------------------------------------------------
118
+ # POST /databases
119
+ # ------------------------------------------------------------------
120
+
121
+ def create(
122
+ self,
123
+ parent: Dict,
124
+ title: List[Dict],
125
+ properties: Dict[str, Dict],
126
+ *,
127
+ icon: Optional[Dict] = None,
128
+ cover: Optional[Dict] = None,
129
+ is_inline: bool = False,
130
+ description: Optional[List[Dict]] = None,
131
+ ) -> Dict:
132
+ """Create a new database as a child of a page.
133
+
134
+ Args:
135
+ parent: Parent object, e.g. ``{"type": "page_id", "page_id": "..."}``.
136
+ title: Rich-text array for the database title.
137
+ Use :class:`~notion_database.models.rich_text.RichText` to build.
138
+ properties: Database property schema dict where keys are column
139
+ names and values are property schema objects.
140
+ Use :class:`~notion_database.models.properties.PropertySchema`
141
+ to build individual schemas.
142
+ icon: Icon object. Use :class:`~notion_database.models.icons.Icon`.
143
+ cover: Cover object. Use :class:`~notion_database.models.icons.Cover`.
144
+ is_inline: Whether the database appears inline on its parent page.
145
+ description: Rich-text array for the database description.
146
+
147
+ Returns:
148
+ Newly created Notion database object.
149
+
150
+ Reference: https://developers.notion.com/reference/create-a-database
151
+ """
152
+ body: Dict[str, Any] = {
153
+ "parent": parent,
154
+ "title": title,
155
+ "properties": properties,
156
+ "is_inline": is_inline,
157
+ }
158
+ if icon is not None:
159
+ body["icon"] = icon
160
+ if cover is not None:
161
+ body["cover"] = cover
162
+ if description is not None:
163
+ body["description"] = description
164
+ return self._http.post("/databases", body)
165
+
166
+ # ------------------------------------------------------------------
167
+ # PATCH /databases/{database_id}
168
+ # ------------------------------------------------------------------
169
+
170
+ def update(
171
+ self,
172
+ database_id: str,
173
+ *,
174
+ title: Optional[List[Dict]] = None,
175
+ description: Optional[List[Dict]] = None,
176
+ properties: Optional[Dict[str, Any]] = None,
177
+ icon: Optional[Any] = None,
178
+ cover: Optional[Any] = None,
179
+ ) -> Dict:
180
+ """Update an existing database.
181
+
182
+ Pass ``None`` as a property value to remove it from the schema.
183
+
184
+ Args:
185
+ database_id: The database to update.
186
+ title: New rich-text title array.
187
+ description: New rich-text description array.
188
+ properties: Partial property schema dict. Set a key to ``None``
189
+ to remove that property from the schema.
190
+ icon: New icon object, or ``None`` to remove.
191
+ cover: New cover object, or ``None`` to remove.
192
+
193
+ Returns:
194
+ Updated Notion database object.
195
+
196
+ Reference: https://developers.notion.com/reference/update-a-database
197
+ """
198
+ body: Dict[str, Any] = {}
199
+ if title is not None:
200
+ body["title"] = title
201
+ if description is not None:
202
+ body["description"] = description
203
+ if properties is not None:
204
+ body["properties"] = properties
205
+ if icon is not None:
206
+ body["icon"] = icon
207
+ if cover is not None:
208
+ body["cover"] = cover
209
+ return self._http.patch(f"/databases/{database_id}", body)
@@ -0,0 +1,183 @@
1
+ """
2
+ Notion Pages API – https://developers.notion.com/reference/page
3
+ """
4
+ from typing import Any, Dict, List, Optional
5
+
6
+ from notion_database.http.client import HttpClient
7
+
8
+
9
+ class PagesAPI:
10
+ """1-to-1 mapping of the Notion Pages REST endpoints.
11
+
12
+ All methods accept plain Python dicts / lists that match the Notion API
13
+ request body schema, and return the raw Notion API response dict.
14
+
15
+ Reference: https://developers.notion.com/reference/page
16
+ """
17
+
18
+ def __init__(self, http: HttpClient) -> None:
19
+ self._http = http
20
+
21
+ # ------------------------------------------------------------------
22
+ # GET /pages/{page_id}
23
+ # ------------------------------------------------------------------
24
+
25
+ def retrieve(
26
+ self,
27
+ page_id: str,
28
+ *,
29
+ filter_properties: Optional[List[str]] = None,
30
+ ) -> Dict:
31
+ """Retrieve a page by ID.
32
+
33
+ Args:
34
+ page_id: The ID of the page to retrieve.
35
+ filter_properties: List of property names/IDs to include.
36
+ Reduces response payload size.
37
+
38
+ Returns:
39
+ Notion page object.
40
+
41
+ Reference: https://developers.notion.com/reference/retrieve-a-page
42
+ """
43
+ params: Dict[str, Any] = {}
44
+ if filter_properties:
45
+ params["filter_properties"] = filter_properties
46
+ return self._http.get(f"/pages/{page_id}", params=params or None)
47
+
48
+ # ------------------------------------------------------------------
49
+ # GET /pages/{page_id}/properties/{property_id}
50
+ # ------------------------------------------------------------------
51
+
52
+ def retrieve_property(
53
+ self,
54
+ page_id: str,
55
+ property_id: str,
56
+ *,
57
+ page_size: int = 100,
58
+ start_cursor: Optional[str] = None,
59
+ ) -> Dict:
60
+ """Retrieve a specific property item of a page.
61
+
62
+ Useful for properties that contain more values than the inline page
63
+ object can carry (e.g. long relation lists, rollup arrays, rich-text
64
+ properties that exceed the inline limit).
65
+
66
+ Args:
67
+ page_id: The page containing the property.
68
+ property_id: The property ID or name.
69
+ page_size: Number of items per page (1-100).
70
+ start_cursor: Cursor for pagination.
71
+
72
+ Returns:
73
+ Property item object or a paginated list of property item objects.
74
+
75
+ Reference: https://developers.notion.com/reference/retrieve-a-page-property
76
+ """
77
+ params: Dict[str, Any] = {"page_size": page_size}
78
+ if start_cursor is not None:
79
+ params["start_cursor"] = start_cursor
80
+ return self._http.get(f"/pages/{page_id}/properties/{property_id}", params=params)
81
+
82
+ # ------------------------------------------------------------------
83
+ # POST /pages
84
+ # ------------------------------------------------------------------
85
+
86
+ def create(
87
+ self,
88
+ parent: Dict,
89
+ properties: Dict[str, Dict],
90
+ *,
91
+ children: Optional[List[Dict]] = None,
92
+ icon: Optional[Dict] = None,
93
+ cover: Optional[Dict] = None,
94
+ ) -> Dict:
95
+ """Create a new page.
96
+
97
+ Args:
98
+ parent: Parent object. For database children:
99
+ ``{"type": "database_id", "database_id": "..."}``.
100
+ For page children:
101
+ ``{"type": "page_id", "page_id": "..."}``.
102
+ properties: Page property values dict. Keys are property names
103
+ matching the parent database schema. Build values with
104
+ :class:`~notion_database.models.properties.PropertyValue`.
105
+ children: Initial page content as a list of block objects.
106
+ Build with :class:`~notion_database.models.blocks.BlockContent`.
107
+ icon: Icon object.
108
+ cover: Cover object.
109
+
110
+ Returns:
111
+ Newly created Notion page object.
112
+
113
+ Reference: https://developers.notion.com/reference/post-page
114
+ """
115
+ body: Dict[str, Any] = {
116
+ "parent": parent,
117
+ "properties": properties,
118
+ }
119
+ if children is not None:
120
+ body["children"] = children
121
+ if icon is not None:
122
+ body["icon"] = icon
123
+ if cover is not None:
124
+ body["cover"] = cover
125
+ return self._http.post("/pages", body)
126
+
127
+ # ------------------------------------------------------------------
128
+ # PATCH /pages/{page_id}
129
+ # ------------------------------------------------------------------
130
+
131
+ def update(
132
+ self,
133
+ page_id: str,
134
+ *,
135
+ properties: Optional[Dict[str, Any]] = None,
136
+ archived: Optional[bool] = None,
137
+ icon: Optional[Any] = None,
138
+ cover: Optional[Any] = None,
139
+ in_trash: Optional[bool] = None,
140
+ ) -> Dict:
141
+ """Update a page's properties, icon, cover, or archived status.
142
+
143
+ Args:
144
+ page_id: The page to update.
145
+ properties: Partial property values dict. Omitted keys are
146
+ left unchanged.
147
+ archived: Set to ``True`` to archive (soft-delete) the page,
148
+ ``False`` to restore it.
149
+ icon: New icon object, or ``None`` to remove.
150
+ cover: New cover object, or ``None`` to remove.
151
+ in_trash: Set to ``True`` to move to trash.
152
+
153
+ Returns:
154
+ Updated Notion page object.
155
+
156
+ Reference: https://developers.notion.com/reference/patch-page
157
+ """
158
+ body: Dict[str, Any] = {}
159
+ if properties is not None:
160
+ body["properties"] = properties
161
+ if archived is not None:
162
+ body["archived"] = archived
163
+ if icon is not None:
164
+ body["icon"] = icon
165
+ if cover is not None:
166
+ body["cover"] = cover
167
+ if in_trash is not None:
168
+ body["in_trash"] = in_trash
169
+ return self._http.patch(f"/pages/{page_id}", body)
170
+
171
+ def archive(self, page_id: str, *, archived: bool = True) -> Dict:
172
+ """Archive or restore a page.
173
+
174
+ Convenience wrapper around :meth:`update`.
175
+
176
+ Args:
177
+ page_id: The page to archive/restore.
178
+ archived: ``True`` to archive, ``False`` to restore.
179
+
180
+ Returns:
181
+ Updated Notion page object.
182
+ """
183
+ return self.update(page_id, archived=archived)