notionary 0.2.18__py3-none-any.whl → 0.2.21__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 (204) hide show
  1. notionary/__init__.py +8 -4
  2. notionary/base_notion_client.py +3 -1
  3. notionary/blocks/__init__.py +2 -91
  4. notionary/blocks/_bootstrap.py +263 -0
  5. notionary/blocks/audio/__init__.py +8 -2
  6. notionary/blocks/audio/audio_element.py +42 -104
  7. notionary/blocks/audio/audio_markdown_node.py +3 -1
  8. notionary/blocks/audio/audio_models.py +6 -55
  9. notionary/blocks/base_block_element.py +30 -0
  10. notionary/blocks/bookmark/__init__.py +9 -2
  11. notionary/blocks/bookmark/bookmark_element.py +46 -139
  12. notionary/blocks/bookmark/bookmark_markdown_node.py +3 -1
  13. notionary/blocks/bookmark/bookmark_models.py +15 -0
  14. notionary/blocks/breadcrumbs/__init__.py +17 -0
  15. notionary/blocks/breadcrumbs/breadcrumb_element.py +39 -0
  16. notionary/blocks/breadcrumbs/breadcrumb_markdown_node.py +32 -0
  17. notionary/blocks/breadcrumbs/breadcrumb_models.py +12 -0
  18. notionary/blocks/bulleted_list/__init__.py +12 -2
  19. notionary/blocks/bulleted_list/bulleted_list_element.py +40 -55
  20. notionary/blocks/bulleted_list/bulleted_list_markdown_node.py +2 -1
  21. notionary/blocks/bulleted_list/bulleted_list_models.py +18 -0
  22. notionary/blocks/callout/__init__.py +9 -2
  23. notionary/blocks/callout/callout_element.py +40 -89
  24. notionary/blocks/callout/callout_markdown_node.py +3 -1
  25. notionary/blocks/callout/callout_models.py +33 -0
  26. notionary/blocks/child_database/__init__.py +7 -0
  27. notionary/blocks/child_database/child_database_models.py +19 -0
  28. notionary/blocks/child_page/__init__.py +9 -0
  29. notionary/blocks/child_page/child_page_models.py +12 -0
  30. notionary/blocks/{shared/block_client.py → client.py} +55 -54
  31. notionary/blocks/code/__init__.py +6 -2
  32. notionary/blocks/code/code_element.py +53 -187
  33. notionary/blocks/code/code_markdown_node.py +13 -13
  34. notionary/blocks/code/code_models.py +94 -0
  35. notionary/blocks/column/__init__.py +25 -1
  36. notionary/blocks/column/column_element.py +40 -314
  37. notionary/blocks/column/column_list_element.py +37 -0
  38. notionary/blocks/column/column_list_markdown_node.py +50 -0
  39. notionary/blocks/column/column_markdown_node.py +59 -0
  40. notionary/blocks/column/column_models.py +26 -0
  41. notionary/blocks/divider/__init__.py +9 -2
  42. notionary/blocks/divider/divider_element.py +26 -49
  43. notionary/blocks/divider/divider_markdown_node.py +2 -1
  44. notionary/blocks/divider/divider_models.py +12 -0
  45. notionary/blocks/embed/__init__.py +9 -2
  46. notionary/blocks/embed/embed_element.py +47 -114
  47. notionary/blocks/embed/embed_markdown_node.py +3 -1
  48. notionary/blocks/embed/embed_models.py +14 -0
  49. notionary/blocks/equation/__init__.py +14 -0
  50. notionary/blocks/equation/equation_element.py +80 -0
  51. notionary/blocks/equation/equation_element_markdown_node.py +36 -0
  52. notionary/blocks/equation/equation_models.py +11 -0
  53. notionary/blocks/file/__init__.py +25 -0
  54. notionary/blocks/file/file_element.py +93 -0
  55. notionary/blocks/file/file_element_markdown_node.py +35 -0
  56. notionary/blocks/file/file_element_models.py +39 -0
  57. notionary/blocks/heading/__init__.py +16 -2
  58. notionary/blocks/heading/heading_element.py +67 -72
  59. notionary/blocks/heading/heading_markdown_node.py +2 -1
  60. notionary/blocks/heading/heading_models.py +29 -0
  61. notionary/blocks/image_block/__init__.py +13 -0
  62. notionary/blocks/image_block/image_element.py +84 -0
  63. notionary/blocks/{image → image_block}/image_markdown_node.py +3 -1
  64. notionary/blocks/image_block/image_models.py +10 -0
  65. notionary/blocks/models.py +172 -0
  66. notionary/blocks/numbered_list/__init__.py +12 -2
  67. notionary/blocks/numbered_list/numbered_list_element.py +33 -58
  68. notionary/blocks/numbered_list/numbered_list_markdown_node.py +3 -1
  69. notionary/blocks/numbered_list/numbered_list_models.py +17 -0
  70. notionary/blocks/paragraph/__init__.py +12 -2
  71. notionary/blocks/paragraph/paragraph_element.py +27 -69
  72. notionary/blocks/paragraph/paragraph_markdown_node.py +2 -1
  73. notionary/blocks/paragraph/paragraph_models.py +16 -0
  74. notionary/blocks/pdf/__init__.py +13 -0
  75. notionary/blocks/pdf/pdf_element.py +91 -0
  76. notionary/blocks/pdf/pdf_markdown_node.py +35 -0
  77. notionary/blocks/pdf/pdf_models.py +11 -0
  78. notionary/blocks/quote/__init__.py +11 -2
  79. notionary/blocks/quote/quote_element.py +31 -65
  80. notionary/blocks/quote/quote_markdown_node.py +4 -1
  81. notionary/blocks/quote/quote_models.py +18 -0
  82. notionary/blocks/registry/__init__.py +4 -0
  83. notionary/blocks/registry/block_registry.py +75 -91
  84. notionary/blocks/registry/block_registry_builder.py +107 -59
  85. notionary/blocks/rich_text/__init__.py +33 -0
  86. notionary/blocks/rich_text/rich_text_models.py +188 -0
  87. notionary/blocks/rich_text/text_inline_formatter.py +125 -0
  88. notionary/blocks/table/__init__.py +16 -2
  89. notionary/blocks/table/table_element.py +48 -241
  90. notionary/blocks/table/table_markdown_node.py +2 -1
  91. notionary/blocks/table/table_models.py +28 -0
  92. notionary/blocks/table_of_contents/__init__.py +19 -0
  93. notionary/blocks/table_of_contents/table_of_contents_element.py +51 -0
  94. notionary/blocks/table_of_contents/table_of_contents_markdown_node.py +35 -0
  95. notionary/blocks/table_of_contents/table_of_contents_models.py +18 -0
  96. notionary/blocks/todo/__init__.py +9 -2
  97. notionary/blocks/todo/todo_element.py +38 -95
  98. notionary/blocks/todo/todo_markdown_node.py +2 -1
  99. notionary/blocks/todo/todo_models.py +19 -0
  100. notionary/blocks/toggle/__init__.py +13 -3
  101. notionary/blocks/toggle/toggle_element.py +57 -264
  102. notionary/blocks/toggle/toggle_markdown_node.py +24 -14
  103. notionary/blocks/toggle/toggle_models.py +17 -0
  104. notionary/blocks/toggleable_heading/__init__.py +6 -2
  105. notionary/blocks/toggleable_heading/toggleable_heading_element.py +74 -244
  106. notionary/blocks/toggleable_heading/toggleable_heading_markdown_node.py +26 -18
  107. notionary/blocks/types.py +61 -0
  108. notionary/blocks/video/__init__.py +8 -2
  109. notionary/blocks/video/video_element.py +67 -143
  110. notionary/blocks/video/video_element_models.py +10 -0
  111. notionary/blocks/video/video_markdown_node.py +3 -1
  112. notionary/database/client.py +3 -8
  113. notionary/database/database.py +13 -14
  114. notionary/database/database_filter_builder.py +2 -2
  115. notionary/database/database_provider.py +5 -4
  116. notionary/database/models.py +337 -0
  117. notionary/database/notion_database.py +6 -7
  118. notionary/file_upload/client.py +5 -7
  119. notionary/file_upload/models.py +2 -1
  120. notionary/file_upload/notion_file_upload.py +2 -3
  121. notionary/markdown/markdown_builder.py +722 -0
  122. notionary/markdown/markdown_document_model.py +228 -0
  123. notionary/{blocks → markdown}/markdown_node.py +1 -0
  124. notionary/models/notion_database_response.py +0 -338
  125. notionary/page/client.py +9 -10
  126. notionary/page/models.py +327 -0
  127. notionary/page/notion_page.py +99 -52
  128. notionary/page/notion_text_length_utils.py +119 -0
  129. notionary/page/{content/page_content_writer.py → page_content_writer.py} +88 -38
  130. notionary/page/reader/handler/__init__.py +17 -0
  131. notionary/page/reader/handler/base_block_renderer.py +44 -0
  132. notionary/page/reader/handler/block_processing_context.py +35 -0
  133. notionary/page/reader/handler/block_rendering_context.py +43 -0
  134. notionary/page/reader/handler/column_list_renderer.py +51 -0
  135. notionary/page/reader/handler/column_renderer.py +60 -0
  136. notionary/page/reader/handler/line_renderer.py +60 -0
  137. notionary/page/reader/handler/toggle_renderer.py +69 -0
  138. notionary/page/reader/handler/toggleable_heading_renderer.py +89 -0
  139. notionary/page/reader/page_content_retriever.py +69 -0
  140. notionary/page/search_filter_builder.py +2 -1
  141. notionary/page/writer/handler/__init__.py +22 -0
  142. notionary/page/writer/handler/code_handler.py +100 -0
  143. notionary/page/writer/handler/column_handler.py +141 -0
  144. notionary/page/writer/handler/column_list_handler.py +139 -0
  145. notionary/page/writer/handler/line_handler.py +35 -0
  146. notionary/page/writer/handler/line_processing_context.py +54 -0
  147. notionary/page/writer/handler/regular_line_handler.py +92 -0
  148. notionary/page/writer/handler/table_handler.py +130 -0
  149. notionary/page/writer/handler/toggle_handler.py +153 -0
  150. notionary/page/writer/handler/toggleable_heading_handler.py +167 -0
  151. notionary/page/writer/markdown_to_notion_converter.py +76 -0
  152. notionary/telemetry/__init__.py +2 -2
  153. notionary/telemetry/service.py +4 -3
  154. notionary/user/__init__.py +2 -2
  155. notionary/user/base_notion_user.py +2 -1
  156. notionary/user/client.py +2 -3
  157. notionary/user/models.py +1 -0
  158. notionary/user/notion_bot_user.py +4 -5
  159. notionary/user/notion_user.py +3 -4
  160. notionary/user/notion_user_manager.py +3 -2
  161. notionary/user/notion_user_provider.py +1 -1
  162. notionary/util/__init__.py +3 -2
  163. notionary/util/fuzzy.py +2 -1
  164. notionary/util/logging_mixin.py +2 -2
  165. notionary/util/singleton_metaclass.py +1 -1
  166. notionary/workspace.py +3 -2
  167. {notionary-0.2.18.dist-info → notionary-0.2.21.dist-info}/METADATA +12 -8
  168. notionary-0.2.21.dist-info/RECORD +185 -0
  169. notionary/blocks/document/__init__.py +0 -7
  170. notionary/blocks/document/document_element.py +0 -102
  171. notionary/blocks/document/document_markdown_node.py +0 -31
  172. notionary/blocks/image/__init__.py +0 -7
  173. notionary/blocks/image/image_element.py +0 -151
  174. notionary/blocks/markdown_builder.py +0 -356
  175. notionary/blocks/mention/__init__.py +0 -7
  176. notionary/blocks/mention/mention_element.py +0 -229
  177. notionary/blocks/mention/mention_markdown_node.py +0 -38
  178. notionary/blocks/prompts/element_prompt_builder.py +0 -83
  179. notionary/blocks/prompts/element_prompt_content.py +0 -41
  180. notionary/blocks/shared/__init__.py +0 -0
  181. notionary/blocks/shared/models.py +0 -710
  182. notionary/blocks/shared/notion_block_element.py +0 -37
  183. notionary/blocks/shared/text_inline_formatter.py +0 -262
  184. notionary/blocks/shared/text_inline_formatter_new.py +0 -139
  185. notionary/blocks/toggleable_heading/toggleable_heading_models.py +0 -0
  186. notionary/database/models/page_result.py +0 -10
  187. notionary/models/notion_block_response.py +0 -264
  188. notionary/models/notion_page_response.py +0 -78
  189. notionary/models/search_response.py +0 -0
  190. notionary/page/__init__.py +0 -0
  191. notionary/page/content/notion_text_length_utils.py +0 -87
  192. notionary/page/content/page_content_retriever.py +0 -52
  193. notionary/page/formatting/line_processor.py +0 -153
  194. notionary/page/formatting/markdown_to_notion_converter.py +0 -153
  195. notionary/page/markdown_syntax_prompt_generator.py +0 -114
  196. notionary/page/notion_to_markdown_converter.py +0 -179
  197. notionary/page/properites/property_value_extractor.py +0 -0
  198. notionary-0.2.18.dist-info/RECORD +0 -149
  199. /notionary/{blocks/document/document_models.py → markdown/___init__.py} +0 -0
  200. /notionary/{blocks/image/image_models.py → markdown/makdown_document_model.py} +0 -0
  201. /notionary/page/{content/markdown_whitespace_processor.py → markdown_whitespace_processor.py} +0 -0
  202. /notionary/{blocks/mention/mention_models.py → page/reader/handler/context.py} +0 -0
  203. {notionary-0.2.18.dist-info → notionary-0.2.21.dist-info}/LICENSE +0 -0
  204. {notionary-0.2.18.dist-info → notionary-0.2.21.dist-info}/WHEEL +0 -0
@@ -1,710 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from dataclasses import dataclass
4
- from typing import Literal, Optional, Union, Any, Dict
5
- from pydantic import BaseModel
6
-
7
-
8
- # ============================================================================
9
- # ENUMS AND COMMON TYPES
10
- # ============================================================================
11
-
12
- BlockColor = Literal[
13
- "blue",
14
- "blue_background",
15
- "brown",
16
- "brown_background",
17
- "default",
18
- "gray",
19
- "gray_background",
20
- "green",
21
- "green_background",
22
- "orange",
23
- "orange_background",
24
- "yellow",
25
- "yellow_background",
26
- "pink",
27
- "pink_background",
28
- "purple",
29
- "purple_background",
30
- "red",
31
- "red_background",
32
- ]
33
-
34
- BlockType = Literal[
35
- "bookmark",
36
- "breadcrumb",
37
- "bulleted_list_item",
38
- "callout",
39
- "child_database",
40
- "child_page",
41
- "column",
42
- "column_list",
43
- "code",
44
- "divider",
45
- "embed",
46
- "equation",
47
- "file",
48
- "heading_1",
49
- "heading_2",
50
- "heading_3",
51
- "image",
52
- "link_preview",
53
- "link_to_page",
54
- "numbered_list_item",
55
- "paragraph",
56
- "pdf",
57
- "quote",
58
- "synced_block",
59
- "table",
60
- "table_of_contents",
61
- "table_row",
62
- "template",
63
- "to_do",
64
- "toggle",
65
- "unsupported",
66
- "video",
67
- "audio",
68
- ]
69
-
70
- CodeLanguage = Literal[
71
- "abap",
72
- "arduino",
73
- "bash",
74
- "basic",
75
- "c",
76
- "clojure",
77
- "coffeescript",
78
- "c++",
79
- "c#",
80
- "css",
81
- "dart",
82
- "diff",
83
- "docker",
84
- "elixir",
85
- "elm",
86
- "erlang",
87
- "flow",
88
- "fortran",
89
- "f#",
90
- "gherkin",
91
- "glsl",
92
- "go",
93
- "graphql",
94
- "groovy",
95
- "haskell",
96
- "html",
97
- "java",
98
- "javascript",
99
- "json",
100
- "julia",
101
- "kotlin",
102
- "latex",
103
- "less",
104
- "lisp",
105
- "livescript",
106
- "lua",
107
- "makefile",
108
- "markdown",
109
- "markup",
110
- "matlab",
111
- "mermaid",
112
- "nix",
113
- "objective-c",
114
- "ocaml",
115
- "pascal",
116
- "perl",
117
- "php",
118
- "plain text",
119
- "powershell",
120
- "prolog",
121
- "protobuf",
122
- "python",
123
- "r",
124
- "reason",
125
- "ruby",
126
- "rust",
127
- "sass",
128
- "scala",
129
- "scheme",
130
- "scss",
131
- "shell",
132
- "sql",
133
- "swift",
134
- "typescript",
135
- "vb.net",
136
- "verilog",
137
- "vhdl",
138
- "visual basic",
139
- "webassembly",
140
- "xml",
141
- "yaml",
142
- "java/c/c++/c#",
143
- ]
144
-
145
-
146
- # ============================================================================
147
- # RICH TEXT AND COMMON OBJECTS
148
- # ============================================================================
149
-
150
-
151
- class TextAnnotations(BaseModel):
152
- bold: bool = False
153
- italic: bool = False
154
- strikethrough: bool = False
155
- underline: bool = False
156
- code: bool = False
157
- color: BlockColor = "default"
158
-
159
-
160
- class TextContent(BaseModel):
161
- content: str
162
- link: Optional[Dict[str, str]] = None
163
-
164
-
165
- class TextObject(BaseModel):
166
- type: Literal["text"]
167
- text: TextContent
168
- annotations: TextAnnotations = TextAnnotations()
169
- plain_text: str
170
- href: Optional[str] = None
171
-
172
-
173
- class MentionDate(BaseModel):
174
- start: str
175
- end: Optional[str] = None
176
- time_zone: Optional[str] = None
177
-
178
-
179
- class MentionUser(BaseModel):
180
- id: str
181
- object: Literal["user"] = "user"
182
-
183
-
184
- class MentionPage(BaseModel):
185
- id: str
186
-
187
-
188
- class MentionDatabase(BaseModel):
189
- id: str
190
-
191
-
192
- class MentionObject(BaseModel):
193
- type: Literal[
194
- "user", "page", "database", "date", "link_preview", "template_mention"
195
- ]
196
- user: Optional[MentionUser] = None
197
- page: Optional[MentionPage] = None
198
- database: Optional[MentionDatabase] = None
199
- date: Optional[MentionDate] = None
200
- # Add other mention types as needed
201
-
202
-
203
- class TextAnnotations(BaseModel):
204
- """Text formatting annotations"""
205
-
206
- bold: bool = False
207
- italic: bool = False
208
- strikethrough: bool = False
209
- underline: bool = False
210
- code: bool = False
211
- color: str = "default"
212
-
213
-
214
- class TextContent(BaseModel):
215
- """Text content with optional link"""
216
-
217
- content: str
218
- link: Optional[str] = None
219
-
220
-
221
- class TextAnnotations(BaseModel):
222
- bold: bool = False
223
- italic: bool = False
224
- strikethrough: bool = False
225
- underline: bool = False
226
- code: bool = False
227
- color: str = "default"
228
-
229
-
230
- class TextContent(BaseModel):
231
- content: str
232
- link: Optional[str] = None
233
-
234
-
235
- class RichTextObject(BaseModel):
236
- type: str = "text"
237
- text: TextContent
238
- annotations: TextAnnotations
239
- plain_text: str
240
- href: Optional[str] = None
241
-
242
- @classmethod
243
- def from_plain_text(cls, content: str, **kwargs) -> RichTextObject:
244
- """Create rich text object from plain text with optional formatting."""
245
- annotations = TextAnnotations(**kwargs)
246
- text_content = TextContent(content=content, link=None)
247
-
248
- return cls(
249
- text=text_content, annotations=annotations, plain_text=content, href=None
250
- )
251
-
252
-
253
- class PageMention(BaseModel):
254
- id: str
255
-
256
-
257
- class MentionContent(BaseModel):
258
- type: Literal["page"] = "page"
259
- page: PageMention
260
-
261
-
262
- class MentionRichText(BaseModel):
263
- type: Literal["mention"] = "mention"
264
- mention: MentionContent
265
- annotations: TextAnnotations
266
- plain_text: str
267
- href: Optional[str] = None
268
-
269
- @classmethod
270
- def from_page_id(cls, page_id: str) -> MentionRichText:
271
- page_mention = PageMention(id=page_id)
272
- mention_content = MentionContent(page=page_mention)
273
- return cls(
274
- mention=mention_content,
275
- annotations=TextAnnotations(),
276
- plain_text=f"@{page_id}",
277
- href=None,
278
- )
279
-
280
-
281
- # ============================================================================
282
- # FILE OBJECTS
283
- # ============================================================================
284
-
285
-
286
- class ExternalFile(BaseModel):
287
- url: str
288
-
289
-
290
- class NotionHostedFile(BaseModel):
291
- url: str
292
- expiry_time: str
293
-
294
-
295
- class FileUploadFile(BaseModel):
296
- id: str
297
-
298
-
299
- class FileObject(BaseModel):
300
- type: Literal["external", "file", "file_upload"]
301
- external: Optional[ExternalFile] = None
302
- file: Optional[NotionHostedFile] = None
303
- file_upload: Optional[FileUploadFile] = None
304
- caption: Optional[list[RichTextObject]] = None
305
- name: Optional[str] = None
306
-
307
-
308
- # ============================================================================
309
- # EMOJI AND ICON OBJECTS
310
- # ============================================================================
311
-
312
-
313
- class EmojiIcon(BaseModel):
314
- type: Literal["emoji"] = "emoji"
315
- emoji: str
316
-
317
-
318
- class FileIcon(BaseModel):
319
- type: Literal["file"] = "file"
320
- file: FileObject
321
-
322
-
323
- IconObject = Union[EmojiIcon, FileIcon]
324
-
325
-
326
- # ============================================================================
327
- # PARENT OBJECTS
328
- # ============================================================================
329
-
330
-
331
- class PageParent(BaseModel):
332
- type: Literal["page_id"]
333
- page_id: str
334
-
335
-
336
- class DatabaseParent(BaseModel):
337
- type: Literal["database_id"]
338
- database_id: str
339
-
340
-
341
- class BlockParent(BaseModel):
342
- type: Literal["block_id"]
343
- block_id: str
344
-
345
-
346
- class WorkspaceParent(BaseModel):
347
- type: Literal["workspace"]
348
- workspace: bool = True
349
-
350
-
351
- ParentObject = Union[PageParent, DatabaseParent, BlockParent, WorkspaceParent]
352
-
353
-
354
- # ============================================================================
355
- # USER OBJECTS
356
- # ============================================================================
357
-
358
-
359
- class PartialUser(BaseModel):
360
- object: Literal["user"]
361
- id: str
362
-
363
-
364
- # ============================================================================
365
- # BLOCK TYPE OBJECTS
366
- # ============================================================================
367
-
368
-
369
- class ExternalUrl(BaseModel):
370
- url: str
371
-
372
-
373
- class AudioContent(BaseModel):
374
- type: Literal["external"]
375
- external: ExternalUrl
376
- caption: Optional[list[RichTextObject]] = None
377
-
378
-
379
- class AudioBlockCreate(BaseModel):
380
- type: Literal["audio"]
381
- audio: AudioContent
382
-
383
-
384
- class AudioBlock(BaseModel):
385
- type: Literal["external", "file", "file_upload"]
386
- external: Optional[ExternalFile] = None
387
- file: Optional[NotionHostedFile] = None
388
- file_upload: Optional[FileUploadFile] = None
389
-
390
-
391
- class BookmarkBlock(BaseModel):
392
- caption: list[RichTextObject] = []
393
- url: str
394
-
395
-
396
- class BreadcrumbBlock(BaseModel):
397
- pass
398
-
399
-
400
- class BulletedListItemBlock(BaseModel):
401
- rich_text: list[RichTextObject]
402
- color: BlockColor = "default"
403
- children: Optional[list["Block"]] = None
404
-
405
-
406
- class CalloutBlock(BaseModel):
407
- rich_text: list[RichTextObject]
408
- icon: Optional[IconObject] = None
409
- color: BlockColor = "default"
410
- children: Optional[list["Block"]] = None
411
-
412
-
413
- class ChildDatabaseBlock(BaseModel):
414
- title: str
415
-
416
-
417
- class ChildPageBlock(BaseModel):
418
- title: str
419
-
420
-
421
- class CodeBlock(BaseModel):
422
- caption: list[RichTextObject] = []
423
- rich_text: list[RichTextObject]
424
- language: CodeLanguage = "plain text"
425
-
426
-
427
- class ColumnListBlock(BaseModel):
428
- pass
429
-
430
-
431
- class ColumnBlock(BaseModel):
432
- width_ratio: Optional[float] = None
433
-
434
-
435
- class DividerBlock(BaseModel):
436
- pass
437
-
438
-
439
- class EmbedBlock(BaseModel):
440
- url: str
441
-
442
-
443
- class EquationBlock(BaseModel):
444
- expression: str
445
-
446
-
447
- class FileBlock(BaseModel):
448
- caption: list[RichTextObject] = []
449
- type: Literal["external", "file", "file_upload"]
450
- external: Optional[ExternalFile] = None
451
- file: Optional[NotionHostedFile] = None
452
- file_upload: Optional[FileUploadFile] = None
453
- name: Optional[str] = None
454
-
455
-
456
- class HeadingBlock(BaseModel):
457
- rich_text: list[RichTextObject]
458
- color: BlockColor = "default"
459
- is_toggleable: bool = False
460
- children: Optional[list["Block"]] = None
461
-
462
-
463
- class ImageBlock(BaseModel):
464
- type: Literal["external", "file", "file_upload"]
465
- external: Optional[ExternalFile] = None
466
- file: Optional[NotionHostedFile] = None
467
- file_upload: Optional[FileUploadFile] = None
468
- caption: Optional[list[RichTextObject]] = None
469
-
470
-
471
- class LinkPreviewBlock(BaseModel):
472
- url: str
473
-
474
-
475
- class LinkToPageBlock(BaseModel):
476
- type: Literal["page_id", "database_id"]
477
- page_id: Optional[str] = None
478
- database_id: Optional[str] = None
479
-
480
-
481
- class NumberedListItemBlock(BaseModel):
482
- rich_text: list[RichTextObject]
483
- color: BlockColor = "default"
484
- children: Optional[list["Block"]] = None
485
-
486
-
487
- class ParagraphBlock(BaseModel):
488
- rich_text: list[RichTextObject]
489
- color: BlockColor = "default"
490
- children: Optional[list["Block"]] = None
491
-
492
-
493
- class PdfBlock(BaseModel):
494
- caption: list[RichTextObject] = []
495
- type: Literal["external", "file", "file_upload"]
496
- external: Optional[ExternalFile] = None
497
- file: Optional[NotionHostedFile] = None
498
- file_upload: Optional[FileUploadFile] = None
499
-
500
-
501
- class QuoteBlock(BaseModel):
502
- rich_text: list[RichTextObject]
503
- color: BlockColor = "default"
504
- children: Optional[list["Block"]] = None
505
-
506
-
507
- class SyncedFromObject(BaseModel):
508
- type: Literal["block_id"]
509
- block_id: str
510
-
511
-
512
- class SyncedBlock(BaseModel):
513
- synced_from: Optional[SyncedFromObject] = (
514
- None # None for original, object for duplicate
515
- )
516
- children: Optional[list["Block"]] = None
517
-
518
-
519
- class TableBlock(BaseModel):
520
- table_width: int
521
- has_column_header: bool = False
522
- has_row_header: bool = False
523
-
524
-
525
- class TableRowBlock(BaseModel):
526
- cells: list[list[RichTextObject]]
527
-
528
-
529
- class TableOfContentsBlock(BaseModel):
530
- color: BlockColor = "default"
531
-
532
-
533
- class TemplateBlock(BaseModel):
534
- rich_text: list[RichTextObject]
535
- children: Optional[list["Block"]] = None
536
-
537
-
538
- class ToDoBlock(BaseModel):
539
- rich_text: list[RichTextObject]
540
- checked: bool = False
541
- color: BlockColor = "default"
542
- children: Optional[list["Block"]] = None
543
-
544
-
545
- class ToggleBlock(BaseModel):
546
- rich_text: list[RichTextObject]
547
- color: BlockColor = "default"
548
- children: Optional[list["Block"]] = None
549
-
550
-
551
- class VideoBlock(BaseModel):
552
- type: Literal["external", "file", "file_upload"]
553
- external: Optional[ExternalFile] = None
554
- file: Optional[NotionHostedFile] = None
555
- file_upload: Optional[FileUploadFile] = None
556
- caption: Optional[list[RichTextObject]] = None
557
-
558
-
559
- class UnsupportedBlock(BaseModel):
560
- pass
561
-
562
-
563
- # ============================================================================
564
- # MAIN BLOCK MODEL
565
- # ============================================================================
566
-
567
-
568
- class Block(BaseModel):
569
- object: Literal["block"]
570
- id: str
571
- parent: Optional[ParentObject] = None
572
- type: BlockType
573
- created_time: str
574
- last_edited_time: str
575
- created_by: PartialUser
576
- last_edited_by: PartialUser
577
- archived: bool = False
578
- in_trash: bool = False
579
- has_children: bool = False
580
-
581
- # Block type-specific content (only one will be populated based on type)
582
- audio: Optional[AudioBlock] = None
583
- bookmark: Optional[BookmarkBlock] = None
584
- breadcrumb: Optional[BreadcrumbBlock] = None
585
- bulleted_list_item: Optional[BulletedListItemBlock] = None
586
- callout: Optional[CalloutBlock] = None
587
- child_database: Optional[ChildDatabaseBlock] = None
588
- child_page: Optional[ChildPageBlock] = None
589
- code: Optional[CodeBlock] = None
590
- column_list: Optional[ColumnListBlock] = None
591
- column: Optional[ColumnBlock] = None
592
- divider: Optional[DividerBlock] = None
593
- embed: Optional[EmbedBlock] = None
594
- equation: Optional[EquationBlock] = None
595
- file: Optional[FileBlock] = None
596
- heading_1: Optional[HeadingBlock] = None
597
- heading_2: Optional[HeadingBlock] = None
598
- heading_3: Optional[HeadingBlock] = None
599
- image: Optional[ImageBlock] = None
600
- link_preview: Optional[LinkPreviewBlock] = None
601
- link_to_page: Optional[LinkToPageBlock] = None
602
- numbered_list_item: Optional[NumberedListItemBlock] = None
603
- paragraph: Optional[ParagraphBlock] = None
604
- pdf: Optional[PdfBlock] = None
605
- quote: Optional[QuoteBlock] = None
606
- synced_block: Optional[SyncedBlock] = None
607
- table: Optional[TableBlock] = None
608
- table_row: Optional[TableRowBlock] = None
609
- table_of_contents: Optional[TableOfContentsBlock] = None
610
- template: Optional[TemplateBlock] = None
611
- to_do: Optional[ToDoBlock] = None
612
- toggle: Optional[ToggleBlock] = None
613
- video: Optional[VideoBlock] = None
614
- unsupported: Optional[UnsupportedBlock] = None
615
-
616
- def get_block_content(self) -> Optional[Any]:
617
- """Get the content object for this block based on its type."""
618
- return getattr(self, self.type, None)
619
-
620
-
621
- # Forward reference resolution
622
- Block.model_rebuild()
623
- BulletedListItemBlock.model_rebuild()
624
- CalloutBlock.model_rebuild()
625
- HeadingBlock.model_rebuild()
626
- NumberedListItemBlock.model_rebuild()
627
- ParagraphBlock.model_rebuild()
628
- QuoteBlock.model_rebuild()
629
- SyncedBlock.model_rebuild()
630
- TemplateBlock.model_rebuild()
631
- ToDoBlock.model_rebuild()
632
- ToggleBlock.model_rebuild()
633
-
634
-
635
- # ============================================================================
636
- # API REQUEST/RESPONSE MODELS
637
- # ============================================================================
638
-
639
-
640
- class BlockChildrenResponse(BaseModel):
641
- object: Literal["list"]
642
- results: list[Block]
643
- next_cursor: Optional[str] = None
644
- has_more: bool
645
- type: Literal["block"]
646
- block: Dict = {}
647
- request_id: str
648
-
649
-
650
- class AppendBlockChildrenRequest(BaseModel):
651
- children: list[Dict[str, Any]] # Block creation objects
652
- after: Optional[str] = None
653
-
654
-
655
- class UpdateBlockRequest(BaseModel):
656
- # Type-specific updates based on block type
657
- # This would contain the block-specific content to update
658
- pass
659
-
660
-
661
- class BlockResponse(BaseModel):
662
- """Single block response from the API"""
663
-
664
- object: Literal["block"]
665
- id: str
666
- parent: Optional[ParentObject] = None
667
- type: BlockType
668
- created_time: str
669
- last_edited_time: str
670
- created_by: PartialUser
671
- last_edited_by: PartialUser
672
- archived: bool = False
673
- in_trash: bool = False
674
- has_children: bool = False
675
- request_id: str
676
-
677
- # Block type-specific content
678
- audio: Optional[AudioBlock] = None
679
- bookmark: Optional[BookmarkBlock] = None
680
- breadcrumb: Optional[BreadcrumbBlock] = None
681
- bulleted_list_item: Optional[BulletedListItemBlock] = None
682
- callout: Optional[CalloutBlock] = None
683
- child_database: Optional[ChildDatabaseBlock] = None
684
- child_page: Optional[ChildPageBlock] = None
685
- code: Optional[CodeBlock] = None
686
- column_list: Optional[ColumnListBlock] = None
687
- column: Optional[ColumnBlock] = None
688
- divider: Optional[DividerBlock] = None
689
- embed: Optional[EmbedBlock] = None
690
- equation: Optional[EquationBlock] = None
691
- file: Optional[FileBlock] = None
692
- heading_1: Optional[HeadingBlock] = None
693
- heading_2: Optional[HeadingBlock] = None
694
- heading_3: Optional[HeadingBlock] = None
695
- image: Optional[ImageBlock] = None
696
- link_preview: Optional[LinkPreviewBlock] = None
697
- link_to_page: Optional[LinkToPageBlock] = None
698
- numbered_list_item: Optional[NumberedListItemBlock] = None
699
- paragraph: Optional[ParagraphBlock] = None
700
- pdf: Optional[PdfBlock] = None
701
- quote: Optional[QuoteBlock] = None
702
- synced_block: Optional[SyncedBlock] = None
703
- table: Optional[TableBlock] = None
704
- table_row: Optional[TableRowBlock] = None
705
- table_of_contents: Optional[TableOfContentsBlock] = None
706
- template: Optional[TemplateBlock] = None
707
- to_do: Optional[ToDoBlock] = None
708
- toggle: Optional[ToggleBlock] = None
709
- video: Optional[VideoBlock] = None
710
- unsupported: Optional[UnsupportedBlock] = None