kalamos 0.1.0__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 (42) hide show
  1. kalamos-0.1.0/.gitignore +7 -0
  2. kalamos-0.1.0/CHANGELOG.md +11 -0
  3. kalamos-0.1.0/CONTRIBUTING.md +18 -0
  4. kalamos-0.1.0/LICENSE +22 -0
  5. kalamos-0.1.0/LICENSES/Apache-2.0.txt +202 -0
  6. kalamos-0.1.0/LICENSES/MIT-pdfmux.txt +21 -0
  7. kalamos-0.1.0/NOTICE +37 -0
  8. kalamos-0.1.0/PKG-INFO +148 -0
  9. kalamos-0.1.0/README.md +111 -0
  10. kalamos-0.1.0/SECURITY.md +5 -0
  11. kalamos-0.1.0/assets/logo.svg +1 -0
  12. kalamos-0.1.0/pyproject.toml +67 -0
  13. kalamos-0.1.0/src/kalamos/__init__.py +12 -0
  14. kalamos-0.1.0/src/kalamos/__main__.py +3 -0
  15. kalamos-0.1.0/src/kalamos/backends/__init__.py +15 -0
  16. kalamos-0.1.0/src/kalamos/backends/base.py +39 -0
  17. kalamos-0.1.0/src/kalamos/backends/docling.py +43 -0
  18. kalamos-0.1.0/src/kalamos/backends/external.py +49 -0
  19. kalamos-0.1.0/src/kalamos/backends/marker.py +54 -0
  20. kalamos-0.1.0/src/kalamos/backends/mineru.py +46 -0
  21. kalamos-0.1.0/src/kalamos/backends/textlayer.py +24 -0
  22. kalamos-0.1.0/src/kalamos/checks.py +224 -0
  23. kalamos-0.1.0/src/kalamos/cli.py +141 -0
  24. kalamos-0.1.0/src/kalamos/garble.py +81 -0
  25. kalamos-0.1.0/src/kalamos/ocr.py +55 -0
  26. kalamos-0.1.0/src/kalamos/pipeline.py +263 -0
  27. kalamos-0.1.0/src/kalamos/postprocess.py +21 -0
  28. kalamos-0.1.0/src/kalamos/recover.py +68 -0
  29. kalamos-0.1.0/src/kalamos/reference.py +379 -0
  30. kalamos-0.1.0/src/kalamos/text.py +103 -0
  31. kalamos-0.1.0/tests/conftest.py +213 -0
  32. kalamos-0.1.0/tests/test_adversarial.py +205 -0
  33. kalamos-0.1.0/tests/test_cli.py +54 -0
  34. kalamos-0.1.0/tests/test_edges.py +124 -0
  35. kalamos-0.1.0/tests/test_engines.py +42 -0
  36. kalamos-0.1.0/tests/test_furniture.py +77 -0
  37. kalamos-0.1.0/tests/test_garbled.py +107 -0
  38. kalamos-0.1.0/tests/test_math_coverage.py +38 -0
  39. kalamos-0.1.0/tests/test_numbers.py +71 -0
  40. kalamos-0.1.0/tests/test_pipeline.py +195 -0
  41. kalamos-0.1.0/tests/test_scanned.py +185 -0
  42. kalamos-0.1.0/tests/test_units.py +109 -0
@@ -0,0 +1,7 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.egg-info/
4
+ .pytest_cache/
5
+ dist/
6
+ build/
7
+ .env
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ First release.
6
+
7
+ - Converts a PDF to markdown with MinerU, marker or docling, tried in that order, and checks every page against the text layer of the PDF.
8
+ - Checks coverage, precision, reading order, run-together words and numbers, and reports the status of each page in a JSON report.
9
+ - Restores lines that an engine dropped from the text layer, and never restores a changed number.
10
+ - Checks scanned pages against an embedded OCR layer or an independent Tesseract reading.
11
+ - Provides the `kalamos convert`, `kalamos check` and `kalamos backends` commands.
@@ -0,0 +1,18 @@
1
+ # Contributing
2
+
3
+ The `main` branch is protected. Every change reaches it through a pull request, and the `ci-passed` check must succeed before the merge.
4
+
5
+ ```
6
+ pip install -e ".[dev,docling]"
7
+ ruff check src tests
8
+ pytest
9
+ pytest -m engines
10
+ ```
11
+
12
+ The tests under `-m engines` run each installed engine on generated PDFs and skip any engine that is not installed.
13
+
14
+ ## Release
15
+
16
+ 1. Set `__version__` in `src/kalamos/__init__.py` and add an entry to `CHANGELOG.md`, through a pull request.
17
+ 2. After the merge, tag a release candidate such as `v0.2.0rc1` (with the matching `__version__`) to publish to TestPyPI.
18
+ 3. Tag `v0.2.0` to publish to PyPI. The release workflow refuses a tag that differs from `__version__`.
kalamos-0.1.0/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 nashid
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nameet Potnis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
kalamos-0.1.0/NOTICE ADDED
@@ -0,0 +1,37 @@
1
+ kalamos
2
+ Copyright (c) 2026 nashid. Licensed under the MIT License (see LICENSE).
3
+
4
+ kalamos builds on three document conversion projects. It runs them as optional
5
+ backends and does not bundle their code or model weights; whoever installs a
6
+ backend accepts its licence.
7
+
8
+ docling https://github.com/docling-project/docling MIT License
9
+ marker https://github.com/datalab-to/marker Apache License 2.0 (code);
10
+ model weights under a modified
11
+ AI Pubs OpenRAIL-M licence
12
+ MinerU https://github.com/opendatalab/MinerU Apache License 2.0 with
13
+ additional terms
14
+
15
+ Adapted code
16
+ ------------
17
+ src/kalamos/garble.py is adapted from score_text_garble in marker
18
+ (marker/builders/line.py, commit c4423cee5e8c94f804845dff6669d90dc302de36),
19
+ Copyright Datalab, licensed under the Apache License, Version 2.0
20
+ (http://www.apache.org/licenses/LICENSE-2.0). The file states the changes made.
21
+ The license text is in LICENSES/Apache-2.0.txt.
22
+
23
+ The numeric literal pattern and its normalization in src/kalamos/checks.py are
24
+ adapted from verifier.py in pdfmux (https://github.com/NameetP/pdfmux, commit
25
+ ff8c406), Copyright (c) 2026 Nameet Potnis, licensed under the MIT License.
26
+ kalamos fails a page on any lost or changed value, reads numbers inside LaTeX,
27
+ and leaves years out. No other pdfmux code is used. The copyright and permission
28
+ notice of pdfmux are in LICENSES/MIT-pdfmux.txt.
29
+
30
+ The reading-order heuristics in src/kalamos/reference.py follow the recursive
31
+ XY-cut approach also used by docling and marker; no code was copied.
32
+
33
+ Using MinerU through kalamos
34
+ ----------------------------
35
+ MinerU's additional terms require an online service built on MinerU to state
36
+ that MinerU is used. kalamos records the backend that produced each page in its
37
+ report, so that such a service can comply.
kalamos-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,148 @@
1
+ Metadata-Version: 2.5
2
+ Name: kalamos
3
+ Version: 0.1.0
4
+ Summary: PDF to markdown that checks its own work: proven layout engines, verified page by page against the PDF text layer.
5
+ Project-URL: Homepage, https://github.com/nashid/kalamos
6
+ Project-URL: Repository, https://github.com/nashid/kalamos
7
+ Project-URL: Issues, https://github.com/nashid/kalamos/issues
8
+ Project-URL: Changelog, https://github.com/nashid/kalamos/blob/main/CHANGELOG.md
9
+ Author: nashid
10
+ License-Expression: MIT AND Apache-2.0
11
+ License-File: LICENSE
12
+ License-File: LICENSES/Apache-2.0.txt
13
+ License-File: LICENSES/MIT-pdfmux.txt
14
+ License-File: NOTICE
15
+ Keywords: docling,document-conversion,markdown,marker,mineru,pdf,scientific-papers
16
+ Classifier: Development Status :: 3 - Alpha
17
+ Classifier: Environment :: Console
18
+ Classifier: Intended Audience :: Science/Research
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Programming Language :: Python :: 3
21
+ Classifier: Programming Language :: Python :: 3 :: Only
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Programming Language :: Python :: 3.13
26
+ Classifier: Topic :: Scientific/Engineering
27
+ Classifier: Topic :: Text Processing :: Markup :: Markdown
28
+ Requires-Python: >=3.10
29
+ Requires-Dist: pypdfium2>=4.30
30
+ Provides-Extra: dev
31
+ Requires-Dist: fpdf2>=2.7; extra == 'dev'
32
+ Requires-Dist: pytest>=8; extra == 'dev'
33
+ Requires-Dist: ruff>=0.8; extra == 'dev'
34
+ Provides-Extra: docling
35
+ Requires-Dist: docling>=2.50; extra == 'docling'
36
+ Description-Content-Type: text/markdown
37
+
38
+ <p align="center"><img src="https://raw.githubusercontent.com/nashid/kalamos/main/assets/logo.svg" alt="kalamos" width="160"></p>
39
+
40
+ # kalamos
41
+
42
+ kalamos converts PDF files to markdown and checks every page of the result against the PDF itself. It runs established layout engines (MinerU, marker and docling), scores each page that an engine produces, and keeps the first page that passes. A page that no engine converts faithfully is reported as failed and is never passed off as correct.
43
+
44
+ kalamos uses no language model and sends no data to any remote service.
45
+
46
+ Status: alpha.
47
+
48
+ ## Why
49
+
50
+ Layout engines lose text without warning. A dropped table row, a figure label that disappears, or a number whose digits change all leave markdown that looks complete. kalamos compares each converted page with what the PDF holds and states, page by page, whether the conversion can be trusted.
51
+
52
+ ## Installation
53
+
54
+ kalamos needs Python 3.10 or later.
55
+
56
+ ```
57
+ pip install kalamos
58
+ ```
59
+
60
+ kalamos tries MinerU first, then marker, then docling. MinerU and marker run as separate command-line tools, and docling runs inside the kalamos process. Install the engines you want:
61
+
62
+ ```
63
+ uv tool install "mineru[core]"
64
+ uv tool install marker-pdf
65
+ pip install "kalamos[docling]"
66
+ ```
67
+
68
+ kalamos finds `mineru-kit` and `marker_single` on the `PATH`, or at the paths given in `KALAMOS_MINERU` and `KALAMOS_MARKER`. An engine that is not installed is skipped. Tesseract is optional and is used only to cross-check scanned pages. Check what is available with:
69
+
70
+ ```
71
+ kalamos backends
72
+ ```
73
+
74
+ ## Usage
75
+
76
+ ```
77
+ kalamos convert paper.pdf -o paper.md --report paper.json
78
+ ```
79
+
80
+ | Option | Effect |
81
+ | --- | --- |
82
+ | `-b, --backends` | Engines in order of preference, default `mineru,marker,docling` |
83
+ | `-p, --pages` | 1-based pages, as in `1-3,7` |
84
+ | `--report` | Write the per-page JSON report |
85
+ | `--no-recover` | Do not restore text that an engine dropped |
86
+ | `--strict` | Exit with code 2 if any page fails its checks |
87
+ | `--min-coverage`, `--min-order`, `--max-run-together` | Change the thresholds of the checks |
88
+
89
+ To score markdown produced by another tool against its PDF:
90
+
91
+ ```
92
+ kalamos check paper.pdf paper.md
93
+ ```
94
+
95
+ ## Checks
96
+
97
+ Each page is compared with a reference built from the text layer of the PDF, after lines that the text layer itself has garbled are removed.
98
+
99
+ | Check | Fails a page when |
100
+ | --- | --- |
101
+ | Coverage | Too few words of the reference appear in the output (default 0.85) |
102
+ | Precision | Too many words of the output are absent from the reference (default 0.85) |
103
+ | Reading order | Words appear in the wrong order (default 0.80) |
104
+ | Run-together words | Words are glued together (default at most 0.02) |
105
+ | Numbers | A number of the text layer is lost or changed |
106
+
107
+ When an engine drops text but its other output is sound, kalamos restores the missing lines from the text layer and marks the page as recovered. A changed number is never recovered.
108
+
109
+ A page with almost no text layer is a scan. kalamos renders it and compares the output with an independent Tesseract reading. The Tesseract text is used only for the comparison and is never copied into the output. A scan that carries an invisible OCR layer is checked against that layer, and the engine that reads the same layer is not allowed to confirm itself.
110
+
111
+ ## Page status
112
+
113
+ | Status | Meaning |
114
+ | --- | --- |
115
+ | `passed` | An engine passed every check against the text layer |
116
+ | `recovered` | Text dropped by the engine was restored from the text layer |
117
+ | `cross-checked` | A scanned page agreed with an independent OCR reading |
118
+ | `unverifiable` | No independent reference exists for the page, for example a scan without Tesseract installed |
119
+ | `failed` | No engine produced a faithful page |
120
+
121
+ The JSON report lists, for each page, the status, the chosen engine, the scores of every attempt, the reference used and any notes.
122
+
123
+ ## Privacy
124
+
125
+ MinerU runs locally with its telemetry disabled, and kalamos never uses the remote parsing service of MinerU. No backend receives an API key from kalamos.
126
+
127
+ ## Development
128
+
129
+ ```
130
+ pip install -e ".[dev,docling]"
131
+ pytest
132
+ ```
133
+
134
+ Tests generate their own PDFs, so no third-party document is stored in the repository.
135
+
136
+ ## License
137
+
138
+ kalamos is released under the MIT License. `src/kalamos/garble.py` is adapted from marker under the Apache License 2.0, and the number pattern in `src/kalamos/checks.py` is adapted from pdfmux under the MIT License. `NOTICE` records the changes, and `LICENSES` holds both license texts.
139
+
140
+ kalamos does not bundle or download any engine, model or weight. Each engine carries its own license, which applies to whoever installs it:
141
+
142
+ | Engine | License |
143
+ | --- | --- |
144
+ | [MinerU](https://github.com/opendatalab/MinerU) | Apache 2.0 with additional terms. An organization above 100 million monthly active users or USD 20 million monthly revenue needs a commercial license, and an online service built on MinerU must state that it uses MinerU. |
145
+ | [marker](https://github.com/datalab-to/marker) | Code under Apache 2.0. Model weights under a modified AI Pubs OpenRAIL-M license, free for research, personal use and startups under USD 5 million in funding or revenue. Other commercial use needs a license from Datalab. |
146
+ | [docling](https://github.com/docling-project/docling) | MIT |
147
+
148
+ The JSON report names the engine that produced each page, so a service built on kalamos can state which engines it used.
@@ -0,0 +1,111 @@
1
+ <p align="center"><img src="https://raw.githubusercontent.com/nashid/kalamos/main/assets/logo.svg" alt="kalamos" width="160"></p>
2
+
3
+ # kalamos
4
+
5
+ kalamos converts PDF files to markdown and checks every page of the result against the PDF itself. It runs established layout engines (MinerU, marker and docling), scores each page that an engine produces, and keeps the first page that passes. A page that no engine converts faithfully is reported as failed and is never passed off as correct.
6
+
7
+ kalamos uses no language model and sends no data to any remote service.
8
+
9
+ Status: alpha.
10
+
11
+ ## Why
12
+
13
+ Layout engines lose text without warning. A dropped table row, a figure label that disappears, or a number whose digits change all leave markdown that looks complete. kalamos compares each converted page with what the PDF holds and states, page by page, whether the conversion can be trusted.
14
+
15
+ ## Installation
16
+
17
+ kalamos needs Python 3.10 or later.
18
+
19
+ ```
20
+ pip install kalamos
21
+ ```
22
+
23
+ kalamos tries MinerU first, then marker, then docling. MinerU and marker run as separate command-line tools, and docling runs inside the kalamos process. Install the engines you want:
24
+
25
+ ```
26
+ uv tool install "mineru[core]"
27
+ uv tool install marker-pdf
28
+ pip install "kalamos[docling]"
29
+ ```
30
+
31
+ kalamos finds `mineru-kit` and `marker_single` on the `PATH`, or at the paths given in `KALAMOS_MINERU` and `KALAMOS_MARKER`. An engine that is not installed is skipped. Tesseract is optional and is used only to cross-check scanned pages. Check what is available with:
32
+
33
+ ```
34
+ kalamos backends
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ```
40
+ kalamos convert paper.pdf -o paper.md --report paper.json
41
+ ```
42
+
43
+ | Option | Effect |
44
+ | --- | --- |
45
+ | `-b, --backends` | Engines in order of preference, default `mineru,marker,docling` |
46
+ | `-p, --pages` | 1-based pages, as in `1-3,7` |
47
+ | `--report` | Write the per-page JSON report |
48
+ | `--no-recover` | Do not restore text that an engine dropped |
49
+ | `--strict` | Exit with code 2 if any page fails its checks |
50
+ | `--min-coverage`, `--min-order`, `--max-run-together` | Change the thresholds of the checks |
51
+
52
+ To score markdown produced by another tool against its PDF:
53
+
54
+ ```
55
+ kalamos check paper.pdf paper.md
56
+ ```
57
+
58
+ ## Checks
59
+
60
+ Each page is compared with a reference built from the text layer of the PDF, after lines that the text layer itself has garbled are removed.
61
+
62
+ | Check | Fails a page when |
63
+ | --- | --- |
64
+ | Coverage | Too few words of the reference appear in the output (default 0.85) |
65
+ | Precision | Too many words of the output are absent from the reference (default 0.85) |
66
+ | Reading order | Words appear in the wrong order (default 0.80) |
67
+ | Run-together words | Words are glued together (default at most 0.02) |
68
+ | Numbers | A number of the text layer is lost or changed |
69
+
70
+ When an engine drops text but its other output is sound, kalamos restores the missing lines from the text layer and marks the page as recovered. A changed number is never recovered.
71
+
72
+ A page with almost no text layer is a scan. kalamos renders it and compares the output with an independent Tesseract reading. The Tesseract text is used only for the comparison and is never copied into the output. A scan that carries an invisible OCR layer is checked against that layer, and the engine that reads the same layer is not allowed to confirm itself.
73
+
74
+ ## Page status
75
+
76
+ | Status | Meaning |
77
+ | --- | --- |
78
+ | `passed` | An engine passed every check against the text layer |
79
+ | `recovered` | Text dropped by the engine was restored from the text layer |
80
+ | `cross-checked` | A scanned page agreed with an independent OCR reading |
81
+ | `unverifiable` | No independent reference exists for the page, for example a scan without Tesseract installed |
82
+ | `failed` | No engine produced a faithful page |
83
+
84
+ The JSON report lists, for each page, the status, the chosen engine, the scores of every attempt, the reference used and any notes.
85
+
86
+ ## Privacy
87
+
88
+ MinerU runs locally with its telemetry disabled, and kalamos never uses the remote parsing service of MinerU. No backend receives an API key from kalamos.
89
+
90
+ ## Development
91
+
92
+ ```
93
+ pip install -e ".[dev,docling]"
94
+ pytest
95
+ ```
96
+
97
+ Tests generate their own PDFs, so no third-party document is stored in the repository.
98
+
99
+ ## License
100
+
101
+ kalamos is released under the MIT License. `src/kalamos/garble.py` is adapted from marker under the Apache License 2.0, and the number pattern in `src/kalamos/checks.py` is adapted from pdfmux under the MIT License. `NOTICE` records the changes, and `LICENSES` holds both license texts.
102
+
103
+ kalamos does not bundle or download any engine, model or weight. Each engine carries its own license, which applies to whoever installs it:
104
+
105
+ | Engine | License |
106
+ | --- | --- |
107
+ | [MinerU](https://github.com/opendatalab/MinerU) | Apache 2.0 with additional terms. An organization above 100 million monthly active users or USD 20 million monthly revenue needs a commercial license, and an online service built on MinerU must state that it uses MinerU. |
108
+ | [marker](https://github.com/datalab-to/marker) | Code under Apache 2.0. Model weights under a modified AI Pubs OpenRAIL-M license, free for research, personal use and startups under USD 5 million in funding or revenue. Other commercial use needs a license from Datalab. |
109
+ | [docling](https://github.com/docling-project/docling) | MIT |
110
+
111
+ The JSON report names the engine that produced each page, so a service built on kalamos can state which engines it used.
@@ -0,0 +1,5 @@
1
+ # Security
2
+
3
+ Report a vulnerability through a private security advisory at https://github.com/nashid/kalamos/security/advisories/new rather than a public issue.
4
+
5
+ kalamos parses PDF files with pypdfium2 and passes them to the installed engines. Treat a PDF from an untrusted source with the same care as for those tools.
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" role="img" aria-label="kalamos"><title>kalamos</title><circle cx="100" cy="100" r="98" fill="#C65D3B"/><circle cx="100" cy="100" r="80" fill="none" stroke="#1C1917" stroke-width="2.8"/><circle cx="100" cy="100" r="94" fill="none" stroke="#1C1917" stroke-width="2.8"/><polyline points="100.00,20.00 100.00,8.80 128.18,13.26 125.80,20.59 111.44,17.29 112.02,13.13 120.47,14.72" fill="none" stroke="#1C1917" stroke-width="2.8"/><polyline points="130.61,26.09 134.90,15.74 159.23,30.65 154.23,36.51 142.22,27.96 144.35,24.34 151.55,29.05" fill="none" stroke="#1C1917" stroke-width="2.8"/><polyline points="156.57,43.43 164.49,35.51 181.26,58.60 174.40,62.09 166.58,49.60 169.93,47.07 174.78,54.18" fill="none" stroke="#1C1917" stroke-width="2.8"/><polyline points="173.91,69.39 184.26,65.10 190.92,92.84 183.24,93.45 180.79,78.92 184.86,77.86 186.62,86.28" fill="none" stroke="#1C1917" stroke-width="2.8"/><polyline points="180.00,100.00 191.20,100.00 186.74,128.18 179.41,125.80 182.71,111.44 186.87,112.02 185.28,120.47" fill="none" stroke="#1C1917" stroke-width="2.8"/><polyline points="173.91,130.61 184.26,134.90 169.35,159.23 163.49,154.23 172.04,142.22 175.66,144.35 170.95,151.55" fill="none" stroke="#1C1917" stroke-width="2.8"/><polyline points="156.57,156.57 164.49,164.49 141.40,181.26 137.91,174.40 150.40,166.58 152.93,169.93 145.82,174.78" fill="none" stroke="#1C1917" stroke-width="2.8"/><polyline points="130.61,173.91 134.90,184.26 107.16,190.92 106.55,183.24 121.08,180.79 122.14,184.86 113.72,186.62" fill="none" stroke="#1C1917" stroke-width="2.8"/><polyline points="100.00,180.00 100.00,191.20 71.82,186.74 74.20,179.41 88.56,182.71 87.98,186.87 79.53,185.28" fill="none" stroke="#1C1917" stroke-width="2.8"/><polyline points="69.39,173.91 65.10,184.26 40.77,169.35 45.77,163.49 57.78,172.04 55.65,175.66 48.45,170.95" fill="none" stroke="#1C1917" stroke-width="2.8"/><polyline points="43.43,156.57 35.51,164.49 18.74,141.40 25.60,137.91 33.42,150.40 30.07,152.93 25.22,145.82" fill="none" stroke="#1C1917" stroke-width="2.8"/><polyline points="26.09,130.61 15.74,134.90 9.08,107.16 16.76,106.55 19.21,121.08 15.14,122.14 13.38,113.72" fill="none" stroke="#1C1917" stroke-width="2.8"/><polyline points="20.00,100.00 8.80,100.00 13.26,71.82 20.59,74.20 17.29,88.56 13.13,87.98 14.72,79.53" fill="none" stroke="#1C1917" stroke-width="2.8"/><polyline points="26.09,69.39 15.74,65.10 30.65,40.77 36.51,45.77 27.96,57.78 24.34,55.65 29.05,48.45" fill="none" stroke="#1C1917" stroke-width="2.8"/><polyline points="43.43,43.43 35.51,35.51 58.60,18.74 62.09,25.60 49.60,33.42 47.07,30.07 54.18,25.22" fill="none" stroke="#1C1917" stroke-width="2.8"/><polyline points="69.39,26.09 65.10,15.74 92.84,9.08 93.45,16.76 78.92,19.21 77.86,15.14 86.28,13.38" fill="none" stroke="#1C1917" stroke-width="2.8"/><circle cx="100" cy="100" r="77" fill="#1C1917"/><path d="M95 160 C42 152 30 94 58 44" fill="none" stroke="#C65D3B" stroke-width="4.5" stroke-linecap="round"/><g transform="translate(80.3 156.2) rotate(-188.8)"><path d="M0 0 Q9.6 -7.5 24.0 0 Q9.6 7.5 0 0 Z" fill="#C65D3B"/><line x1="2" y1="0" x2="19.2" y2="0" stroke="#1C1917" stroke-width="1.1"/></g><g transform="translate(66.0 148.1) rotate(-112.2)"><path d="M0 0 Q9.1 -7.5 22.7 0 Q9.1 7.5 0 0 Z" fill="#C65D3B"/><line x1="2" y1="0" x2="18.2" y2="0" stroke="#1C1917" stroke-width="1.1"/></g><g transform="translate(55.1 136.8) rotate(-155.6)"><path d="M0 0 Q8.6 -7.5 21.4 0 Q8.6 7.5 0 0 Z" fill="#C65D3B"/><line x1="2" y1="0" x2="17.1" y2="0" stroke="#1C1917" stroke-width="1.1"/></g><g transform="translate(47.8 122.9) rotate(-80.4)"><path d="M0 0 Q8.0 -7.5 20.1 0 Q8.0 7.5 0 0 Z" fill="#C65D3B"/><line x1="2" y1="0" x2="16.1" y2="0" stroke="#1C1917" stroke-width="1.1"/></g><g transform="translate(44.0 106.9) rotate(-127.1)"><path d="M0 0 Q7.5 -7.5 18.8 0 Q7.5 7.5 0 0 Z" fill="#C65D3B"/><line x1="2" y1="0" x2="15.0" y2="0" stroke="#1C1917" stroke-width="1.1"/></g><g transform="translate(43.6 89.6) rotate(-55.5)"><path d="M0 0 Q7.0 -7.5 17.5 0 Q7.0 7.5 0 0 Z" fill="#C65D3B"/><line x1="2" y1="0" x2="14.0" y2="0" stroke="#1C1917" stroke-width="1.1"/></g><g transform="translate(46.8 71.4) rotate(-105.1)"><path d="M0 0 Q6.5 -7.5 16.2 0 Q6.5 7.5 0 0 Z" fill="#C65D3B"/><line x1="2" y1="0" x2="13.0" y2="0" stroke="#1C1917" stroke-width="1.1"/></g><g transform="translate(53.4 53.1) rotate(-35.4)"><path d="M0 0 Q6.0 -7.5 14.9 0 Q6.0 7.5 0 0 Z" fill="#C65D3B"/><line x1="2" y1="0" x2="11.9" y2="0" stroke="#1C1917" stroke-width="1.1"/></g><g transform="translate(58.0 44.0) rotate(-60.8)"><path d="M0 0 Q6.4 -5.0 16.0 0 Q6.4 5.0 0 0 Z" fill="#C65D3B"/><line x1="2" y1="0" x2="12.8" y2="0" stroke="#1C1917" stroke-width="1.1"/></g><line x1="57.2" y1="145.6" x2="63.0" y2="140.0" stroke="#1C1917" stroke-width="2"/><line x1="41.5" y1="116.0" x2="49.3" y2="114.2" stroke="#1C1917" stroke-width="2"/><line x1="40.8" y1="79.9" x2="48.7" y2="81.3" stroke="#1C1917" stroke-width="2"/><path d="M105 160 C158 152 170 94 142 44" fill="none" stroke="#C65D3B" stroke-width="4.5" stroke-linecap="round"/><g transform="translate(119.7 156.2) rotate(8.8)"><path d="M0 0 Q9.6 -7.5 24.0 0 Q9.6 7.5 0 0 Z" fill="#C65D3B"/><line x1="2" y1="0" x2="19.2" y2="0" stroke="#1C1917" stroke-width="1.1"/></g><g transform="translate(134.0 148.1) rotate(-67.8)"><path d="M0 0 Q9.1 -7.5 22.7 0 Q9.1 7.5 0 0 Z" fill="#C65D3B"/><line x1="2" y1="0" x2="18.2" y2="0" stroke="#1C1917" stroke-width="1.1"/></g><g transform="translate(144.9 136.8) rotate(-24.4)"><path d="M0 0 Q8.6 -7.5 21.4 0 Q8.6 7.5 0 0 Z" fill="#C65D3B"/><line x1="2" y1="0" x2="17.1" y2="0" stroke="#1C1917" stroke-width="1.1"/></g><g transform="translate(152.2 122.9) rotate(-99.6)"><path d="M0 0 Q8.0 -7.5 20.1 0 Q8.0 7.5 0 0 Z" fill="#C65D3B"/><line x1="2" y1="0" x2="16.1" y2="0" stroke="#1C1917" stroke-width="1.1"/></g><g transform="translate(156.0 106.9) rotate(-52.9)"><path d="M0 0 Q7.5 -7.5 18.8 0 Q7.5 7.5 0 0 Z" fill="#C65D3B"/><line x1="2" y1="0" x2="15.0" y2="0" stroke="#1C1917" stroke-width="1.1"/></g><g transform="translate(156.4 89.6) rotate(-124.5)"><path d="M0 0 Q7.0 -7.5 17.5 0 Q7.0 7.5 0 0 Z" fill="#C65D3B"/><line x1="2" y1="0" x2="14.0" y2="0" stroke="#1C1917" stroke-width="1.1"/></g><g transform="translate(153.2 71.4) rotate(-74.9)"><path d="M0 0 Q6.5 -7.5 16.2 0 Q6.5 7.5 0 0 Z" fill="#C65D3B"/><line x1="2" y1="0" x2="13.0" y2="0" stroke="#1C1917" stroke-width="1.1"/></g><g transform="translate(146.6 53.1) rotate(-144.6)"><path d="M0 0 Q6.0 -7.5 14.9 0 Q6.0 7.5 0 0 Z" fill="#C65D3B"/><line x1="2" y1="0" x2="11.9" y2="0" stroke="#1C1917" stroke-width="1.1"/></g><g transform="translate(142.0 44.0) rotate(-119.2)"><path d="M0 0 Q6.4 -5.0 16.0 0 Q6.4 5.0 0 0 Z" fill="#C65D3B"/><line x1="2" y1="0" x2="12.8" y2="0" stroke="#1C1917" stroke-width="1.1"/></g><line x1="137.0" y1="140.0" x2="142.8" y2="145.6" stroke="#1C1917" stroke-width="2"/><line x1="150.7" y1="114.2" x2="158.5" y2="116.0" stroke="#1C1917" stroke-width="2"/><line x1="151.3" y1="81.3" x2="159.2" y2="79.9" stroke="#1C1917" stroke-width="2"/><path d="M88 156 Q100 165 112 156 L115 166 Q100 173 85 166 Z" fill="#F3E9D2"/><path d="M91 166 L84 177 L93 173 Z M109 166 L116 177 L107 173 Z" fill="#F3E9D2"/><path d="M100 142 L79 110.6 Q73 95.6 83 83.6 L88.45 62 L111.55 62 L117 83.6 Q127 95.6 121 110.6 Z" fill="#F3E9D2"/><rect x="88.45" y="62" width="23.1" height="5" fill="#1C1917" opacity="0.35"/><circle cx="100" cy="93.6" r="3.6" fill="#1C1917"/><line x1="100" y1="93.6" x2="100" y2="138" stroke="#1C1917" stroke-width="2.4" stroke-linecap="round"/></svg>