notionary 0.3.1__py3-none-any.whl → 0.4.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.
Files changed (201) hide show
  1. notionary/__init__.py +49 -1
  2. notionary/blocks/client.py +37 -11
  3. notionary/blocks/enums.py +0 -6
  4. notionary/blocks/rich_text/markdown_rich_text_converter.py +49 -15
  5. notionary/blocks/rich_text/models.py +13 -4
  6. notionary/blocks/rich_text/name_id_resolver/data_source.py +9 -3
  7. notionary/blocks/rich_text/name_id_resolver/person.py +6 -2
  8. notionary/blocks/rich_text/rich_text_markdown_converter.py +10 -3
  9. notionary/blocks/schemas.py +33 -78
  10. notionary/comments/client.py +19 -6
  11. notionary/comments/factory.py +10 -3
  12. notionary/comments/schemas.py +10 -31
  13. notionary/comments/service.py +12 -4
  14. notionary/data_source/http/data_source_instance_client.py +59 -17
  15. notionary/data_source/properties/schemas.py +156 -115
  16. notionary/data_source/query/builder.py +67 -18
  17. notionary/data_source/query/resolver.py +16 -5
  18. notionary/data_source/query/schema.py +24 -6
  19. notionary/data_source/query/validator.py +18 -6
  20. notionary/data_source/schema/registry.py +31 -12
  21. notionary/data_source/schema/service.py +66 -20
  22. notionary/data_source/schemas.py +2 -2
  23. notionary/data_source/service.py +103 -43
  24. notionary/database/client.py +27 -9
  25. notionary/database/database_metadata_update_client.py +12 -4
  26. notionary/database/schemas.py +2 -2
  27. notionary/database/service.py +14 -9
  28. notionary/exceptions/__init__.py +20 -4
  29. notionary/exceptions/api.py +2 -2
  30. notionary/exceptions/base.py +1 -1
  31. notionary/exceptions/block_parsing.py +9 -5
  32. notionary/exceptions/data_source/builder.py +13 -7
  33. notionary/exceptions/data_source/properties.py +6 -4
  34. notionary/exceptions/file_upload.py +76 -0
  35. notionary/exceptions/properties.py +7 -5
  36. notionary/exceptions/search.py +10 -6
  37. notionary/file_upload/__init__.py +4 -0
  38. notionary/file_upload/client.py +128 -210
  39. notionary/file_upload/config/__init__.py +17 -0
  40. notionary/file_upload/config/config.py +39 -0
  41. notionary/file_upload/config/constants.py +16 -0
  42. notionary/file_upload/file/reader.py +28 -0
  43. notionary/file_upload/query/__init__.py +7 -0
  44. notionary/file_upload/query/builder.py +58 -0
  45. notionary/file_upload/query/models.py +37 -0
  46. notionary/file_upload/schemas.py +80 -0
  47. notionary/file_upload/service.py +182 -291
  48. notionary/file_upload/validation/factory.py +66 -0
  49. notionary/file_upload/validation/impl/file_name_length.py +25 -0
  50. notionary/file_upload/validation/models.py +134 -0
  51. notionary/file_upload/validation/port.py +7 -0
  52. notionary/file_upload/validation/service.py +17 -0
  53. notionary/file_upload/validation/validators/__init__.py +11 -0
  54. notionary/file_upload/validation/validators/file_exists.py +15 -0
  55. notionary/file_upload/validation/validators/file_extension.py +131 -0
  56. notionary/file_upload/validation/validators/file_name_length.py +21 -0
  57. notionary/file_upload/validation/validators/upload_limit.py +31 -0
  58. notionary/http/client.py +33 -30
  59. notionary/page/content/__init__.py +9 -0
  60. notionary/page/content/factory.py +21 -7
  61. notionary/page/content/markdown/builder.py +85 -23
  62. notionary/page/content/markdown/nodes/audio.py +8 -4
  63. notionary/page/content/markdown/nodes/base.py +3 -3
  64. notionary/page/content/markdown/nodes/bookmark.py +5 -3
  65. notionary/page/content/markdown/nodes/breadcrumb.py +2 -2
  66. notionary/page/content/markdown/nodes/bulleted_list.py +5 -3
  67. notionary/page/content/markdown/nodes/callout.py +2 -2
  68. notionary/page/content/markdown/nodes/code.py +5 -3
  69. notionary/page/content/markdown/nodes/columns.py +3 -3
  70. notionary/page/content/markdown/nodes/container.py +9 -5
  71. notionary/page/content/markdown/nodes/divider.py +2 -2
  72. notionary/page/content/markdown/nodes/embed.py +8 -4
  73. notionary/page/content/markdown/nodes/equation.py +4 -2
  74. notionary/page/content/markdown/nodes/file.py +8 -4
  75. notionary/page/content/markdown/nodes/heading.py +2 -2
  76. notionary/page/content/markdown/nodes/image.py +8 -4
  77. notionary/page/content/markdown/nodes/mixins/caption.py +5 -3
  78. notionary/page/content/markdown/nodes/numbered_list.py +5 -3
  79. notionary/page/content/markdown/nodes/paragraph.py +4 -2
  80. notionary/page/content/markdown/nodes/pdf.py +8 -4
  81. notionary/page/content/markdown/nodes/quote.py +2 -2
  82. notionary/page/content/markdown/nodes/space.py +2 -2
  83. notionary/page/content/markdown/nodes/table.py +8 -5
  84. notionary/page/content/markdown/nodes/table_of_contents.py +2 -2
  85. notionary/page/content/markdown/nodes/todo.py +15 -7
  86. notionary/page/content/markdown/nodes/toggle.py +2 -2
  87. notionary/page/content/markdown/nodes/video.py +8 -4
  88. notionary/page/content/markdown/structured_output/__init__.py +73 -0
  89. notionary/page/content/markdown/structured_output/models.py +391 -0
  90. notionary/page/content/markdown/structured_output/service.py +211 -0
  91. notionary/page/content/parser/context.py +1 -1
  92. notionary/page/content/parser/factory.py +26 -8
  93. notionary/page/content/parser/parsers/audio.py +12 -32
  94. notionary/page/content/parser/parsers/base.py +2 -2
  95. notionary/page/content/parser/parsers/bookmark.py +2 -2
  96. notionary/page/content/parser/parsers/breadcrumb.py +2 -2
  97. notionary/page/content/parser/parsers/bulleted_list.py +19 -6
  98. notionary/page/content/parser/parsers/callout.py +15 -5
  99. notionary/page/content/parser/parsers/caption.py +9 -3
  100. notionary/page/content/parser/parsers/code.py +21 -7
  101. notionary/page/content/parser/parsers/column.py +8 -4
  102. notionary/page/content/parser/parsers/column_list.py +19 -7
  103. notionary/page/content/parser/parsers/divider.py +2 -2
  104. notionary/page/content/parser/parsers/embed.py +2 -4
  105. notionary/page/content/parser/parsers/equation.py +8 -4
  106. notionary/page/content/parser/parsers/file.py +12 -34
  107. notionary/page/content/parser/parsers/file_like_block.py +109 -0
  108. notionary/page/content/parser/parsers/heading.py +31 -10
  109. notionary/page/content/parser/parsers/image.py +12 -34
  110. notionary/page/content/parser/parsers/numbered_list.py +18 -6
  111. notionary/page/content/parser/parsers/paragraph.py +3 -1
  112. notionary/page/content/parser/parsers/pdf.py +12 -34
  113. notionary/page/content/parser/parsers/quote.py +28 -9
  114. notionary/page/content/parser/parsers/space.py +2 -2
  115. notionary/page/content/parser/parsers/table.py +31 -10
  116. notionary/page/content/parser/parsers/table_of_contents.py +7 -3
  117. notionary/page/content/parser/parsers/todo.py +15 -5
  118. notionary/page/content/parser/parsers/toggle.py +15 -5
  119. notionary/page/content/parser/parsers/video.py +12 -34
  120. notionary/page/content/parser/post_processing/handlers/rich_text_length.py +8 -2
  121. notionary/page/content/parser/post_processing/handlers/rich_text_length_truncation.py +8 -2
  122. notionary/page/content/parser/post_processing/service.py +3 -1
  123. notionary/page/content/parser/pre_processsing/handlers/column_syntax.py +21 -7
  124. notionary/page/content/parser/pre_processsing/handlers/indentation.py +11 -4
  125. notionary/page/content/parser/pre_processsing/handlers/video_syntax.py +13 -6
  126. notionary/page/content/parser/service.py +4 -1
  127. notionary/page/content/renderer/context.py +15 -5
  128. notionary/page/content/renderer/factory.py +12 -6
  129. notionary/page/content/renderer/post_processing/handlers/numbered_list.py +19 -9
  130. notionary/page/content/renderer/renderers/audio.py +20 -23
  131. notionary/page/content/renderer/renderers/base.py +3 -3
  132. notionary/page/content/renderer/renderers/bookmark.py +3 -1
  133. notionary/page/content/renderer/renderers/bulleted_list.py +11 -5
  134. notionary/page/content/renderer/renderers/callout.py +19 -7
  135. notionary/page/content/renderer/renderers/captioned_block.py +11 -5
  136. notionary/page/content/renderer/renderers/code.py +6 -2
  137. notionary/page/content/renderer/renderers/column.py +3 -1
  138. notionary/page/content/renderer/renderers/column_list.py +3 -1
  139. notionary/page/content/renderer/renderers/embed.py +3 -1
  140. notionary/page/content/renderer/renderers/equation.py +3 -1
  141. notionary/page/content/renderer/renderers/file.py +20 -23
  142. notionary/page/content/renderer/renderers/file_like_block.py +47 -0
  143. notionary/page/content/renderer/renderers/heading.py +22 -8
  144. notionary/page/content/renderer/renderers/image.py +20 -23
  145. notionary/page/content/renderer/renderers/numbered_list.py +8 -3
  146. notionary/page/content/renderer/renderers/paragraph.py +12 -4
  147. notionary/page/content/renderer/renderers/pdf.py +20 -23
  148. notionary/page/content/renderer/renderers/quote.py +14 -6
  149. notionary/page/content/renderer/renderers/table.py +15 -5
  150. notionary/page/content/renderer/renderers/todo.py +16 -6
  151. notionary/page/content/renderer/renderers/toggle.py +8 -4
  152. notionary/page/content/renderer/renderers/video.py +20 -23
  153. notionary/page/content/renderer/service.py +9 -3
  154. notionary/page/content/service.py +21 -7
  155. notionary/page/content/syntax/definition/__init__.py +11 -0
  156. notionary/page/content/syntax/definition/models.py +57 -0
  157. notionary/page/content/syntax/definition/registry.py +371 -0
  158. notionary/page/content/syntax/prompts/__init__.py +4 -0
  159. notionary/page/content/syntax/prompts/models.py +11 -0
  160. notionary/page/content/syntax/prompts/registry.py +703 -0
  161. notionary/page/page_metadata_update_client.py +12 -4
  162. notionary/page/properties/client.py +46 -16
  163. notionary/page/properties/factory.py +6 -2
  164. notionary/page/properties/{models.py → schemas.py} +93 -107
  165. notionary/page/properties/service.py +111 -37
  166. notionary/page/schemas.py +3 -3
  167. notionary/page/service.py +21 -7
  168. notionary/shared/entity/client.py +6 -2
  169. notionary/shared/entity/dto_parsers.py +4 -37
  170. notionary/shared/entity/entity_metadata_update_client.py +25 -5
  171. notionary/shared/entity/schemas.py +6 -6
  172. notionary/shared/entity/service.py +89 -35
  173. notionary/shared/models/file.py +36 -6
  174. notionary/shared/models/icon.py +5 -12
  175. notionary/user/base.py +6 -2
  176. notionary/user/bot.py +22 -14
  177. notionary/user/client.py +3 -1
  178. notionary/user/person.py +3 -1
  179. notionary/user/schemas.py +3 -1
  180. notionary/user/service.py +6 -2
  181. notionary/utils/decorators.py +13 -9
  182. notionary/utils/fuzzy.py +6 -2
  183. notionary/utils/mixins/logging.py +3 -1
  184. notionary/utils/pagination.py +14 -4
  185. notionary/workspace/__init__.py +6 -2
  186. notionary/workspace/query/__init__.py +2 -1
  187. notionary/workspace/query/service.py +42 -13
  188. notionary/workspace/service.py +74 -46
  189. {notionary-0.3.1.dist-info → notionary-0.4.1.dist-info}/METADATA +1 -1
  190. notionary-0.4.1.dist-info/RECORD +236 -0
  191. notionary/file_upload/models.py +0 -69
  192. notionary/page/blocks/client.py +0 -1
  193. notionary/page/content/syntax/__init__.py +0 -4
  194. notionary/page/content/syntax/models.py +0 -66
  195. notionary/page/content/syntax/registry.py +0 -393
  196. notionary/page/page_context.py +0 -50
  197. notionary/shared/models/cover.py +0 -20
  198. notionary-0.3.1.dist-info/RECORD +0 -211
  199. /notionary/page/content/syntax/{grammar.py → definition/grammar.py} +0 -0
  200. {notionary-0.3.1.dist-info → notionary-0.4.1.dist-info}/WHEEL +0 -0
  201. {notionary-0.3.1.dist-info → notionary-0.4.1.dist-info}/licenses/LICENSE +0 -0
@@ -8,7 +8,10 @@ from notionary.comments.schemas import (
8
8
  CommentListResponse,
9
9
  )
10
10
  from notionary.http.client import NotionHttpClient
11
- from notionary.utils.pagination import paginate_notion_api, paginate_notion_api_generator
11
+ from notionary.utils.pagination import (
12
+ paginate_notion_api,
13
+ paginate_notion_api_generator,
14
+ )
12
15
 
13
16
 
14
17
  class CommentClient(NotionHttpClient):
@@ -21,16 +24,24 @@ class CommentClient(NotionHttpClient):
21
24
  total_results_limit: int | None = None,
22
25
  ) -> AsyncGenerator[CommentDto]:
23
26
  async for comment in paginate_notion_api_generator(
24
- self._list_comments_page, block_id=block_id, total_results_limit=total_results_limit
27
+ self._list_comments_page,
28
+ block_id=block_id,
29
+ total_results_limit=total_results_limit,
25
30
  ):
26
31
  yield comment
27
32
 
28
- async def get_all_comments(self, block_id: str, *, total_results_limit: int | None = None) -> list[CommentDto]:
33
+ async def get_all_comments(
34
+ self, block_id: str, *, total_results_limit: int | None = None
35
+ ) -> list[CommentDto]:
29
36
  all_comments = await paginate_notion_api(
30
- self._list_comments_page, block_id=block_id, total_results_limit=total_results_limit
37
+ self._list_comments_page,
38
+ block_id=block_id,
39
+ total_results_limit=total_results_limit,
31
40
  )
32
41
 
33
- self.logger.debug("Retrieved %d total comments for block %s", len(all_comments), block_id)
42
+ self.logger.debug(
43
+ "Retrieved %d total comments for block %s", len(all_comments), block_id
44
+ )
34
45
  return all_comments
35
46
 
36
47
  async def _list_comments_page(
@@ -65,7 +76,9 @@ class CommentClient(NotionHttpClient):
65
76
  rich_text: list[RichText],
66
77
  discussion_id: str,
67
78
  ) -> CommentDto:
68
- request = CommentCreateRequest.for_discussion(discussion_id=discussion_id, rich_text=rich_text)
79
+ request = CommentCreateRequest.for_discussion(
80
+ discussion_id=discussion_id, rich_text=rich_text
81
+ )
69
82
 
70
83
  body = request.model_dump(exclude_unset=True, exclude_none=True)
71
84
 
@@ -1,6 +1,8 @@
1
1
  import asyncio
2
2
 
3
- from notionary.blocks.rich_text.rich_text_markdown_converter import RichTextToMarkdownConverter
3
+ from notionary.blocks.rich_text.rich_text_markdown_converter import (
4
+ RichTextToMarkdownConverter,
5
+ )
4
6
  from notionary.comments.models import Comment
5
7
  from notionary.comments.schemas import CommentDto
6
8
  from notionary.user.base import BaseUser
@@ -20,7 +22,9 @@ class CommentFactory(LoggingMixin):
20
22
  self.markdown_converter = markdown_converter or RichTextToMarkdownConverter()
21
23
 
22
24
  async def create_from_dto(self, dto: CommentDto) -> Comment:
23
- author_name, content = await asyncio.gather(self._resolve_user_name(dto), self._resolve_content(dto))
25
+ author_name, content = await asyncio.gather(
26
+ self._resolve_user_name(dto), self._resolve_content(dto)
27
+ )
24
28
 
25
29
  return Comment(author_name=author_name, content=content)
26
30
 
@@ -30,7 +34,10 @@ class CommentFactory(LoggingMixin):
30
34
  try:
31
35
  return await BaseUser.from_id_auto(created_by_id, self.http_client)
32
36
  except Exception:
33
- self.logger.warning(f"Failed to resolve user name for user_id: {created_by_id}", exc_info=True)
37
+ self.logger.warning(
38
+ f"Failed to resolve user name for user_id: {created_by_id}",
39
+ exc_info=True,
40
+ )
34
41
 
35
42
  return self.UNKNOWN_AUTHOR
36
43
 
@@ -8,10 +8,6 @@ from pydantic import BaseModel, Field
8
8
 
9
9
  from notionary.blocks.rich_text.models import RichText
10
10
 
11
- # ---------------------------
12
- # Comment Parent
13
- # ---------------------------
14
-
15
11
 
16
12
  class CommentParentType(StrEnum):
17
13
  PAGE_ID = "page_id"
@@ -28,7 +24,7 @@ class BlockCommentParent(BaseModel):
28
24
  block_id: str
29
25
 
30
26
 
31
- CommentParent = PageCommentParent | BlockCommentParent
27
+ type CommentParent = PageCommentParent | BlockCommentParent
32
28
 
33
29
 
34
30
  # ---------------------------
@@ -65,7 +61,9 @@ class CommentAttachmentFileUploadType(StrEnum):
65
61
 
66
62
  class CommentAttachmentInput(BaseModel):
67
63
  file_upload_id: str
68
- type: Literal[CommentAttachmentFileUploadType.FILE_UPLOAD] = CommentAttachmentFileUploadType.FILE_UPLOAD
64
+ type: Literal[CommentAttachmentFileUploadType.FILE_UPLOAD] = (
65
+ CommentAttachmentFileUploadType.FILE_UPLOAD
66
+ )
69
67
 
70
68
 
71
69
  # ---------------------------
@@ -84,7 +82,9 @@ class CustomDisplayName(BaseModel):
84
82
 
85
83
 
86
84
  class IntegrationDisplayName(BaseModel):
87
- type: Literal[CommentDisplayNameType.INTEGRATION] = CommentDisplayNameType.INTEGRATION
85
+ type: Literal[CommentDisplayNameType.INTEGRATION] = (
86
+ CommentDisplayNameType.INTEGRATION
87
+ )
88
88
 
89
89
 
90
90
  class UserDisplayName(BaseModel):
@@ -96,7 +96,9 @@ class CustomCommentDisplayName(BaseModel):
96
96
  custom: CustomDisplayName
97
97
 
98
98
 
99
- CommentDisplayNameInput = IntegrationDisplayName | UserDisplayName | CustomCommentDisplayName
99
+ type CommentDisplayNameInput = (
100
+ IntegrationDisplayName | UserDisplayName | CustomCommentDisplayName
101
+ )
100
102
 
101
103
 
102
104
  class CommentDisplayNameDto(BaseModel):
@@ -189,8 +191,6 @@ class UserRef(BaseModel):
189
191
 
190
192
 
191
193
  class CommentDto(BaseModel):
192
- """Comment object as returned by the API"""
193
-
194
194
  object: Literal["comment"] = "comment"
195
195
  id: str
196
196
 
@@ -217,24 +217,3 @@ class CommentListResponse(BaseModel):
217
217
  results: list[CommentDto] = Field(default_factory=list)
218
218
  next_cursor: str | None = None
219
219
  has_more: bool = False
220
-
221
-
222
- # ---------------------------
223
- # Convenience Builders
224
- # ---------------------------
225
-
226
-
227
- class CommentDisplayNameBuilder:
228
- """Helper class to build display names easily"""
229
-
230
- @staticmethod
231
- def integration() -> IntegrationDisplayName:
232
- return IntegrationDisplayName()
233
-
234
- @staticmethod
235
- def user() -> UserDisplayName:
236
- return UserDisplayName()
237
-
238
- @staticmethod
239
- def custom(name: str) -> CustomCommentDisplayName:
240
- return CustomCommentDisplayName(custom=CustomDisplayName(name=name))
@@ -1,6 +1,8 @@
1
1
  import asyncio
2
2
 
3
- from notionary.blocks.rich_text.markdown_rich_text_converter import MarkdownRichTextConverter
3
+ from notionary.blocks.rich_text.markdown_rich_text_converter import (
4
+ MarkdownRichTextConverter,
5
+ )
4
6
  from notionary.comments.client import CommentClient
5
7
  from notionary.comments.factory import CommentFactory
6
8
  from notionary.comments.models import Comment
@@ -20,15 +22,21 @@ class CommentService:
20
22
  async def list_all_comments_for_page(self, page_id: str) -> list[Comment]:
21
23
  comment_dtos = [dto async for dto in self.client.iter_comments(page_id)]
22
24
 
23
- comments = await asyncio.gather(*(self.factory.create_from_dto(dto) for dto in comment_dtos))
25
+ comments = await asyncio.gather(
26
+ *(self.factory.create_from_dto(dto) for dto in comment_dtos)
27
+ )
24
28
  return comments
25
29
 
26
30
  async def create_comment_on_page(self, page_id: str, text: str) -> Comment:
27
31
  rich_text = await self._converter.to_rich_text(text)
28
- comment_dto = await self.client.create_comment_for_page(rich_text=rich_text, page_id=page_id)
32
+ comment_dto = await self.client.create_comment_for_page(
33
+ rich_text=rich_text, page_id=page_id
34
+ )
29
35
  return await self.factory.create_from_dto(comment_dto)
30
36
 
31
37
  async def reply_to_discussion_by_id(self, discussion_id: str, text: str) -> Comment:
32
38
  rich_text = await self._converter.to_rich_text(text)
33
- comment_dto = await self.client.create_comment_for_discussion(rich_text=rich_text, discussion_id=discussion_id)
39
+ comment_dto = await self.client.create_comment_for_discussion(
40
+ rich_text=rich_text, discussion_id=discussion_id
41
+ )
34
42
  return await self.factory.create_from_dto(comment_dto)
@@ -3,14 +3,25 @@ from __future__ import annotations
3
3
  from collections.abc import AsyncIterator
4
4
  from typing import TYPE_CHECKING, Any, override
5
5
 
6
- from notionary.blocks.rich_text.rich_text_markdown_converter import RichTextToMarkdownConverter
6
+ from notionary.blocks.rich_text.rich_text_markdown_converter import (
7
+ RichTextToMarkdownConverter,
8
+ )
7
9
  from notionary.data_source.query.schema import DataSourceQueryParams
8
- from notionary.data_source.schemas import DataSourceDto, QueryDataSourceResponse, UpdateDataSourceDto
10
+ from notionary.data_source.schemas import (
11
+ DataSourceDto,
12
+ QueryDataSourceResponse,
13
+ UpdateDataSourceDto,
14
+ )
9
15
  from notionary.http.client import NotionHttpClient
10
16
  from notionary.page.schemas import NotionPageDto
11
- from notionary.shared.entity.entity_metadata_update_client import EntityMetadataUpdateClient
17
+ from notionary.shared.entity.entity_metadata_update_client import (
18
+ EntityMetadataUpdateClient,
19
+ )
12
20
  from notionary.shared.typings import JsonDict
13
- from notionary.utils.pagination import paginate_notion_api, paginate_notion_api_generator
21
+ from notionary.utils.pagination import (
22
+ paginate_notion_api,
23
+ paginate_notion_api_generator,
24
+ )
14
25
 
15
26
  if TYPE_CHECKING:
16
27
  from notionary import NotionPage
@@ -22,9 +33,15 @@ class DataSourceInstanceClient(NotionHttpClient, EntityMetadataUpdateClient):
22
33
  self._data_source_id = data_source_id
23
34
 
24
35
  @override
25
- async def patch_metadata(self, update_data_source_dto: UpdateDataSourceDto) -> DataSourceDto:
26
- update_data_source_dto_dict = update_data_source_dto.model_dump(exclude_none=True)
27
- response = await self.patch(f"data_sources/{self._data_source_id}", data=update_data_source_dto_dict)
36
+ async def patch_metadata(
37
+ self, update_data_source_dto: UpdateDataSourceDto
38
+ ) -> DataSourceDto:
39
+ update_data_source_dto_dict = update_data_source_dto.model_dump(
40
+ exclude_none=True
41
+ )
42
+ response = await self.patch(
43
+ f"data_sources/{self._data_source_id}", data=update_data_source_dto_dict
44
+ )
28
45
  return DataSourceDto.model_validate(response)
29
46
 
30
47
  async def update_title(self, title: str) -> DataSourceDto:
@@ -40,28 +57,38 @@ class DataSourceInstanceClient(NotionHttpClient, EntityMetadataUpdateClient):
40
57
  await self.patch_metadata(update_data_source_dto)
41
58
 
42
59
  async def update_description(self, description: str) -> str:
43
- from notionary.blocks.rich_text.markdown_rich_text_converter import MarkdownRichTextConverter
60
+ from notionary.blocks.rich_text.markdown_rich_text_converter import (
61
+ MarkdownRichTextConverter,
62
+ )
44
63
 
45
64
  markdown_rich_text_converter = MarkdownRichTextConverter()
46
- rich_text_description = await markdown_rich_text_converter.to_rich_text(description)
65
+ rich_text_description = await markdown_rich_text_converter.to_rich_text(
66
+ description
67
+ )
47
68
  update_data_source_dto = UpdateDataSourceDto(description=rich_text_description)
48
69
 
49
70
  updated_data_source_dto = await self.patch_metadata(update_data_source_dto)
50
71
 
51
72
  markdown_rich_text_converter = RichTextToMarkdownConverter()
52
73
  updated_markdown_description = (
53
- await markdown_rich_text_converter.to_markdown(updated_data_source_dto.description)
74
+ await markdown_rich_text_converter.to_markdown(
75
+ updated_data_source_dto.description
76
+ )
54
77
  if updated_data_source_dto.description
55
78
  else None
56
79
  )
57
80
  return updated_markdown_description
58
81
 
59
- async def query(self, query_params: DataSourceQueryParams | None = None) -> QueryDataSourceResponse:
82
+ async def query(
83
+ self, query_params: DataSourceQueryParams | None = None
84
+ ) -> QueryDataSourceResponse:
60
85
  query_params_dict = query_params.to_api_params() if query_params else {}
61
86
  total_result_limit = query_params.total_results_limit if query_params else None
62
87
 
63
88
  all_results = await paginate_notion_api(
64
- self._make_query_request, query_data=query_params_dict or {}, total_result_limit=total_result_limit
89
+ self._make_query_request,
90
+ query_data=query_params_dict or {},
91
+ total_result_limit=total_result_limit,
65
92
  )
66
93
 
67
94
  return QueryDataSourceResponse(
@@ -70,17 +97,24 @@ class DataSourceInstanceClient(NotionHttpClient, EntityMetadataUpdateClient):
70
97
  has_more=False,
71
98
  )
72
99
 
73
- async def query_stream(self, query_params: DataSourceQueryParams | None = None) -> AsyncIterator[Any]:
100
+ async def query_stream(
101
+ self, query_params: DataSourceQueryParams | None = None
102
+ ) -> AsyncIterator[Any]:
74
103
  query_params_dict = query_params.model_dump() if query_params else {}
75
104
  total_result_limit = query_params.total_results_limit if query_params else None
76
105
 
77
106
  async for result in paginate_notion_api_generator(
78
- self._make_query_request, query_data=query_params_dict or {}, total_results_limit=total_result_limit
107
+ self._make_query_request,
108
+ query_data=query_params_dict or {},
109
+ total_results_limit=total_result_limit,
79
110
  ):
80
111
  yield result
81
112
 
82
113
  async def _make_query_request(
83
- self, query_data: JsonDict, start_cursor: str | None = None, page_size: int | None = None
114
+ self,
115
+ query_data: JsonDict,
116
+ start_cursor: str | None = None,
117
+ page_size: int | None = None,
84
118
  ) -> QueryDataSourceResponse:
85
119
  current_query_data = query_data.copy()
86
120
  if start_cursor:
@@ -88,13 +122,21 @@ class DataSourceInstanceClient(NotionHttpClient, EntityMetadataUpdateClient):
88
122
  if page_size:
89
123
  current_query_data["page_size"] = page_size
90
124
 
91
- response = await self.post(f"data_sources/{self._data_source_id}/query", data=current_query_data)
125
+ response = await self.post(
126
+ f"data_sources/{self._data_source_id}/query", data=current_query_data
127
+ )
92
128
  return QueryDataSourceResponse.model_validate(response)
93
129
 
94
130
  async def create_blank_page(self, title: str | None = None) -> NotionPage:
95
131
  from notionary import NotionPage
96
132
 
97
- data = {"parent": {"type": "data_source_id", "data_source_id": self._data_source_id}, "properties": {}}
133
+ data = {
134
+ "parent": {
135
+ "type": "data_source_id",
136
+ "data_source_id": self._data_source_id,
137
+ },
138
+ "properties": {},
139
+ }
98
140
 
99
141
  if title:
100
142
  data["properties"]["Name"] = {"title": [{"text": {"content": title}}]}