API Reference
md_spreadsheet_parser
ConversionSchema
dataclass
Configuration for converting string values to Python types.
Attributes:
| Name | Type | Description |
|---|---|---|
boolean_pairs |
tuple[tuple[str, str], ...]
|
Pairs of strings representing (True, False). Case-insensitive.
Example: |
custom_converters |
dict[type, Callable[[str], Any]]
|
Dictionary mapping ANY Python type to a conversion function |
field_converters |
dict[str, Callable[[str], Any]]
|
Dictionary mapping field names (str) to conversion functions.
Takes precedence over |
Source code in src/md_spreadsheet_parser/schemas.py
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 | |
ExcelParsingSchema
dataclass
Configuration for parsing Excel-exported data (TSV/CSV or openpyxl).
Attributes:
| Name | Type | Description |
|---|---|---|
header_rows |
int
|
Number of header rows (1 or 2). If 2, headers are flattened to "Parent - Child" format. |
fill_merged_headers |
bool
|
Whether to forward-fill empty header cells (for merged cells in Excel exports). |
delimiter |
str
|
Column separator for TSV/CSV parsing. Default is tab. |
header_separator |
str
|
Separator used when flattening 2-row headers. |
Source code in src/md_spreadsheet_parser/schemas.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
MultiTableParsingSchema
dataclass
Bases: ParsingSchema
Configuration for parsing multiple tables (workbook mode). Inherits from ParsingSchema.
Attributes:
| Name | Type | Description |
|---|---|---|
root_marker |
str
|
The marker indicating the start of the data section. Defaults to "# Tables". |
sheet_header_level |
int
|
The markdown header level for sheets. Defaults to 2 (e.g. |
table_header_level |
int | None
|
The markdown header level for tables. If None, table names are not extracted. Defaults to None. |
capture_description |
bool
|
Whether to capture text between the table header and the table as a description. Defaults to False. |
Source code in src/md_spreadsheet_parser/schemas.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
ParsingSchema
dataclass
Configuration for parsing markdown tables. Designed to be immutable and passed to pure functions.
Attributes:
| Name | Type | Description |
|---|---|---|
column_separator |
str
|
Character used to separate columns. Defaults to "|". |
header_separator_char |
str
|
Character used in the separator row. Defaults to "-". |
require_outer_pipes |
bool
|
Whether tables must have outer pipes (e.g. |
strip_whitespace |
bool
|
Whether to strip whitespace from cell values. Defaults to True. |
Source code in src/md_spreadsheet_parser/schemas.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
Sheet
dataclass
Represents a single sheet containing tables.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the sheet. |
tables |
list[Table]
|
List of tables contained in this sheet. |
metadata |
dict[str, Any] | None
|
Arbitrary metadata (e.g. layout). Defaults to None. |
Source code in src/md_spreadsheet_parser/models.py
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 | |
json
property
Returns a JSON-compatible dictionary representation of the sheet.
Returns:
| Name | Type | Description |
|---|---|---|
SheetJSON |
SheetJSON
|
A dictionary containing the sheet data. |
get_table(name)
Retrieve a table by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the table to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Table | None
|
Table | None: The table object if found, otherwise None. |
Source code in src/md_spreadsheet_parser/models.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
to_markdown(schema=DEFAULT_SCHEMA)
Generates a Markdown string representation of the sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
ParsingSchema
|
Configuration for formatting. |
DEFAULT_SCHEMA
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The Markdown string. |
Source code in src/md_spreadsheet_parser/models.py
397 398 399 400 401 402 403 404 405 406 407 | |
Table
dataclass
Represents a parsed table with optional metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
headers |
list[str] | None
|
List of column headers, or None if the table has no headers. |
rows |
list[list[str]]
|
List of data rows. |
alignments |
list[AlignmentType] | None
|
List of column alignments ('left', 'center', 'right'). Defaults to None. |
name |
str | None
|
Name of the table (e.g. from a header). Defaults to None. |
description |
str | None
|
Description of the table. Defaults to None. |
metadata |
dict[str, Any] | None
|
Arbitrary metadata. Defaults to None. |
Source code in src/md_spreadsheet_parser/models.py
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 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 | |
json
property
Returns a JSON-compatible dictionary representation of the table.
Returns:
| Name | Type | Description |
|---|---|---|
TableJSON |
TableJSON
|
A dictionary containing the table data. |
clear_column_data(col_idx)
Return a new Table with data in the specified column cleared (set to empty string), but headers and column structure preserved.
Source code in src/md_spreadsheet_parser/models.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
delete_column(col_idx)
Return a new Table with the column at index removed.
Source code in src/md_spreadsheet_parser/models.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
delete_row(row_idx)
Return a new Table with the row at index removed.
Source code in src/md_spreadsheet_parser/models.py
227 228 229 230 231 232 233 234 | |
insert_column(col_idx)
Return a new Table with an empty column inserted at col_idx. Subsequent columns are shifted right.
Source code in src/md_spreadsheet_parser/models.py
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 | |
insert_row(row_idx)
Return a new Table with an empty row inserted at row_idx. Subsequent rows are shifted down.
Source code in src/md_spreadsheet_parser/models.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
to_markdown(schema=DEFAULT_SCHEMA)
Generates a Markdown string representation of the table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
ParsingSchema
|
Configuration for formatting. |
DEFAULT_SCHEMA
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The Markdown string. |
Source code in src/md_spreadsheet_parser/models.py
125 126 127 128 129 130 131 132 133 134 135 | |
to_models(schema_cls, conversion_schema=DEFAULT_CONVERSION_SCHEMA)
Converts the table rows into a list of dataclass instances, performing validation and type conversion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema_cls
|
type[T]
|
The dataclass type to validate against. |
required |
conversion_schema
|
ConversionSchema
|
Configuration for type conversion. |
DEFAULT_CONVERSION_SCHEMA
|
Returns:
| Type | Description |
|---|---|
list[T]
|
list[T]: A list of validated dataclass instances. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If schema_cls is not a dataclass. |
TableValidationError
|
If validation fails for any row or if the table has no headers. |
Source code in src/md_spreadsheet_parser/models.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
update_cell(row_idx, col_idx, value)
Return a new Table with the specified cell updated.
Source code in src/md_spreadsheet_parser/models.py
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 | |
TableValidationError
Bases: Exception
Exception raised when table validation fails. Contains a list of errors found during validation.
Source code in src/md_spreadsheet_parser/validation.py
14 15 16 17 18 19 20 21 22 23 24 | |
Workbook
dataclass
Represents a collection of sheets (multi-table output).
Attributes:
| Name | Type | Description |
|---|---|---|
sheets |
list[Sheet]
|
List of sheets in the workbook. |
metadata |
dict[str, Any] | None
|
Arbitrary metadata. Defaults to None. |
Source code in src/md_spreadsheet_parser/models.py
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 441 442 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 | |
json
property
Returns a JSON-compatible dictionary representation of the workbook.
Returns:
| Name | Type | Description |
|---|---|---|
WorkbookJSON |
WorkbookJSON
|
A dictionary containing the workbook data. |
add_sheet(name)
Return a new Workbook with a new sheet added.
Source code in src/md_spreadsheet_parser/models.py
468 469 470 471 472 473 474 475 476 477 478 479 | |
delete_sheet(index)
Return a new Workbook with the sheet at index removed.
Source code in src/md_spreadsheet_parser/models.py
481 482 483 484 485 486 487 488 489 490 491 | |
get_sheet(name)
Retrieve a sheet by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the sheet to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Sheet | None
|
Sheet | None: The sheet object if found, otherwise None. |
Source code in src/md_spreadsheet_parser/models.py
441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
to_markdown(schema)
Generates a Markdown string representation of the workbook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
MultiTableParsingSchema
|
Configuration for formatting. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The Markdown string. |
Source code in src/md_spreadsheet_parser/models.py
456 457 458 459 460 461 462 463 464 465 466 | |
generate_sheet_markdown(sheet, schema=DEFAULT_SCHEMA)
Generates a Markdown string representation of the sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Sheet
|
The Sheet object. |
required |
schema
|
ParsingSchema
|
Configuration for formatting. |
DEFAULT_SCHEMA
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The Markdown string. |
Source code in src/md_spreadsheet_parser/generator.py
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 | |
generate_table_markdown(table, schema=DEFAULT_SCHEMA)
Generates a Markdown string representation of the table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
Table
|
The Table object. |
required |
schema
|
ParsingSchema
|
Configuration for formatting. |
DEFAULT_SCHEMA
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The Markdown string. |
Source code in src/md_spreadsheet_parser/generator.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 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 | |
generate_workbook_markdown(workbook, schema)
Generates a Markdown string representation of the workbook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workbook
|
Workbook
|
The Workbook object. |
required |
schema
|
MultiTableParsingSchema
|
Configuration for formatting. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The Markdown string. |
Source code in src/md_spreadsheet_parser/generator.py
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 | |
parse_excel(source, schema=DEFAULT_EXCEL_SCHEMA)
Parse Excel data from various sources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
ExcelSource
|
One of: - openpyxl.Worksheet (if openpyxl is installed) - str: TSV/CSV text content - list[list[str]]: Pre-parsed 2D array |
required |
schema
|
ExcelParsingSchema
|
Configuration for parsing. |
DEFAULT_EXCEL_SCHEMA
|
Returns:
| Type | Description |
|---|---|
Table
|
Table object with processed headers and data. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If source type is not supported. |
Source code in src/md_spreadsheet_parser/excel.py
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 | |
parse_excel_text(rows, schema=DEFAULT_EXCEL_SCHEMA)
Parse a 2D string array into a Table with merged cell and header handling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
list[list[str]]
|
2D list of strings (e.g., from csv.reader or worksheet iteration). |
required |
schema
|
ExcelParsingSchema
|
Configuration for header processing. |
DEFAULT_EXCEL_SCHEMA
|
Returns:
| Type | Description |
|---|---|
Table
|
Table object with processed headers and data rows. |
Source code in src/md_spreadsheet_parser/excel.py
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 | |
parse_sheet(markdown, name, schema, start_line_offset=0)
Parse a sheet (section) containing one or more tables.
Source code in src/md_spreadsheet_parser/parsing.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | |
parse_table(markdown, schema=DEFAULT_SCHEMA)
Parse a markdown table into a Table object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
markdown
|
str
|
The markdown string containing the table. |
required |
schema
|
ParsingSchema
|
Configuration for parsing. |
DEFAULT_SCHEMA
|
Returns:
| Type | Description |
|---|---|
Table
|
Table object with headers and rows. |
Source code in src/md_spreadsheet_parser/parsing.py
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 | |
parse_table_from_file(source, schema=DEFAULT_SCHEMA)
Parse a markdown table from a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Union[str, Path, TextIO]
|
File path (str/Path) or file-like object. |
required |
schema
|
ParsingSchema
|
Parsing configuration. |
DEFAULT_SCHEMA
|
Source code in src/md_spreadsheet_parser/loader.py
20 21 22 23 24 25 26 27 28 29 30 31 | |
parse_workbook(markdown, schema=MultiTableParsingSchema())
Parse a markdown document into a Workbook.
Source code in src/md_spreadsheet_parser/parsing.py
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 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | |
parse_workbook_from_file(source, schema=MultiTableParsingSchema())
Parse a markdown workbook from a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Union[str, Path, TextIO]
|
File path (str/Path) or file-like object. |
required |
schema
|
MultiTableParsingSchema
|
Parsing configuration. |
MultiTableParsingSchema()
|
Source code in src/md_spreadsheet_parser/loader.py
34 35 36 37 38 39 40 41 42 43 44 45 46 | |
scan_tables(markdown, schema=None)
Scan a markdown document for all tables, ignoring sheet structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
markdown
|
str
|
The markdown text. |
required |
schema
|
MultiTableParsingSchema | None
|
Optional schema. If None, uses default MultiTableParsingSchema. |
None
|
Returns:
Source code in src/md_spreadsheet_parser/parsing.py
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | |
scan_tables_from_file(source, schema=None)
Scan a markdown file for all tables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Union[str, Path, TextIO]
|
File path (str/Path) or file-like object. |
required |
schema
|
MultiTableParsingSchema | None
|
Optional schema. |
None
|
Source code in src/md_spreadsheet_parser/loader.py
49 50 51 52 53 54 55 56 57 58 59 60 | |
scan_tables_iter(source, schema=None)
Stream tables from a source (file path, file object, or iterable) one by one. This allows processing files larger than memory, provided that individual tables fit in memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Union[str, Path, TextIO, Iterable[str]]
|
File path, open file object, or iterable of strings. |
required |
schema
|
MultiTableParsingSchema | None
|
Parsing configuration. |
None
|
Yields:
| Type | Description |
|---|---|
Table
|
Table objects found in the stream. |
Source code in src/md_spreadsheet_parser/loader.py
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 | |
md_spreadsheet_parser.schemas
ConversionSchema
dataclass
Configuration for converting string values to Python types.
Attributes:
| Name | Type | Description |
|---|---|---|
boolean_pairs |
tuple[tuple[str, str], ...]
|
Pairs of strings representing (True, False). Case-insensitive.
Example: |
custom_converters |
dict[type, Callable[[str], Any]]
|
Dictionary mapping ANY Python type to a conversion function |
field_converters |
dict[str, Callable[[str], Any]]
|
Dictionary mapping field names (str) to conversion functions.
Takes precedence over |
Source code in src/md_spreadsheet_parser/schemas.py
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 | |
ExcelParsingSchema
dataclass
Configuration for parsing Excel-exported data (TSV/CSV or openpyxl).
Attributes:
| Name | Type | Description |
|---|---|---|
header_rows |
int
|
Number of header rows (1 or 2). If 2, headers are flattened to "Parent - Child" format. |
fill_merged_headers |
bool
|
Whether to forward-fill empty header cells (for merged cells in Excel exports). |
delimiter |
str
|
Column separator for TSV/CSV parsing. Default is tab. |
header_separator |
str
|
Separator used when flattening 2-row headers. |
Source code in src/md_spreadsheet_parser/schemas.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
MultiTableParsingSchema
dataclass
Bases: ParsingSchema
Configuration for parsing multiple tables (workbook mode). Inherits from ParsingSchema.
Attributes:
| Name | Type | Description |
|---|---|---|
root_marker |
str
|
The marker indicating the start of the data section. Defaults to "# Tables". |
sheet_header_level |
int
|
The markdown header level for sheets. Defaults to 2 (e.g. |
table_header_level |
int | None
|
The markdown header level for tables. If None, table names are not extracted. Defaults to None. |
capture_description |
bool
|
Whether to capture text between the table header and the table as a description. Defaults to False. |
Source code in src/md_spreadsheet_parser/schemas.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
ParsingSchema
dataclass
Configuration for parsing markdown tables. Designed to be immutable and passed to pure functions.
Attributes:
| Name | Type | Description |
|---|---|---|
column_separator |
str
|
Character used to separate columns. Defaults to "|". |
header_separator_char |
str
|
Character used in the separator row. Defaults to "-". |
require_outer_pipes |
bool
|
Whether tables must have outer pipes (e.g. |
strip_whitespace |
bool
|
Whether to strip whitespace from cell values. Defaults to True. |
Source code in src/md_spreadsheet_parser/schemas.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
md_spreadsheet_parser.models
Sheet
dataclass
Represents a single sheet containing tables.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the sheet. |
tables |
list[Table]
|
List of tables contained in this sheet. |
metadata |
dict[str, Any] | None
|
Arbitrary metadata (e.g. layout). Defaults to None. |
Source code in src/md_spreadsheet_parser/models.py
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 | |
json
property
Returns a JSON-compatible dictionary representation of the sheet.
Returns:
| Name | Type | Description |
|---|---|---|
SheetJSON |
SheetJSON
|
A dictionary containing the sheet data. |
get_table(name)
Retrieve a table by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the table to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Table | None
|
Table | None: The table object if found, otherwise None. |
Source code in src/md_spreadsheet_parser/models.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
to_markdown(schema=DEFAULT_SCHEMA)
Generates a Markdown string representation of the sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
ParsingSchema
|
Configuration for formatting. |
DEFAULT_SCHEMA
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The Markdown string. |
Source code in src/md_spreadsheet_parser/models.py
397 398 399 400 401 402 403 404 405 406 407 | |
SheetJSON
Bases: TypedDict
JSON-compatible dictionary representation of a Sheet.
Source code in src/md_spreadsheet_parser/models.py
38 39 40 41 42 43 44 45 | |
Table
dataclass
Represents a parsed table with optional metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
headers |
list[str] | None
|
List of column headers, or None if the table has no headers. |
rows |
list[list[str]]
|
List of data rows. |
alignments |
list[AlignmentType] | None
|
List of column alignments ('left', 'center', 'right'). Defaults to None. |
name |
str | None
|
Name of the table (e.g. from a header). Defaults to None. |
description |
str | None
|
Description of the table. Defaults to None. |
metadata |
dict[str, Any] | None
|
Arbitrary metadata. Defaults to None. |
Source code in src/md_spreadsheet_parser/models.py
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 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 | |
json
property
Returns a JSON-compatible dictionary representation of the table.
Returns:
| Name | Type | Description |
|---|---|---|
TableJSON |
TableJSON
|
A dictionary containing the table data. |
clear_column_data(col_idx)
Return a new Table with data in the specified column cleared (set to empty string), but headers and column structure preserved.
Source code in src/md_spreadsheet_parser/models.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
delete_column(col_idx)
Return a new Table with the column at index removed.
Source code in src/md_spreadsheet_parser/models.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
delete_row(row_idx)
Return a new Table with the row at index removed.
Source code in src/md_spreadsheet_parser/models.py
227 228 229 230 231 232 233 234 | |
insert_column(col_idx)
Return a new Table with an empty column inserted at col_idx. Subsequent columns are shifted right.
Source code in src/md_spreadsheet_parser/models.py
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 | |
insert_row(row_idx)
Return a new Table with an empty row inserted at row_idx. Subsequent rows are shifted down.
Source code in src/md_spreadsheet_parser/models.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
to_markdown(schema=DEFAULT_SCHEMA)
Generates a Markdown string representation of the table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
ParsingSchema
|
Configuration for formatting. |
DEFAULT_SCHEMA
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The Markdown string. |
Source code in src/md_spreadsheet_parser/models.py
125 126 127 128 129 130 131 132 133 134 135 | |
to_models(schema_cls, conversion_schema=DEFAULT_CONVERSION_SCHEMA)
Converts the table rows into a list of dataclass instances, performing validation and type conversion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema_cls
|
type[T]
|
The dataclass type to validate against. |
required |
conversion_schema
|
ConversionSchema
|
Configuration for type conversion. |
DEFAULT_CONVERSION_SCHEMA
|
Returns:
| Type | Description |
|---|---|
list[T]
|
list[T]: A list of validated dataclass instances. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If schema_cls is not a dataclass. |
TableValidationError
|
If validation fails for any row or if the table has no headers. |
Source code in src/md_spreadsheet_parser/models.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
update_cell(row_idx, col_idx, value)
Return a new Table with the specified cell updated.
Source code in src/md_spreadsheet_parser/models.py
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 | |
TableJSON
Bases: TypedDict
JSON-compatible dictionary representation of a Table.
Source code in src/md_spreadsheet_parser/models.py
23 24 25 26 27 28 29 30 31 32 33 34 35 | |
Workbook
dataclass
Represents a collection of sheets (multi-table output).
Attributes:
| Name | Type | Description |
|---|---|---|
sheets |
list[Sheet]
|
List of sheets in the workbook. |
metadata |
dict[str, Any] | None
|
Arbitrary metadata. Defaults to None. |
Source code in src/md_spreadsheet_parser/models.py
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 441 442 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 | |
json
property
Returns a JSON-compatible dictionary representation of the workbook.
Returns:
| Name | Type | Description |
|---|---|---|
WorkbookJSON |
WorkbookJSON
|
A dictionary containing the workbook data. |
add_sheet(name)
Return a new Workbook with a new sheet added.
Source code in src/md_spreadsheet_parser/models.py
468 469 470 471 472 473 474 475 476 477 478 479 | |
delete_sheet(index)
Return a new Workbook with the sheet at index removed.
Source code in src/md_spreadsheet_parser/models.py
481 482 483 484 485 486 487 488 489 490 491 | |
get_sheet(name)
Retrieve a sheet by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the sheet to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Sheet | None
|
Sheet | None: The sheet object if found, otherwise None. |
Source code in src/md_spreadsheet_parser/models.py
441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
to_markdown(schema)
Generates a Markdown string representation of the workbook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
MultiTableParsingSchema
|
Configuration for formatting. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The Markdown string. |
Source code in src/md_spreadsheet_parser/models.py
456 457 458 459 460 461 462 463 464 465 466 | |
WorkbookJSON
Bases: TypedDict
JSON-compatible dictionary representation of a Workbook.
Source code in src/md_spreadsheet_parser/models.py
48 49 50 51 52 53 54 | |
md_spreadsheet_parser.validation
TableValidationError
Bases: Exception
Exception raised when table validation fails. Contains a list of errors found during validation.
Source code in src/md_spreadsheet_parser/validation.py
14 15 16 17 18 19 20 21 22 23 24 | |
validate_table(table, schema_cls, conversion_schema=DEFAULT_CONVERSION_SCHEMA)
Validates a Table object against a dataclass OR Pydantic schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
Table
|
The Table object to validate. |
required |
schema_cls
|
Type[T]
|
The dataclass or Pydantic model type to validate against. |
required |
conversion_schema
|
ConversionSchema
|
Configuration for type conversion. |
DEFAULT_CONVERSION_SCHEMA
|
Returns:
| Type | Description |
|---|---|
list[T]
|
list[T]: A list of validated instances. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If schema_cls is not a valid schema. |
TableValidationError
|
If validation fails. |
Source code in src/md_spreadsheet_parser/validation.py
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 | |
md_spreadsheet_parser.generator
generate_sheet_markdown(sheet, schema=DEFAULT_SCHEMA)
Generates a Markdown string representation of the sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet
|
Sheet
|
The Sheet object. |
required |
schema
|
ParsingSchema
|
Configuration for formatting. |
DEFAULT_SCHEMA
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The Markdown string. |
Source code in src/md_spreadsheet_parser/generator.py
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 | |
generate_table_markdown(table, schema=DEFAULT_SCHEMA)
Generates a Markdown string representation of the table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
Table
|
The Table object. |
required |
schema
|
ParsingSchema
|
Configuration for formatting. |
DEFAULT_SCHEMA
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The Markdown string. |
Source code in src/md_spreadsheet_parser/generator.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 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 | |
generate_workbook_markdown(workbook, schema)
Generates a Markdown string representation of the workbook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workbook
|
Workbook
|
The Workbook object. |
required |
schema
|
MultiTableParsingSchema
|
Configuration for formatting. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The Markdown string. |
Source code in src/md_spreadsheet_parser/generator.py
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 | |