Notion Datasource
This module contains functionality related to the Notion
datasource.
Cleaner
NotionCleaner
Bases: BaseCleaner
Cleaner for Notion document content.
Implements cleaning logic for Notion databases and pages, removing HTML tags and comments while preserving meaningful content.
Note
Expects documents to be in markdown format.
Source code in src/embedding/datasources/notion/cleaner.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
_clean_database(document)
Clean Notion database content.
Parameters: |
|
---|
Returns: |
|
---|
Source code in src/embedding/datasources/notion/cleaner.py
46 47 48 49 50 51 52 53 54 55 |
|
_clean_page(document)
Clean Notion page content.
Parameters: |
|
---|
Returns: |
|
---|
Source code in src/embedding/datasources/notion/cleaner.py
57 58 59 60 61 62 63 64 65 66 |
|
_get_documents_with_tqdm(documents)
staticmethod
Wrap document iteration with optional progress bar.
Parameters: |
|
---|
Returns: |
|
---|
Source code in src/embedding/datasources/notion/cleaner.py
97 98 99 100 101 102 103 104 105 106 107 |
|
_parse_html_in_markdown(md_text)
staticmethod
Process HTML elements within markdown content.
Converts HTML to markdown and removes content without alphanumeric characters.
Parameters: |
|
---|
Returns: |
|
---|
Note
Uses BeautifulSoup for HTML parsing
Source code in src/embedding/datasources/notion/cleaner.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
clean(documents)
Clean a collection of Notion documents.
Processes both databases and pages, removing HTML artifacts and empty content.
Parameters: |
|
---|
Returns: |
|
---|
Source code in src/embedding/datasources/notion/cleaner.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
Document
NotionDocument
Bases: BaseDocument
Document representation for Notion page content.
Extends BaseDocument to handle Notion-specific document processing including metadata handling and filtering for embeddings and LLM contexts.
Attributes: |
|
---|
Source code in src/embedding/datasources/notion/document.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
_get_metadata(metadata)
staticmethod
Process and enhance page metadata.
Parameters: |
|
---|
Returns: |
|
---|
Source code in src/embedding/datasources/notion/document.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
_set_excluded_embed_metadata_keys()
Configure metadata keys to exclude from embeddings.
Identifies metadata keys not explicitly included in embedding processing and marks them for exclusion.
Source code in src/embedding/datasources/notion/document.py
38 39 40 41 42 43 44 45 46 47 48 49 |
|
_set_excluded_llm_metadata_keys()
Configure metadata keys to exclude from LLM context.
Identifies metadata keys not explicitly included in LLM processing and marks them for exclusion.
Source code in src/embedding/datasources/notion/document.py
51 52 53 54 55 56 57 58 59 60 61 62 |
|
from_page(metadata, text)
classmethod
Create NotionDocument instance from page data.
Parameters: |
|
---|
Returns: |
|
---|
Source code in src/embedding/datasources/notion/document.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
Exporter
NotionExporter
Exporter for converting Notion pages to markdown documents.
Handles extraction and conversion of Notion pages and databases to NotionDocument instances with markdown content.
Attributes: |
|
---|
Source code in src/embedding/datasources/notion/exporter.py
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
|
__init__(api_token)
Initialize Notion exporter.
Parameters: |
|
---|
Source code in src/embedding/datasources/notion/exporter.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
|
run(page_ids=None, database_ids=None)
async
Export Notion content to document collection.
Parameters: |
|
---|
Returns: |
|
---|
Raises: |
|
---|
Source code in src/embedding/datasources/notion/exporter.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
|
_BlockConverter
Bases: BlockConverter
Source code in src/embedding/datasources/notion/exporter.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
convert_block(block, indent=False, indent_level=0)
Converts a block to a Markdown string.
Source code in src/embedding/datasources/notion/exporter.py
62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
_NotionExporterCore
Bases: NotionExporter
Custom version of notion_exporter.exporter.NotionExporter
. Modifications are related to metadata parsing and asynchronous execution.
Large amount of code corresponds to the original implementation. Modifications are marked with Custom modification
comments.
Source code in src/embedding/datasources/notion/exporter.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
|
_async_export_pages(page_ids, database_ids, ids_to_exclude=None, parent_page_ids=None, page_paths=None)
async
Export pages and databases to markdown format.
:param page_ids: List of page IDs to export. :param database_ids: List of database IDs to export. :param ids_to_exclude: List of IDs to ignore.
Source code in src/embedding/datasources/notion/exporter.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
|
_get_database_meta(database_id)
async
Retrieve metadata of a database from Notion.
Custom modification:
- Remove created_by
and last_edited_by
calls.
- Add created_time
, type
and format
.
:param database_id: The ID of the database. :return: A dictionary containing metadata of the database.
Source code in src/embedding/datasources/notion/exporter.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
|
_get_page_meta(page_id)
async
Retrieve metadata of a page from Notion.
Custom modification:
- Remove created_by
and last_edited_by
calls.
- Add created_time
, type
and format
.
:param page_id: The ID of the page. :return: A dictionary containing metadata of the page.
Source code in src/embedding/datasources/notion/exporter.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
async_export_pages(page_ids=None, database_ids=None, ids_to_exclude=None)
async
Export pages and databases to markdown files.
:param page_ids: List of page IDs to export. :param database_ids: List of database IDs to export. :param ids_to_exclude: List of IDs to ignore.
Source code in src/embedding/datasources/notion/exporter.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
|
_PropertyConverter
Bases: PropertyConverter
Source code in src/embedding/datasources/notion/exporter.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
convert_property(property_item)
Converts a Notion property to a Markdown string.
Source code in src/embedding/datasources/notion/exporter.py
47 48 49 50 51 52 53 54 55 56 57 |
|
verification(property_item)
Converts a verification property to a Markdown string.
Source code in src/embedding/datasources/notion/exporter.py
41 42 43 44 45 |
|
Manager
NotionDatasourceManager
Bases: DatasourceManager
Manager for Notion content extraction and processing.
Handles document retrieval, cleaning, splitting and embedding updates for Notion workspaces. Implements the base DatasourceManager interface for Notion-specific processing.
Source code in src/embedding/datasources/notion/manager.py
4 5 6 7 8 9 10 11 12 |
|
Reader
NotionReader
Bases: BaseReader
Reader for extracting documents from Notion workspace.
Implements document extraction from Notion pages and databases with support for batched async operations and export limits.
Attributes: |
|
---|
Source code in src/embedding/datasources/notion/reader.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
__init__(configuration, notion_client, exporter)
Initialize Notion reader.
Parameters: |
|
---|
Source code in src/embedding/datasources/notion/reader.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
_collect_paginated_api(function, limit, **kwargs)
staticmethod
Collect all results from paginated Notion API endpoint.
Parameters: |
|
---|
Returns: |
|
---|
Source code in src/embedding/datasources/notion/reader.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
_export_documents(chunked_ids, objects_type)
async
Export documents in batches.
Parameters: |
|
---|
Returns: |
|
---|
Raises: |
|
---|
Source code in src/embedding/datasources/notion/reader.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
_get_all_ids(objects_type, limit=None)
Fetch all IDs for specified Notion object type.
Parameters: |
|
---|
Returns: |
|
---|
Note
Returns empty list if limit is 0 or negative
Source code in src/embedding/datasources/notion/reader.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
|
_get_current_limit(database_ids, page_ids)
Calculate remaining object limit based on existing IDs.
Parameters: |
|
---|
Returns: |
|
---|
Note
Subtracts total of existing IDs from configured export limit
Source code in src/embedding/datasources/notion/reader.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
_get_ids_from_home_page()
Extract database and page IDs from home page database.
Queries the configured home page database and extracts IDs for both databases and pages.
Returns: |
|
---|
Source code in src/embedding/datasources/notion/reader.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
_has_more_pages(response)
staticmethod
Check if more pages are available.
Parameters: |
|
---|
Returns: |
|
---|
Source code in src/embedding/datasources/notion/reader.py
310 311 312 313 314 315 316 317 318 319 320 |
|
_limit_reached(result, limit)
staticmethod
Check if result count has reached limit.
Parameters: |
|
---|
Returns: |
|
---|
Source code in src/embedding/datasources/notion/reader.py
297 298 299 300 301 302 303 304 305 306 307 308 |
|
get_all_documents()
Synchronous implementation for fetching all documents from the data source.
Source code in src/embedding/datasources/notion/reader.py
55 56 57 58 59 |
|
get_all_documents_async()
async
Asynchronously retrieve all documents from Notion.
Fetches pages and databases in batches, respecting export limits and batch sizes.
Returns: |
|
---|
Source code in src/embedding/datasources/notion/reader.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
Splitter
NotionSplitter
Bases: BaseSplitter
Splitter for Notion content with separate database and page handling.
Implements content splitting for Notion documents by routing databases and pages to specialized splitters.
Attributes: |
|
---|
Source code in src/embedding/datasources/notion/splitter.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
__init__(database_splitter, page_splitter)
Initialize Notion content splitter.
Parameters: |
|
---|
Source code in src/embedding/datasources/notion/splitter.py
21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
split(documents)
Split Notion documents into text nodes.
Separates documents by type and processes them with appropriate splitter.
Parameters: |
|
---|
Returns: |
|
---|
Source code in src/embedding/datasources/notion/splitter.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
Builders
NotionCleanerBuilder
Builder for creating Notion content cleaner instances.
Provides factory method to create NotionCleaner objects.
Source code in src/embedding/datasources/notion/builders.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
build()
staticmethod
Creates a content cleaner for Notion.
Returns: |
|
---|
Source code in src/embedding/datasources/notion/builders.py
129 130 131 132 133 134 135 136 137 |
|
NotionClientBuilder
Builder for creating Notion API client instances.
Provides factory method to create configured Notion API clients.
Source code in src/embedding/datasources/notion/builders.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
build(configuration)
staticmethod
Creates a configured Notion API client.
Parameters: |
|
---|
Returns: |
|
---|
Source code in src/embedding/datasources/notion/builders.py
87 88 89 90 91 92 93 94 95 96 97 98 |
|
NotionDatasourceManagerBuilder
Builder for creating Notion datasource manager instances.
Provides factory method to create configured NotionDatasourceManager with required components for content processing.
Source code in src/embedding/datasources/notion/builders.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
build(configuration, reader, cleaner, splitter)
staticmethod
Creates a configured Notion datasource manager.
Parameters: |
|
---|
Returns: |
|
---|
Source code in src/embedding/datasources/notion/builders.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
NotionExporterBuilder
Builder for creating Notion content exporter instances.
Provides factory method to create configured NotionExporter objects.
Source code in src/embedding/datasources/notion/builders.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
build(configuration)
staticmethod
Creates a configured Notion content exporter.
Parameters: |
|
---|
Returns: |
|
---|
Source code in src/embedding/datasources/notion/builders.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
NotionReaderBuilder
Builder for creating Notion reader instances.
Provides factory method to create configured NotionReader objects.
Source code in src/embedding/datasources/notion/builders.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
build(configuration, notion_client, exporter)
staticmethod
Creates a configured Notion reader.
Parameters: |
|
---|
Returns: |
|
---|
Source code in src/embedding/datasources/notion/builders.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
NotionSplitterBuilder
Builder for creating Notion content splitter instances.
Provides factory method to create configured NotionSplitter objects with separate splitters for databases and pages.
Source code in src/embedding/datasources/notion/builders.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
build(database_splitter, page_splitter)
staticmethod
Creates a configured Notion content splitter.
Parameters: |
|
---|
Returns: |
|
---|
Source code in src/embedding/datasources/notion/builders.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|