knovas-extract 0.1.1__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.
- knovas_extract-0.1.1/.gitignore +55 -0
- knovas_extract-0.1.1/CHANGELOG.md +90 -0
- knovas_extract-0.1.1/LICENSE +201 -0
- knovas_extract-0.1.1/NOTICE +54 -0
- knovas_extract-0.1.1/PKG-INFO +188 -0
- knovas_extract-0.1.1/README.md +134 -0
- knovas_extract-0.1.1/RELEASING.md +89 -0
- knovas_extract-0.1.1/SECURITY.md +89 -0
- knovas_extract-0.1.1/docs/sandboxing.md +126 -0
- knovas_extract-0.1.1/pyproject.toml +305 -0
- knovas_extract-0.1.1/src/knovas_extract/__init__.py +64 -0
- knovas_extract-0.1.1/src/knovas_extract/_version.py +11 -0
- knovas_extract-0.1.1/src/knovas_extract/cli.py +52 -0
- knovas_extract-0.1.1/src/knovas_extract/dispatch.py +266 -0
- knovas_extract-0.1.1/src/knovas_extract/errors.py +66 -0
- knovas_extract-0.1.1/src/knovas_extract/extractors/__init__.py +2 -0
- knovas_extract-0.1.1/src/knovas_extract/extractors/docx.py +265 -0
- knovas_extract-0.1.1/src/knovas_extract/extractors/eml.py +210 -0
- knovas_extract-0.1.1/src/knovas_extract/extractors/html.py +208 -0
- knovas_extract-0.1.1/src/knovas_extract/extractors/md.py +145 -0
- knovas_extract-0.1.1/src/knovas_extract/extractors/msg.py +177 -0
- knovas_extract-0.1.1/src/knovas_extract/extractors/pdf.py +211 -0
- knovas_extract-0.1.1/src/knovas_extract/extractors/rtf.py +90 -0
- knovas_extract-0.1.1/src/knovas_extract/extractors/txt.py +98 -0
- knovas_extract-0.1.1/src/knovas_extract/interfaces.py +39 -0
- knovas_extract-0.1.1/src/knovas_extract/normalize.py +39 -0
- knovas_extract-0.1.1/src/knovas_extract/result.py +120 -0
- knovas_extract-0.1.1/tests/__init__.py +0 -0
- knovas_extract-0.1.1/tests/conftest.py +52 -0
- knovas_extract-0.1.1/tests/fuzz/__init__.py +0 -0
- knovas_extract-0.1.1/tests/fuzz/fuzz_docx.py +45 -0
- knovas_extract-0.1.1/tests/fuzz/fuzz_eml.py +32 -0
- knovas_extract-0.1.1/tests/fuzz/fuzz_html.py +32 -0
- knovas_extract-0.1.1/tests/fuzz/fuzz_md.py +38 -0
- knovas_extract-0.1.1/tests/fuzz/fuzz_pdf.py +44 -0
- knovas_extract-0.1.1/tests/fuzz/fuzz_rtf.py +32 -0
- knovas_extract-0.1.1/tests/fuzz/fuzz_txt.py +41 -0
- knovas_extract-0.1.1/tests/golden/__init__.py +0 -0
- knovas_extract-0.1.1/tests/golden/test_adversarial.py +136 -0
- knovas_extract-0.1.1/tests/golden/test_corpus.py +125 -0
- knovas_extract-0.1.1/tests/property/__init__.py +0 -0
- knovas_extract-0.1.1/tests/property/test_network_isolation.py +44 -0
- knovas_extract-0.1.1/tests/property/test_no_crashes.py +79 -0
- knovas_extract-0.1.1/tests/unit/__init__.py +0 -0
- knovas_extract-0.1.1/tests/unit/test_dispatch.py +35 -0
- knovas_extract-0.1.1/tests/unit/test_errors.py +58 -0
- knovas_extract-0.1.1/tests/unit/test_extractors_docx.py +149 -0
- knovas_extract-0.1.1/tests/unit/test_extractors_eml.py +85 -0
- knovas_extract-0.1.1/tests/unit/test_extractors_html.py +82 -0
- knovas_extract-0.1.1/tests/unit/test_extractors_md.py +65 -0
- knovas_extract-0.1.1/tests/unit/test_extractors_msg.py +39 -0
- knovas_extract-0.1.1/tests/unit/test_extractors_pdf.py +122 -0
- knovas_extract-0.1.1/tests/unit/test_extractors_rtf.py +46 -0
- knovas_extract-0.1.1/tests/unit/test_extractors_txt.py +60 -0
- knovas_extract-0.1.1/tests/unit/test_normalize.py +62 -0
- knovas_extract-0.1.1/tests/unit/test_result.py +67 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
build/
|
|
8
|
+
dist/
|
|
9
|
+
*.egg-info/
|
|
10
|
+
.eggs/
|
|
11
|
+
.installed.cfg
|
|
12
|
+
|
|
13
|
+
# Virtual envs
|
|
14
|
+
.venv/
|
|
15
|
+
venv/
|
|
16
|
+
.hatch/
|
|
17
|
+
.python-version
|
|
18
|
+
|
|
19
|
+
# Test / coverage
|
|
20
|
+
.pytest_cache/
|
|
21
|
+
.mypy_cache/
|
|
22
|
+
.ruff_cache/
|
|
23
|
+
.tox/
|
|
24
|
+
.coverage
|
|
25
|
+
.coverage.*
|
|
26
|
+
htmlcov/
|
|
27
|
+
.hypothesis/
|
|
28
|
+
junit.xml
|
|
29
|
+
|
|
30
|
+
# Bench
|
|
31
|
+
.benchmarks/
|
|
32
|
+
|
|
33
|
+
# Fuzz
|
|
34
|
+
crash-*
|
|
35
|
+
crash_*
|
|
36
|
+
fuzz_corpus_minimized/
|
|
37
|
+
|
|
38
|
+
# Spec corpus (consumed via submodule or download — never committed here)
|
|
39
|
+
tests/spec/
|
|
40
|
+
tests/golden_corpus_pinned/
|
|
41
|
+
|
|
42
|
+
# IDE
|
|
43
|
+
.vscode/
|
|
44
|
+
.idea/
|
|
45
|
+
*.swp
|
|
46
|
+
|
|
47
|
+
# OS
|
|
48
|
+
.DS_Store
|
|
49
|
+
Thumbs.db
|
|
50
|
+
|
|
51
|
+
# Security scan artifacts
|
|
52
|
+
sbom.cdx.json
|
|
53
|
+
provenance.intoto.jsonl
|
|
54
|
+
*.sig
|
|
55
|
+
*.crt
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Changelog — knovas-extract (Python)
|
|
2
|
+
|
|
3
|
+
All notable changes documented here. Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); SemVer.
|
|
4
|
+
|
|
5
|
+
A **major** version bump matches the major of `spec_version` it conforms to.
|
|
6
|
+
|
|
7
|
+
## [0.1.1] — 2026-06-25
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
- `release.yml`: the v0.1.0 tag fired the release workflow but the Sign job
|
|
11
|
+
failed because `actions/upload-artifact@v4` with a multi-path config
|
|
12
|
+
nested `dist/` inside itself (`dist/dist/*.whl`). Refactored to upload
|
|
13
|
+
`dist/` as its own artifact (downloads land at `dist/*`) and the SBOM
|
|
14
|
+
as a separate `sbom` artifact. Bumped `sigstore/gh-action-sigstore-python`
|
|
15
|
+
to v3.4.0. Same fix unblocks the Publish-to-PyPI step. No code changes
|
|
16
|
+
vs 0.1.0 — wheel contents are identical except for the version string.
|
|
17
|
+
|
|
18
|
+
## [0.1.0] — 2026-06-25
|
|
19
|
+
|
|
20
|
+
First public release. Conforms to `spec_version = 1.0.0`.
|
|
21
|
+
|
|
22
|
+
### Supported formats
|
|
23
|
+
|
|
24
|
+
PDF (PyMuPDF), DOCX (python-docx + mammoth), TXT, MD, HTML (selectolax),
|
|
25
|
+
RTF (striprtf), EML (stdlib email), MSG (extract-msg).
|
|
26
|
+
|
|
27
|
+
### Security gates (enforced by CI on every commit to `main`)
|
|
28
|
+
|
|
29
|
+
- `pytest-socket`: no extractor may make a network call. Ever.
|
|
30
|
+
- `bandit`, `pip-audit`, `osv-scanner`, `CodeQL`, `gitleaks`: zero
|
|
31
|
+
high/critical findings to merge.
|
|
32
|
+
- Adversarial corpus (in [`knovas/KnowledgeBase`](https://github.com/Seifeddini/KnowledgeBase/tree/develop/clients/extraction/spec) at the pinned spec version):
|
|
33
|
+
encrypted PDF → `EncryptedDocumentError`; decompression-bomb DOCX →
|
|
34
|
+
`ResourceExhaustedError`; zip-slip DOCX → `CorruptDocumentError`;
|
|
35
|
+
billion-laughs HTML → sanitized (selectolax ignores XML entities by
|
|
36
|
+
construction); RTF `\object\objemb` → warning emitted, payload bytes
|
|
37
|
+
never touched.
|
|
38
|
+
- Hypothesis property tests on every extractor: random bytes may raise an
|
|
39
|
+
`ExtractError` subclass OR return a valid `ExtractionResult`, but never
|
|
40
|
+
let through a bare `Exception` / `UnicodeDecodeError` / `RuntimeError`.
|
|
41
|
+
|
|
42
|
+
### Supply-chain
|
|
43
|
+
|
|
44
|
+
- Built reproducibly on GitHub Actions with `step-security/harden-runner`
|
|
45
|
+
(egress allowlist + audit).
|
|
46
|
+
- Wheels are **Sigstore-signed** via OIDC; no long-lived signing keys.
|
|
47
|
+
- **SLSA Level 3 build provenance** attached as `provenance.intoto.jsonl`.
|
|
48
|
+
- **CycloneDX SBOM** (`sbom.cdx.json`) attached to every release.
|
|
49
|
+
- Published to PyPI via **Trusted Publishers (OIDC)** — no API tokens in
|
|
50
|
+
repo secrets.
|
|
51
|
+
|
|
52
|
+
Verify a release with:
|
|
53
|
+
```bash
|
|
54
|
+
python -m sigstore verify identity \
|
|
55
|
+
--cert-identity 'https://github.com/Seifeddini/knovas-extract-python/.github/workflows/release.yml@refs/tags/v0.1.0' \
|
|
56
|
+
--cert-oidc-issuer 'https://token.actions.githubusercontent.com' \
|
|
57
|
+
knovas_extract-0.1.0-py3-none-any.whl
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Performance (synthetic, single thread, Python 3.13 / Win11)
|
|
61
|
+
|
|
62
|
+
| Format | Throughput |
|
|
63
|
+
|---|---|
|
|
64
|
+
| TXT 1 MiB | ~700 MB/s (canonicalizer-bound) |
|
|
65
|
+
| PDF 100 pages | ~120 pages/sec |
|
|
66
|
+
| DOCX 500 paragraphs | ~80 docs/sec |
|
|
67
|
+
| HTML 2000 paragraphs | ~25 docs/sec |
|
|
68
|
+
| EML 2000 body lines | ~40 docs/sec |
|
|
69
|
+
|
|
70
|
+
(Reproduce with `hatch -e bench run run`.)
|
|
71
|
+
|
|
72
|
+
### Public API
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from knovas_extract import (
|
|
76
|
+
extract, # path or bytes -> ExtractionResult
|
|
77
|
+
ExtractionResult, Limits,
|
|
78
|
+
ExtractError, # base
|
|
79
|
+
UnsupportedFormatError,
|
|
80
|
+
CorruptDocumentError,
|
|
81
|
+
EncryptedDocumentError,
|
|
82
|
+
ResourceExhaustedError,
|
|
83
|
+
DependencyMissingError,
|
|
84
|
+
)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Stable in shape from 0.1.0. Breaking changes require a major version bump
|
|
88
|
+
AND a corresponding `spec_version` major bump.
|
|
89
|
+
|
|
90
|
+
[0.1.0]: https://github.com/Seifeddini/knovas-extract-python/releases/tag/v0.1.0
|
|
@@ -0,0 +1,201 @@
|
|
|
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 describing the origin of the Work and
|
|
141
|
+
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 Support. 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 support.
|
|
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 2026 Knovas
|
|
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
|
|
200
|
+
implied. See the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
knovas-extract — Python implementation
|
|
2
|
+
Copyright 2026 Knovas
|
|
3
|
+
|
|
4
|
+
This product includes software developed at Knovas (https://knovas.ch/).
|
|
5
|
+
|
|
6
|
+
================================================================================
|
|
7
|
+
|
|
8
|
+
Third-party components used at runtime:
|
|
9
|
+
|
|
10
|
+
* PyMuPDF (https://github.com/pymupdf/PyMuPDF)
|
|
11
|
+
License: AGPL-3.0
|
|
12
|
+
Used by: src/knovas_extract/extractors/pdf.py
|
|
13
|
+
NOTE: PyMuPDF is AGPL-licensed. If you embed knovas-extract in a closed-source
|
|
14
|
+
application and PyMuPDF is loaded at runtime, AGPL section 13 obligations may
|
|
15
|
+
apply. Use `pip install knovas-extract[minimal]` to install without PyMuPDF
|
|
16
|
+
(PDF extraction will raise DependencyMissingError until you opt in).
|
|
17
|
+
|
|
18
|
+
* python-docx (https://github.com/python-openxml/python-docx)
|
|
19
|
+
License: MIT
|
|
20
|
+
Used by: src/knovas_extract/extractors/docx.py
|
|
21
|
+
|
|
22
|
+
* mammoth (https://github.com/mwilliamson/python-mammoth)
|
|
23
|
+
License: BSD-2-Clause
|
|
24
|
+
Used by: src/knovas_extract/extractors/docx.py (heading extraction)
|
|
25
|
+
|
|
26
|
+
* extract-msg (https://github.com/TeamMsgExtractor/msg-extractor)
|
|
27
|
+
License: GPL-3.0
|
|
28
|
+
Used by: src/knovas_extract/extractors/msg.py
|
|
29
|
+
|
|
30
|
+
* selectolax (https://github.com/rushter/selectolax)
|
|
31
|
+
License: MIT
|
|
32
|
+
Used by: src/knovas_extract/extractors/html.py
|
|
33
|
+
|
|
34
|
+
* striprtf (https://github.com/joshy/striprtf)
|
|
35
|
+
License: BSD-3-Clause
|
|
36
|
+
Used by: src/knovas_extract/extractors/rtf.py
|
|
37
|
+
|
|
38
|
+
* python-magic (https://github.com/ahupp/python-magic)
|
|
39
|
+
License: MIT
|
|
40
|
+
Used by: src/knovas_extract/dispatch.py (MIME detection)
|
|
41
|
+
|
|
42
|
+
* defusedxml (https://github.com/tiran/defusedxml)
|
|
43
|
+
License: PSF-2.0
|
|
44
|
+
Used by: any XML parsing path (XXE / billion-laughs protection)
|
|
45
|
+
|
|
46
|
+
* python-frontmatter (https://github.com/eyeseast/python-frontmatter)
|
|
47
|
+
License: MIT
|
|
48
|
+
Used by: src/knovas_extract/extractors/md.py
|
|
49
|
+
|
|
50
|
+
* chardet (https://github.com/chardet/chardet)
|
|
51
|
+
License: LGPL-2.1
|
|
52
|
+
Used by: src/knovas_extract/extractors/txt.py (encoding detection)
|
|
53
|
+
|
|
54
|
+
This NOTICE is regenerated from the SBOM on every release. Last manual update: 2026-06-25.
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: knovas-extract
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Privacy-preserving, performant document extraction (text + metadata) for the Knovas Semantix platform. Python reference implementation.
|
|
5
|
+
Project-URL: Homepage, https://github.com/knovas/knovas-extract-python
|
|
6
|
+
Project-URL: Documentation, https://github.com/knovas/knovas-extract-python#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/knovas/knovas-extract-python
|
|
8
|
+
Project-URL: Issues, https://github.com/knovas/knovas-extract-python/issues
|
|
9
|
+
Project-URL: Security, https://github.com/knovas/knovas-extract-python/blob/main/SECURITY.md
|
|
10
|
+
Project-URL: Changelog, https://github.com/knovas/knovas-extract-python/blob/main/CHANGELOG.md
|
|
11
|
+
Author-email: Knovas <engineering@knovas.ch>
|
|
12
|
+
Maintainer-email: Knovas <engineering@knovas.ch>
|
|
13
|
+
License-Expression: Apache-2.0
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
License-File: NOTICE
|
|
16
|
+
Keywords: docx,extraction,knovas,metadata,msg,pdf,semantix,text
|
|
17
|
+
Classifier: Development Status :: 3 - Alpha
|
|
18
|
+
Classifier: Intended Audience :: Developers
|
|
19
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Topic :: Text Processing
|
|
26
|
+
Requires-Python: >=3.11
|
|
27
|
+
Requires-Dist: chardet>=5.2.0
|
|
28
|
+
Requires-Dist: defusedxml>=0.7.1
|
|
29
|
+
Requires-Dist: python-magic-bin>=0.4.14; sys_platform == 'win32'
|
|
30
|
+
Requires-Dist: python-magic>=0.4.27; sys_platform != 'win32'
|
|
31
|
+
Provides-Extra: all
|
|
32
|
+
Requires-Dist: extract-msg>=0.48.0; extra == 'all'
|
|
33
|
+
Requires-Dist: mammoth>=1.8.0; extra == 'all'
|
|
34
|
+
Requires-Dist: pymupdf>=1.24.0; extra == 'all'
|
|
35
|
+
Requires-Dist: python-docx>=1.1.2; extra == 'all'
|
|
36
|
+
Requires-Dist: python-frontmatter>=1.1.0; extra == 'all'
|
|
37
|
+
Requires-Dist: selectolax>=0.3.21; extra == 'all'
|
|
38
|
+
Requires-Dist: striprtf>=0.0.27; extra == 'all'
|
|
39
|
+
Provides-Extra: docx
|
|
40
|
+
Requires-Dist: mammoth>=1.8.0; extra == 'docx'
|
|
41
|
+
Requires-Dist: python-docx>=1.1.2; extra == 'docx'
|
|
42
|
+
Provides-Extra: html
|
|
43
|
+
Requires-Dist: selectolax>=0.3.21; extra == 'html'
|
|
44
|
+
Provides-Extra: md
|
|
45
|
+
Requires-Dist: python-frontmatter>=1.1.0; extra == 'md'
|
|
46
|
+
Provides-Extra: minimal
|
|
47
|
+
Provides-Extra: msg
|
|
48
|
+
Requires-Dist: extract-msg>=0.48.0; extra == 'msg'
|
|
49
|
+
Provides-Extra: pdf
|
|
50
|
+
Requires-Dist: pymupdf>=1.24.0; extra == 'pdf'
|
|
51
|
+
Provides-Extra: rtf
|
|
52
|
+
Requires-Dist: striprtf>=0.0.27; extra == 'rtf'
|
|
53
|
+
Description-Content-Type: text/markdown
|
|
54
|
+
|
|
55
|
+
# knovas-extract
|
|
56
|
+
|
|
57
|
+
[](https://github.com/knovas/knovas-extract-python/actions/workflows/ci.yml)
|
|
58
|
+
[](https://pypi.org/project/knovas-extract/)
|
|
59
|
+
[](https://pypi.org/project/knovas-extract/)
|
|
60
|
+
[](LICENSE)
|
|
61
|
+
|
|
62
|
+
Privacy-preserving, performant document extraction (text + metadata) for the [Knovas Semantix](https://knovas.ch/) platform. **Python reference implementation** of the cross-language `knovas-extract` spec.
|
|
63
|
+
|
|
64
|
+
> **Status: alpha (0.1.0.dev).** API stable in shape, not yet in version. Not yet on PyPI.
|
|
65
|
+
|
|
66
|
+
## What it does
|
|
67
|
+
|
|
68
|
+
Give it a document (PDF, DOCX, MSG, EML, HTML, RTF, MD, TXT). Get back a `ExtractionResult`: extracted text, document metadata (title, author, language, dates, page count), per-page text (when paginated), and heading-derived sections.
|
|
69
|
+
|
|
70
|
+
That's the whole library. It does **not** chunk, embed, upload to Semantix, or talk to any network. Those concerns belong in your application code.
|
|
71
|
+
|
|
72
|
+
## Why
|
|
73
|
+
|
|
74
|
+
- **Spec-first**: the [output contract](https://github.com/knovas/KnowledgeBase/tree/develop/clients/extraction/spec) is shared across every language implementation in the `knovas-extract-*` family. Your Python output and a future Node/Go/Rust output are guaranteed equivalent (within documented tolerances).
|
|
75
|
+
- **Fast**: uses the best native library per format (PyMuPDF for PDF, selectolax for HTML, …). PDF throughput ≈ 20–100 pages/sec on a single thread; lazy-imports keep cold start ≈ 50 ms.
|
|
76
|
+
- **Safe by default**: no network calls, no embedded-code execution, no path traversal, ZIP-bomb caps, XXE-hardened XML, typed errors only. See [`SECURITY.md`](SECURITY.md) for the full posture.
|
|
77
|
+
|
|
78
|
+
## Install
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pip install knovas-extract # core only (TXT/MD/HTML/EML)
|
|
82
|
+
pip install 'knovas-extract[pdf]' # + PyMuPDF (AGPL — read NOTICE)
|
|
83
|
+
pip install 'knovas-extract[docx,msg,rtf]' # + DOCX/MSG/RTF
|
|
84
|
+
pip install 'knovas-extract[all]' # everything
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
License-sensitive embedders: install `knovas-extract[minimal]` for the permissive-only subset (no AGPL / GPL deps). Calling `extract()` on a format that needs an unavailable backend raises `DependencyMissingError` with the exact `pip install` command to fix it.
|
|
88
|
+
|
|
89
|
+
## Quickstart
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from knovas_extract import extract
|
|
93
|
+
|
|
94
|
+
result = extract("report.pdf")
|
|
95
|
+
|
|
96
|
+
print(result.content.text) # full extracted text, canonicalized
|
|
97
|
+
print(result.metadata.title) # e.g. "Q4 Earnings"
|
|
98
|
+
print(result.metadata.page_count) # e.g. 12
|
|
99
|
+
for page in result.content.pages: # per-page text (when paginated)
|
|
100
|
+
print(page.index, page.text[:80])
|
|
101
|
+
print(result.warnings) # e.g. ["page 7: unrecognized font"]
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Bytes work too:
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
data = open("report.pdf", "rb").read()
|
|
108
|
+
result = extract(data, mime="application/pdf")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`ExtractionResult.to_dict()` round-trips through the spec's JSON Schema; pass it directly to anything expecting the contract shape.
|
|
112
|
+
|
|
113
|
+
## Resource limits
|
|
114
|
+
|
|
115
|
+
Every extraction is bounded. Override the defaults per call:
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from knovas_extract import extract, Limits
|
|
119
|
+
|
|
120
|
+
result = extract(
|
|
121
|
+
"huge.docx",
|
|
122
|
+
limits=Limits(
|
|
123
|
+
max_input_bytes=50 * 1024 * 1024, # 50 MiB cap
|
|
124
|
+
max_pages=1_000,
|
|
125
|
+
max_decompression_ratio=50,
|
|
126
|
+
max_text_bytes=10 * 1024 * 1024,
|
|
127
|
+
),
|
|
128
|
+
)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
When a limit is crossed, you get a `ResourceExhaustedError` with `.what` / `.limit` / `.observed` attributes. Defaults (in `Limits()`) are conservative; tune them with your throughput budget in mind.
|
|
132
|
+
|
|
133
|
+
## Errors
|
|
134
|
+
|
|
135
|
+
Every call either returns an `ExtractionResult` or raises a subclass of `ExtractError`:
|
|
136
|
+
|
|
137
|
+
| Exception | When |
|
|
138
|
+
|---|---|
|
|
139
|
+
| `UnsupportedFormatError` | MIME not registered (you can register a custom extractor via `knovas_extract.dispatch.MIME_REGISTRY`). |
|
|
140
|
+
| `CorruptDocumentError` | Bytes couldn't be parsed as the claimed format. |
|
|
141
|
+
| `EncryptedDocumentError` | Password-protected document, no password supplied. |
|
|
142
|
+
| `ResourceExhaustedError` | A `Limits` threshold was crossed. |
|
|
143
|
+
| `DependencyMissingError` | An optional extra isn't installed — exception tells you the exact install command. |
|
|
144
|
+
|
|
145
|
+
No bare exceptions, no `None`, no `Optional[ExtractionResult]`.
|
|
146
|
+
|
|
147
|
+
## Security promises (enforced by CI)
|
|
148
|
+
|
|
149
|
+
- **Never makes a network call.** Asserted across every test via `pytest-socket`.
|
|
150
|
+
- **Never executes embedded code.** PDF JavaScript, DOCX macros, RTF object linking — all stripped, warning emitted.
|
|
151
|
+
- **Never writes outside an explicit tmpdir.** ZIP-slip paths are rejected.
|
|
152
|
+
- **XML parsing is XXE-hardened.** All XML goes through `defusedxml`.
|
|
153
|
+
- Releases are **Sigstore-signed** + ship **SLSA L3 provenance**. Verify before installing in production — see [`RELEASING.md`](RELEASING.md).
|
|
154
|
+
|
|
155
|
+
For untrusted inputs, run inside a sandbox. Copy-paste recipes for `nsjail`, `bubblewrap`, and rootless Docker in [`docs/sandboxing.md`](docs/sandboxing.md).
|
|
156
|
+
|
|
157
|
+
## Spec conformance
|
|
158
|
+
|
|
159
|
+
This implementation conforms to `spec_version = 1.0.0` of [`knovas/KnowledgeBase/clients/extraction/spec`](https://github.com/knovas/KnowledgeBase/tree/develop/clients/extraction/spec). The pinned spec sha is recorded in `tests/spec/` (Git submodule). Every release runs the spec's golden corpus + adversarial corpus before tagging.
|
|
160
|
+
|
|
161
|
+
To run the golden tests locally against a sibling KnowledgeBase checkout:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
export KNOVAS_EXTRACT_SPEC_DIR=/path/to/KnowledgeBase/clients/extraction/spec
|
|
165
|
+
hatch -e golden run run
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Development
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
hatch env create # one-time
|
|
172
|
+
hatch run test # unit tests
|
|
173
|
+
hatch -e golden run run # corpus contract tests
|
|
174
|
+
hatch -e property run run # hypothesis robustness
|
|
175
|
+
hatch -e bench run run # benchmarks
|
|
176
|
+
hatch -e lint run all # ruff + mypy + pyright
|
|
177
|
+
hatch -e sec run all # bandit + pip-audit
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
CI runs the full matrix (3 Pythons × 3 OSes × every gate) on every PR.
|
|
181
|
+
|
|
182
|
+
## Reporting vulnerabilities
|
|
183
|
+
|
|
184
|
+
See [`SECURITY.md`](SECURITY.md). Please **do not** open public issues for security reports.
|
|
185
|
+
|
|
186
|
+
## License
|
|
187
|
+
|
|
188
|
+
Apache-2.0 for `knovas-extract` itself. Several optional extras pull AGPL / GPL libraries — see [`NOTICE`](NOTICE) for the full third-party license inventory.
|