exstruct 0.3.1__tar.gz → 0.3.5__tar.gz

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 (30) hide show
  1. {exstruct-0.3.1 → exstruct-0.3.5}/PKG-INFO +269 -12
  2. {exstruct-0.3.1 → exstruct-0.3.5}/README.md +268 -11
  3. {exstruct-0.3.1 → exstruct-0.3.5}/pyproject.toml +1 -1
  4. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/core/backends/base.py +5 -1
  5. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/core/backends/com_backend.py +5 -1
  6. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/core/backends/openpyxl_backend.py +13 -1
  7. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/core/cells.py +48 -0
  8. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/core/integrate.py +6 -0
  9. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/core/modeling.py +22 -0
  10. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/core/pipeline.py +180 -4
  11. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/engine.py +12 -0
  12. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/io/__init__.py +14 -6
  13. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/models/__init__.py +34 -3
  14. {exstruct-0.3.1 → exstruct-0.3.5}/LICENSE +0 -0
  15. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/__init__.py +0 -0
  16. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/cli/availability.py +0 -0
  17. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/cli/main.py +0 -0
  18. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/core/__init__.py +0 -0
  19. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/core/backends/__init__.py +0 -0
  20. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/core/charts.py +0 -0
  21. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/core/logging_utils.py +0 -0
  22. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/core/ranges.py +0 -0
  23. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/core/shapes.py +0 -0
  24. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/core/workbook.py +0 -0
  25. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/errors.py +0 -0
  26. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/io/serialize.py +0 -0
  27. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/models/maps.py +0 -0
  28. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/models/types.py +0 -0
  29. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/py.typed +0 -0
  30. {exstruct-0.3.1 → exstruct-0.3.5}/src/exstruct/render/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: exstruct
3
- Version: 0.3.1
3
+ Version: 0.3.5
4
4
  Summary: Excel to structured JSON (tables, shapes, charts) for LLM/RAG pipelines
5
5
  Keywords: excel,structure,data,exstruct
6
6
  Author: harumiWeb
@@ -57,16 +57,16 @@ Description-Content-Type: text/markdown
57
57
 
58
58
  [![PyPI version](https://badge.fury.io/py/exstruct.svg)](https://pypi.org/project/exstruct/) [![PyPI Downloads](https://static.pepy.tech/personalized-badge/exstruct?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=GREEN&left_text=downloads)](https://pepy.tech/projects/exstruct) ![Licence: BSD-3-Clause](https://img.shields.io/badge/license-BSD--3--Clause-blue?style=flat-square) [![pytest](https://github.com/harumiWeb/exstruct/actions/workflows/pytest.yml/badge.svg)](https://github.com/harumiWeb/exstruct/actions/workflows/pytest.yml) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/e081cb4f634e4175b259eb7c34f54f60)](https://app.codacy.com/gh/harumiWeb/exstruct/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) [![codecov](https://codecov.io/gh/harumiWeb/exstruct/graph/badge.svg?token=2XI1O8TTA9)](https://codecov.io/gh/harumiWeb/exstruct)
59
59
 
60
- ![ExStruct Image](/docs/assets/icon.webp)
60
+ ![ExStruct Image](docs/assets/icon.webp)
61
61
 
62
- ExStruct reads Excel workbooks and outputs structured data (cells, table candidates, shapes, charts, smartart, print areas/views, auto page-break areas, hyperlinks) as JSON by default, with optional YAML/TOON formats. It targets both COM/Excel environments (rich extraction) and non-COM environments (cells + table candidates + print areas), with tunable detection heuristics and multiple output modes to fit LLM/RAG pipelines.
62
+ ExStruct reads Excel workbooks and outputs structured data (cells, table candidates, shapes, charts, smartart, merged cell ranges, print areas/views, auto page-break areas, hyperlinks) as JSON by default, with optional YAML/TOON formats. It targets both COM/Excel environments (rich extraction) and non-COM environments (cells + table candidates + print areas), with tunable detection heuristics and multiple output modes to fit LLM/RAG pipelines.
63
63
 
64
64
  [日本版 README](README.ja.md)
65
65
 
66
66
  ## Features
67
67
 
68
68
  - **Excel → Structured JSON**: cells, shapes, charts, smartart, table candidates, print areas/views, and auto page-break areas per sheet.
69
- - **Output modes**: `light` (cells + table candidates + print areas; no COM, shapes/charts empty), `standard` (texted shapes + arrows, charts, smartart, print areas), `verbose` (all shapes with width/height, charts with size, print areas). Verbose also emits cell hyperlinks and `colors_map`. Size output is flag-controlled.
69
+ - **Output modes**: `light` (cells + table candidates + print areas; no COM, shapes/charts empty), `standard` (texted shapes + arrows, charts, smartart, merged cell ranges, print areas), `verbose` (all shapes with width/height, charts with size, merged cell ranges, print areas). Verbose also emits cell hyperlinks and `colors_map`. Size output is flag-controlled.
70
70
  - **Auto page-break export (COM only)**: capture Excel-computed auto page breaks and write per-area JSON/YAML/TOON when requested (CLI option appears only when COM is available).
71
71
  - **Formats**: JSON (compact by default, `--pretty` available), YAML, TOON (optional dependencies).
72
72
  - **Table detection tuning**: adjust heuristics at runtime via API.
@@ -98,8 +98,8 @@ exstruct input.xlsx -o out.json --pretty # pretty JSON to a file
98
98
  exstruct input.xlsx --format yaml # YAML (needs pyyaml)
99
99
  exstruct input.xlsx --format toon # TOON (needs python-toon)
100
100
  exstruct input.xlsx --sheets-dir sheets/ # split per sheet in chosen format
101
- exstruct input.xlsx --print-areas-dir areas/ # split per print area (if any)
102
101
  exstruct input.xlsx --auto-page-breaks-dir auto_areas/ # COM only; option appears when available
102
+ exstruct input.xlsx --print-areas-dir areas/ # split per print area (if any)
103
103
  exstruct input.xlsx --mode light # cells + table candidates only
104
104
  exstruct input.xlsx --pdf --image # PDF and PNGs (Excel required)
105
105
  ```
@@ -147,9 +147,9 @@ engine = ExStructEngine(
147
147
  ),
148
148
  )
149
149
  wb2 = engine.extract("input.xlsx")
150
- engine.export(wb2, Path("out_filtered.json")) # drops shapes via filters
150
+ engine.export(wb2, Path("out_filtered.json"))
151
151
 
152
- # Enable hyperlinks in other modes
152
+ # Enable hyperlinks in standard mode
153
153
  engine_links = ExStructEngine(options=StructOptions(mode="standard", include_cell_links=True))
154
154
  with_links = engine_links.extract("input.xlsx")
155
155
 
@@ -188,8 +188,8 @@ Use higher thresholds to reduce false positives; lower them if true tables are m
188
188
  ## Output Modes
189
189
 
190
190
  - **light**: cells + table candidates (no COM needed).
191
- - **standard**: texted shapes + arrows, charts (COM if available), table candidates. Hyperlinks are off unless `include_cell_links=True`.
192
- - **verbose**: all shapes (with width/height), charts, table candidates, cell hyperlinks, and `colors_map`.
191
+ - **standard**: texted shapes + arrows, charts (COM if available), merged cell ranges, table candidates. Hyperlinks are off unless `include_cell_links=True`.
192
+ - **verbose**: all shapes (with width/height), charts, merged cell ranges, table candidates, cell hyperlinks, and `colors_map`.
193
193
 
194
194
  ## Error Handling / Fallbacks
195
195
 
@@ -207,7 +207,7 @@ exstruct input.xlsx --pdf --image --dpi 144
207
207
 
208
208
  Creates `<output>.pdf` and `<output>_images/` PNGs per sheet.
209
209
 
210
- ## Benchmark: Excel Structuring Demo
210
+ ## Example 1: Excel Structuring Demo
211
211
 
212
212
  To show how well exstruct can structure Excel, we parse a workbook that combines three elements on one sheet and share an AI reasoning benchmark that uses the JSON output.
213
213
 
@@ -216,7 +216,7 @@ To show how well exstruct can structure Excel, we parse a workbook that combines
216
216
  - Flowchart built only with shapes
217
217
 
218
218
  (Screenshot below is the actual sample Excel sheet)
219
- ![Sample Excel](/docs/assets/demo_sheet.png)
219
+ ![Sample Excel](docs/assets/demo_sheet.png)
220
220
  Sample workbook: `sample/sample.xlsx`
221
221
 
222
222
  ### 1. Input: Excel Sheet Overview
@@ -277,6 +277,7 @@ Below is a **shortened JSON output example** from parsing this Excel workbook.
277
277
  "text": "開始",
278
278
  "l": 148,
279
279
  "t": 220,
280
+ "kind": "shape",
280
281
  "type": "AutoShape-FlowchartProcess"
281
282
  },
282
283
  {
@@ -284,12 +285,13 @@ Below is a **shortened JSON output example** from parsing this Excel workbook.
284
285
  "text": "入力データ読み込み",
285
286
  "l": 132,
286
287
  "t": 282,
288
+ "kind": "shape",
287
289
  "type": "AutoShape-FlowchartProcess"
288
290
  },
289
291
  {
290
292
  "l": 193,
291
293
  "t": 246,
292
- "type": "AutoShape-Mixed",
294
+ "kind": "arrow",
293
295
  "begin_arrow_style": 1,
294
296
  "end_arrow_style": 2,
295
297
  "begin_id": 1,
@@ -389,6 +391,255 @@ flowchart TD
389
391
  ```
390
392
  ````
391
393
 
394
+
395
+ ## Example 2: General Application Form
396
+
397
+ ### Excel Sheet
398
+
399
+ ![General Application Form Excel](docs/assets/demo_form_en.png)
400
+
401
+ ### ExStruct JSON
402
+
403
+ (Truncated for brevity)
404
+
405
+ ```json
406
+ {
407
+ "book_name": "en_sf425.xlsx",
408
+ "sheets": {
409
+ "FFR": {
410
+ "rows": [
411
+ { "r": 1, "c": { "0": "FEDERAL FINANCIAL REPORT" } },
412
+ { "r": 3, "c": { "0": "(Follow form instructions)" } },
413
+ {
414
+ "r": 4,
415
+ "c": {
416
+ "0": "1. Federal Agency and Organizational Element",
417
+ "5": "2. Federal Grant or Other Identifying Number Assigned by Federal Agency",
418
+ "20": "Page",
419
+ "23": " of"
420
+ }
421
+ },
422
+ ...
423
+ ],
424
+ "shapes": [
425
+ {
426
+ "id": 1,
427
+ "text": "Not Required by EPA",
428
+ "l": 575,
429
+ "t": 396,
430
+ "kind": "shape",
431
+ "type": "AutoShape-Rectangle"
432
+ }
433
+ ],
434
+ "print_areas": [{ "r1": 1, "c1": 0, "r2": 66, "c2": 23 }],
435
+ "merged_cells": {
436
+ "schema": ["r1", "c1", "r2", "c2", "v"],
437
+ "items": [
438
+ [34, 15, 34, 23, " "],
439
+ [56, 10, 57, 17, "Federal Share Calculation"],
440
+ [18, 10, 18, 23, " "],
441
+ [15, 0, 15, 1, " "],
442
+ ...
443
+ ]
444
+ }
445
+ }
446
+ }
447
+ }
448
+
449
+ ```
450
+
451
+ ### Migration note (v0.3.5): merged_cells format change
452
+
453
+ `merged_cells` changed from a list of objects to a schema/items structure in v0.3.5 (breaking change for JSON consumers).
454
+
455
+ Old format (<= v0.3.2):
456
+
457
+ ```json
458
+ "merged_cells": [
459
+ { "r1": 34, "c1": 15, "r2": 34, "c2": 23, "v": " " },
460
+ { "r1": 56, "c1": 10, "r2": 57, "c2": 17, "v": "Federal Share Calculation" }
461
+ ]
462
+ ```
463
+
464
+ New format (v0.3.5+):
465
+
466
+ ```json
467
+ "merged_cells": {
468
+ "schema": ["r1", "c1", "r2", "c2", "v"],
469
+ "items": [
470
+ [34, 15, 34, 23, " "],
471
+ [56, 10, 57, 17, "Federal Share Calculation"]
472
+ ]
473
+ }
474
+ ```
475
+
476
+ Migration example (support both during transition):
477
+
478
+ ```python
479
+ def normalize_merged_cells(raw):
480
+ schema = ["r1", "c1", "r2", "c2", "v"]
481
+ if isinstance(raw, list):
482
+ items = [[d.get(k, " ") for k in schema] for d in raw]
483
+ return {"schema": schema, "items": items}
484
+ if isinstance(raw, dict) and "schema" in raw and "items" in raw:
485
+ return raw
486
+ return None
487
+ ```
488
+
489
+ ### LLM reconstruction example
490
+
491
+ ```md
492
+ <!-- This is a structured interpretation, not an official reproduction. -->
493
+
494
+ # **Federal Financial Report (FFR)**
495
+
496
+ _(Follow form instructions)_
497
+
498
+ ---
499
+
500
+ ## **1. Federal Agency and Organizational Element**
501
+
502
+ **United States Environmental Protection Agency**
503
+
504
+ ## **2. Federal Grant or Other Identifying Number Assigned by Federal Agency**
505
+
506
+ **Page 1 of pages**
507
+
508
+ ---
509
+
510
+ ## **3. Recipient Organization**
511
+
512
+ _(Name and complete address including Zip code)_
513
+
514
+ ---
515
+
516
+ ## **4. Recipient Identifiers**
517
+
518
+ - **4a. DUNS Number**
519
+ - **4b. EIN**
520
+ - **5. Recipient Account Number or Identifying Number**
521
+ _(To report multiple grants, use FFR Attachment)_
522
+ - **6. Report Type**
523
+ - □ Quarterly
524
+ - □ Semi-Annual
525
+ - □ Annual
526
+ - □ Final
527
+ - **7. Basis of Accounting**
528
+ - □ Cash
529
+ - □ Accrual
530
+
531
+ ---
532
+
533
+ ## **8. Project/Grant Period**
534
+
535
+ - **From:** (Month, Day, Year)
536
+ - **To:** (Month, Day, Year)
537
+
538
+ ## **9. Reporting Period End Date**
539
+
540
+ (Month, Day, Year)
541
+
542
+ ---
543
+
544
+ # **10. Transactions**
545
+
546
+ _(Use lines a–c for single or multiple grant reporting)_
547
+
548
+ ### **Federal Cash**
549
+
550
+ _(To report multiple grants, also use FFR Attachment)_
551
+
552
+ - **a. Cash Receipts**
553
+ - **b. Cash Disbursements**
554
+ - **c. Cash on Hand** (line a minus b)
555
+
556
+ _(Use lines d–o for single grant reporting)_
557
+
558
+ ### **Federal Expenditures and Unobligated Balance**
559
+
560
+ - **d. Total Federal funds authorized**
561
+ - **e. Federal share of expenditures**
562
+ - **f. Federal share of unliquidated obligations** — 0
563
+ - **g. Total Federal share** (sum of lines e and f) — 0
564
+ - **h. Unobligated balance of Federal funds** (line d minus g) — 0
565
+
566
+ ### **Recipient Share**
567
+
568
+ - **i. Total recipient share required**
569
+ - **j. Recipient share of expenditures**
570
+ - **k. Remaining recipient share to be provided** (line i minus j) — 0
571
+
572
+ ### **Program Income**
573
+
574
+ - **l. Total Federal program income earned**
575
+ - **m. Program income expended (deduction alternative)**
576
+ - **n. Program income expended (addition alternative)**
577
+ - **o. Unexpended program income** (line l minus line m or line n)
578
+
579
+ ---
580
+
581
+ # **11. Indirect Expense**
582
+
583
+ | Type | Rate | Period From | Period To | Base | Amount Charged | Federal Share |
584
+ | -------------- | ---- | ----------- | --------- | ---- | -------------- | ------------- |
585
+ | | | | | | | |
586
+ | **g. Totals:** | | | | 0 | 0 | 0 |
587
+
588
+ ---
589
+
590
+ # **12. Remarks**
591
+
592
+ Attach any explanations deemed necessary or information required by the Federal sponsoring agency in compliance with governing legislation.
593
+
594
+ ---
595
+
596
+ # **13. Certification**
597
+
598
+ By signing this report, I certify that it is true, complete, and accurate to the best of my knowledge.
599
+ I am aware that any false, fictitious, or fraudulent information may subject me to criminal, civil, or administrative penalties.
600
+ _(U.S. Code, Title 18, Section 1001)_
601
+
602
+ - **a. Typed or Printed Name and Title of Authorized Certifying Official**
603
+ - **b. Signature of Authorized Certifying Official**
604
+ - **c. Telephone** (Area code, number, extension)
605
+ - **d. Email address**
606
+ - **e. Date Report Submitted** (Month, Day, Year)
607
+
608
+ ---
609
+
610
+ # **14. Agency Use Only**
611
+
612
+ **Federal Share Calculation**
613
+
614
+ ---
615
+
616
+ ### **Standard Form 425**
617
+
618
+ **OMB Approval Number:** 0348-0061
619
+ **Expiration Date:** 02/28/2015
620
+
621
+ ---
622
+
623
+ # **Paperwork Burden Statement**
624
+
625
+ According to the Paperwork Reduction Act, as amended, no persons are required to respond to a collection of information unless it displays a valid OMB Control Number.
626
+ The valid OMB control number for this information collection is **0348-0061**.
627
+
628
+ Public reporting burden for this collection of information is estimated to average **1.5 hours per response**, including time for reviewing instructions, searching existing data sources, gathering and maintaining the data needed, and completing and reviewing the collection of information.
629
+
630
+ Send comments regarding the burden estimate or any other aspect of this collection of information, including suggestions for reducing this burden, to:
631
+
632
+ **Office of Management and Budget**
633
+ Paperwork Reduction Project (0348-0060)
634
+ Washington, DC 20503
635
+
636
+ ---
637
+
638
+ ### **Shape in Original Document**
639
+
640
+ - _Not Required by EPA_
641
+ ```
642
+
392
643
  From this we can see:
393
644
 
394
645
  **exstruct's JSON is already in a format that AI can read and reason over directly.**
@@ -398,6 +649,7 @@ Other LLM inference samples using this library can be found in the following dir
398
649
  - [Basic Excel](sample/basic/)
399
650
  - [Flowchart](sample/flowchart/)
400
651
  - [Gantt Chart](sample/gantt_chart/)
652
+ - [Application forms with many merged cells](sample/forms_with_many_merged_cells/)
401
653
 
402
654
  ### 4. Summary
403
655
 
@@ -435,6 +687,11 @@ This project is suitable for teams that:
435
687
  - Use CLI `--auto-page-breaks-dir` (COM only), `DestinationOptions.auto_page_breaks_dir` (preferred), or `export_auto_page_breaks(...)` to write per-auto-page-break files; the API raises `ValueError` if no auto page breaks exist.
436
688
  - `PrintAreaView` includes rows and table candidates inside the area, plus shapes/charts that overlap the area (size-less shapes are treated as points). `normalize=True` rebases row/col indices to the area origin.
437
689
 
690
+ ## Documentation build
691
+
692
+ - Update generated model docs before building the site: `python scripts/gen_model_docs.py`.
693
+ - Build locally with mkdocs + mkdocstrings (dev deps required): `uv run mkdocs serve` or `uv run mkdocs build`.
694
+
438
695
  ## Architecture
439
696
 
440
697
  ExStruct uses a pipeline-based architecture that separates