docket-idp 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.
- docket_idp-0.1.0/LICENSE +202 -0
- docket_idp-0.1.0/NOTICE +4 -0
- docket_idp-0.1.0/PKG-INFO +350 -0
- docket_idp-0.1.0/README.md +290 -0
- docket_idp-0.1.0/pyproject.toml +98 -0
- docket_idp-0.1.0/setup.cfg +4 -0
- docket_idp-0.1.0/src/docket/__init__.py +92 -0
- docket_idp-0.1.0/src/docket/amounts.py +68 -0
- docket_idp-0.1.0/src/docket/api.py +212 -0
- docket_idp-0.1.0/src/docket/checksums.py +358 -0
- docket_idp-0.1.0/src/docket/classify.py +290 -0
- docket_idp-0.1.0/src/docket/classify_tfidf.py +153 -0
- docket_idp-0.1.0/src/docket/cli.py +78 -0
- docket_idp-0.1.0/src/docket/config.py +101 -0
- docket_idp-0.1.0/src/docket/export/__init__.py +166 -0
- docket_idp-0.1.0/src/docket/export/einvoice.py +545 -0
- docket_idp-0.1.0/src/docket/export/erp.py +755 -0
- docket_idp-0.1.0/src/docket/extract.py +207 -0
- docket_idp-0.1.0/src/docket/forensics.py +385 -0
- docket_idp-0.1.0/src/docket/job_store.py +82 -0
- docket_idp-0.1.0/src/docket/language.py +98 -0
- docket_idp-0.1.0/src/docket/llm_client.py +287 -0
- docket_idp-0.1.0/src/docket/logging_setup.py +94 -0
- docket_idp-0.1.0/src/docket/matching.py +670 -0
- docket_idp-0.1.0/src/docket/ocr.py +342 -0
- docket_idp-0.1.0/src/docket/ocr_quality.py +110 -0
- docket_idp-0.1.0/src/docket/pdf.py +46 -0
- docket_idp-0.1.0/src/docket/pipeline.py +229 -0
- docket_idp-0.1.0/src/docket/py.typed +0 -0
- docket_idp-0.1.0/src/docket/review_queue.py +195 -0
- docket_idp-0.1.0/src/docket/schemas.py +610 -0
- docket_idp-0.1.0/src/docket/validate.py +1791 -0
- docket_idp-0.1.0/src/docket_idp.egg-info/PKG-INFO +350 -0
- docket_idp-0.1.0/src/docket_idp.egg-info/SOURCES.txt +61 -0
- docket_idp-0.1.0/src/docket_idp.egg-info/dependency_links.txt +1 -0
- docket_idp-0.1.0/src/docket_idp.egg-info/entry_points.txt +3 -0
- docket_idp-0.1.0/src/docket_idp.egg-info/requires.txt +36 -0
- docket_idp-0.1.0/src/docket_idp.egg-info/top_level.txt +1 -0
- docket_idp-0.1.0/tests/test_amounts.py +55 -0
- docket_idp-0.1.0/tests/test_api_service.py +94 -0
- docket_idp-0.1.0/tests/test_boarding_pass.py +92 -0
- docket_idp-0.1.0/tests/test_checksums.py +223 -0
- docket_idp-0.1.0/tests/test_classify.py +210 -0
- docket_idp-0.1.0/tests/test_classify_tfidf.py +25 -0
- docket_idp-0.1.0/tests/test_escalation.py +144 -0
- docket_idp-0.1.0/tests/test_eval_scripts.py +74 -0
- docket_idp-0.1.0/tests/test_export.py +468 -0
- docket_idp-0.1.0/tests/test_forensics.py +188 -0
- docket_idp-0.1.0/tests/test_integration_api.py +183 -0
- docket_idp-0.1.0/tests/test_job_store.py +18 -0
- docket_idp-0.1.0/tests/test_language.py +32 -0
- docket_idp-0.1.0/tests/test_long_documents.py +105 -0
- docket_idp-0.1.0/tests/test_matching.py +553 -0
- docket_idp-0.1.0/tests/test_metrics.py +114 -0
- docket_idp-0.1.0/tests/test_model_selection.py +125 -0
- docket_idp-0.1.0/tests/test_ocr_fallback.py +39 -0
- docket_idp-0.1.0/tests/test_ocr_quality.py +77 -0
- docket_idp-0.1.0/tests/test_page_validation.py +83 -0
- docket_idp-0.1.0/tests/test_review_queue.py +130 -0
- docket_idp-0.1.0/tests/test_schemas.py +405 -0
- docket_idp-0.1.0/tests/test_tracing.py +47 -0
- docket_idp-0.1.0/tests/test_validate.py +1182 -0
- docket_idp-0.1.0/tests/test_witness.py +303 -0
docket_idp-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
docket_idp-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: docket-idp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Invoice and receipt data extraction with OCR and LLMs — validated JSON, source citations, human review, EU e-invoicing export
|
|
5
|
+
Author: Artem Kazakov Kozlov
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/KazKozDev/docket
|
|
8
|
+
Project-URL: Documentation, https://github.com/KazKozDev/docket#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/KazKozDev/docket
|
|
10
|
+
Project-URL: Issues, https://github.com/KazKozDev/docket/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/KazKozDev/docket/blob/master/CHANGELOG.md
|
|
12
|
+
Keywords: invoice,receipt,ocr,llm,document-ai,idp,e-invoicing,ubl,peppol,zugferd,factur-x,xrechnung,facturae
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Office/Business :: Financial :: Accounting
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
|
24
|
+
Classifier: Topic :: Text Processing
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
License-File: NOTICE
|
|
30
|
+
Requires-Dist: pydantic>=2.6
|
|
31
|
+
Requires-Dist: pdfplumber>=0.11
|
|
32
|
+
Requires-Dist: pypdfium2>=4.20
|
|
33
|
+
Requires-Dist: pytesseract>=0.3.10
|
|
34
|
+
Requires-Dist: pillow>=10.0
|
|
35
|
+
Requires-Dist: httpx>=0.27
|
|
36
|
+
Requires-Dist: python-dotenv>=1.0
|
|
37
|
+
Requires-Dist: scikit-learn>=1.4
|
|
38
|
+
Requires-Dist: python-stdnum>=2.0
|
|
39
|
+
Provides-Extra: api
|
|
40
|
+
Requires-Dist: fastapi>=0.110; extra == "api"
|
|
41
|
+
Requires-Dist: uvicorn>=0.29; extra == "api"
|
|
42
|
+
Requires-Dist: python-multipart>=0.0.9; extra == "api"
|
|
43
|
+
Provides-Extra: ui
|
|
44
|
+
Requires-Dist: streamlit>=1.38; extra == "ui"
|
|
45
|
+
Provides-Extra: tui
|
|
46
|
+
Requires-Dist: rich>=13.7; extra == "tui"
|
|
47
|
+
Provides-Extra: tracing
|
|
48
|
+
Requires-Dist: langfuse>=2.0; extra == "tracing"
|
|
49
|
+
Provides-Extra: all
|
|
50
|
+
Requires-Dist: docket-idp[api,tracing,tui,ui]; extra == "all"
|
|
51
|
+
Provides-Extra: eval
|
|
52
|
+
Requires-Dist: datasets>=2.19; extra == "eval"
|
|
53
|
+
Provides-Extra: dev
|
|
54
|
+
Requires-Dist: docket-idp[api,eval,tui,ui]; extra == "dev"
|
|
55
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
56
|
+
Requires-Dist: pymupdf>=1.24; extra == "dev"
|
|
57
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
58
|
+
Requires-Dist: twine>=5.0; extra == "dev"
|
|
59
|
+
Dynamic: license-file
|
|
60
|
+
|
|
61
|
+
# docket — local document AI, invoice & receipt OCR parser with LLMs
|
|
62
|
+
|
|
63
|
+
Turn scanned invoices, receipts, and contracts into structured, validated JSON using local OCR and vision-language models — and export them as EU e-invoices (XRechnung, ZUGFeRD / Factur-X, Peppol UBL, Facturae).
|
|
64
|
+
|
|
65
|
+
Apache-2.0 licensed: use it in your own products, commercial or not. Embed it as a Python library, run it as an HTTP service, or call the CLI.
|
|
66
|
+
|
|
67
|
+
<img width="1653" height="961" alt="demo" src="https://github.com/user-attachments/assets/86355d41-34a7-4201-9699-0fd62080c488" />
|
|
68
|
+
|
|
69
|
+
Runs locally with Ollama or on any OpenAI-compatible API (Mistral, OpenAI, Azure, vLLM) · Pydantic schemas · Grounded citations · Zero hallucinations
|
|
70
|
+
|
|
71
|
+
## Quick start: local invoice & receipt parsing
|
|
72
|
+
|
|
73
|
+
You need Tesseract on PATH (`brew install tesseract`, `apt install
|
|
74
|
+
tesseract-ocr`) and an LLM: either [Ollama](https://ollama.com) with a text
|
|
75
|
+
and a vision model pulled, or an OpenAI-compatible API key (see
|
|
76
|
+
[Configuration](#configuration)).
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pip install docket-idp
|
|
80
|
+
docket invoice.pdf
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Classification, OCR extraction, and validation all run against whichever
|
|
84
|
+
models your environment or `.env` names.
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"doc_type": "invoice",
|
|
89
|
+
"invoice_number": "FAC-2026-0042",
|
|
90
|
+
"issue_date": "2026-03-15",
|
|
91
|
+
"vendor_name": "Talleres Montjuïc S.A.",
|
|
92
|
+
"subtotal": 1234.56,
|
|
93
|
+
"tax_amount": 259.26,
|
|
94
|
+
"total_amount": 1493.82,
|
|
95
|
+
"currency": "EUR"
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The process exits non-zero when validation fails, so it drops into a shell
|
|
100
|
+
pipeline as-is.
|
|
101
|
+
|
|
102
|
+
## Use it in your application
|
|
103
|
+
|
|
104
|
+
**As a Python library**
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from docket import Invoice, export_document, process
|
|
108
|
+
|
|
109
|
+
result = process("invoice.pdf", enqueue_review=False) # your app owns the review flow
|
|
110
|
+
if result.is_valid and isinstance(result.document, Invoice):
|
|
111
|
+
print(result.document.vendor_name, result.document.total_amount)
|
|
112
|
+
xml = export_document(result.document, "xrechnung")
|
|
113
|
+
else:
|
|
114
|
+
print(result.review_reasons, result.validation_issues)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`result.document` is the typed schema (`Invoice`, `Receipt`, `Contract`, …);
|
|
118
|
+
`result.field_sources` says where on the page each value was read.
|
|
119
|
+
|
|
120
|
+
**As an HTTP service (any language)**
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
docker run -p 8000:8000 -e DOCKET_API_KEY=secret ghcr.io/kazkozdev/docket
|
|
124
|
+
# or: pip install "docket-idp[api]" && docket-api --port 8000
|
|
125
|
+
curl -H "Authorization: Bearer secret" -F file=@invoice.pdf localhost:8000/process
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The OpenAPI spec is in [`docs/openapi.json`](https://github.com/KazKozDev/docket/blob/master/docs/openapi.json) —
|
|
129
|
+
generate a typed client for TypeScript, Java, C#, Go, etc. from it.
|
|
130
|
+
|
|
131
|
+
**As a CLI**
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
docket invoice.pdf # JSON on stdout, exit code 2 if invalid
|
|
135
|
+
docket invoice.pdf --export xrechnung # e-invoice XML on stdout
|
|
136
|
+
docket --list-formats
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Runnable versions of all three, a TypeScript client, a Mistral-backed
|
|
140
|
+
`docker-compose.yml` and an exporter plugin are in [`examples/`](https://github.com/KazKozDev/docket/blob/master/examples/).
|
|
141
|
+
|
|
142
|
+
## EU e-invoicing and ERP export
|
|
143
|
+
|
|
144
|
+
| Format | `--export` / `export_document(…)` name |
|
|
145
|
+
|---|---|
|
|
146
|
+
| XRechnung (CII) | `xrechnung` |
|
|
147
|
+
| ZUGFeRD 2.2 / Factur-X, EN 16931 | `zugferd` |
|
|
148
|
+
| UBL 2.1 / Peppol BIS Billing 3.0 | `ubl` |
|
|
149
|
+
| Facturae 3.2.2 (Spain) | `facturae` |
|
|
150
|
+
| SAP IDoc / journal CSV | `sap-idoc`, `sap-csv` |
|
|
151
|
+
| Xero, QuickBooks | `xero-csv`, `xero-json`, `quickbooks-iif`, `quickbooks-json` |
|
|
152
|
+
|
|
153
|
+
Need a format that isn't here? Register one in a few lines
|
|
154
|
+
(`register_exporter("my-erp", func, accepts=(Invoice,))`), or ship it as its own
|
|
155
|
+
pip package through the `docket.exporters` entry point — see
|
|
156
|
+
[`examples/exporter_plugin`](https://github.com/KazKozDev/docket/blob/master/examples/exporter_plugin/).
|
|
157
|
+
Always validate generated XML against your recipient's official validator
|
|
158
|
+
(e.g. KoSIT for XRechnung) before going live.
|
|
159
|
+
|
|
160
|
+
## Structured data extraction with Pydantic schemas
|
|
161
|
+
|
|
162
|
+
Each document type has a strict Pydantic schema, and the model fills it under a JSON
|
|
163
|
+
Schema contract rather than being asked nicely for JSON. A result that fails
|
|
164
|
+
validation is sent back to the model with the error attached.
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
docket invoice.pdf
|
|
168
|
+
python tui.py invoice.pdf # same pipeline, live per-stage progress
|
|
169
|
+
streamlit run app.py # browser UI with a document preview
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
European and American number conventions are both parsed, so `1.234,56` and
|
|
173
|
+
`1,234.56` read as the same amount. Keyword rules cover English and Spanish.
|
|
174
|
+
|
|
175
|
+
### Commercial contracts & CLM analysis
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
docket eval/golden_dataset/contract_services.txt
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
```json
|
|
182
|
+
{
|
|
183
|
+
"doc_type": "contract",
|
|
184
|
+
"contract_title": "SERVICES AGREEMENT",
|
|
185
|
+
"parties_a": ["Vertex Consulting LLC"],
|
|
186
|
+
"parties_b": ["Meridian Retail Inc."],
|
|
187
|
+
"effective_date": "2026-03-01",
|
|
188
|
+
"expiration_date": "2027-03-01",
|
|
189
|
+
"governing_law": "State of New York",
|
|
190
|
+
"payment_terms": "within 30 days of invoice",
|
|
191
|
+
"auto_renewal": false,
|
|
192
|
+
"key_obligations": [
|
|
193
|
+
"Party A shall deliver monthly infrastructure audits.",
|
|
194
|
+
"Party A shall provide a dedicated support engineer during business hours.",
|
|
195
|
+
"Party B shall pay Party A within 30 days of invoice."
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Contracts undergo specialized legal validation: counterparty cross-checking (parties cannot contract with themselves), grounding checks (parties, governing law, payment terms, signatories, and liability caps must appear in the raw document), and automated risk assessment (unlimited liability, auto-renewal traps, notice and cure period bounds).
|
|
201
|
+
|
|
202
|
+
## Human-in-the-loop (HITL) review queue for flagged documents
|
|
203
|
+
|
|
204
|
+
Low classification confidence, a failed extraction or an error-severity
|
|
205
|
+
validation issue routes the document to a review queue instead of a database.
|
|
206
|
+
Each entry gets a stable id, a status, the preserved original, and an audit
|
|
207
|
+
history of who changed what.
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
docket eval/golden_dataset/invoice_bad_total.txt
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
```
|
|
214
|
+
doc_9479a6b321e02ab6de25 pending invoice
|
|
215
|
+
validation error: total_amount — subtotal + tax + shipping - discount = 270.60,
|
|
216
|
+
total_amount says 500.00
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
That document prints `Amount Due: 500.00` while its own subtotal and tax add up
|
|
220
|
+
to 270.60. Nothing silently reconciles it.
|
|
221
|
+
|
|
222
|
+
Embedding docket in an app with its own review UI? Pass
|
|
223
|
+
`process(..., enqueue_review=False)` (or set `DOCKET_REVIEW_QUEUE_ENABLED=false`)
|
|
224
|
+
and act on `result.needs_review` / `result.review_reasons` yourself.
|
|
225
|
+
|
|
226
|
+
## Document AI REST API with FastAPI and async worker
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
DOCKET_API_KEY=secret docket-api
|
|
230
|
+
curl -H "Authorization: Bearer secret" -F file=@invoice.pdf localhost:8000/process
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
`POST /process` runs synchronously; `POST /jobs` queues and returns 202 with a
|
|
234
|
+
job id for `GET /jobs/{id}`. `GET /review-queue` lists what is waiting for a
|
|
235
|
+
person, and `/review-queue/{id}/original` returns the document that produced it.
|
|
236
|
+
Interactive OpenAPI docs at `/docs`.
|
|
237
|
+
|
|
238
|
+
## Pipeline architecture: hybrid OCR, classification, and validation
|
|
239
|
+
|
|
240
|
+
Text comes from the cheapest source that works: a PDF text layer if there is
|
|
241
|
+
one, Tesseract for scans, and a Vision-Language Model (VLM) only when OCR confidence is low or
|
|
242
|
+
a cheap text model judges the scan unusable. Classification tries keyword rules,
|
|
243
|
+
then a TF-IDF model, then an LLM — each tier runs only because the last was not
|
|
244
|
+
confident. Extraction fills a Pydantic schema and cites, for every number, the
|
|
245
|
+
verbatim line it was read from.
|
|
246
|
+
|
|
247
|
+
Validation is completely deterministic and never calls a model: it
|
|
248
|
+
checks arithmetic, date ranges, IBAN mod-97 (ISO 7064 across Europe & Brazil), VAT check digits (all 27 EU member states, UK, Switzerland, Norway), national tax IDs (US EIN, Canadian BN, Brazilian CNPJ/CPF), and asserts that each
|
|
249
|
+
cited line exists and contains the number claimed. Detailed flow in [ARCHITECTURE.md](https://github.com/KazKozDev/docket/blob/master/docs/ARCHITECTURE.md).
|
|
250
|
+
|
|
251
|
+
```
|
|
252
|
+
document → text layer / OCR / VLM → classify → extract + cite → validate → JSON or review
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Configuration
|
|
256
|
+
|
|
257
|
+
| Option | Default | What it does |
|
|
258
|
+
|---|---|---|
|
|
259
|
+
| `DOCKET_LLM_PROVIDER` | `ollama` | `ollama`, or `openai` for any OpenAI-compatible API |
|
|
260
|
+
| `DOCKET_LLM_BASE_URL` | `https://api.openai.com/v1` | Endpoint when provider is `openai` (e.g. `https://api.mistral.ai/v1`) |
|
|
261
|
+
| `DOCKET_LLM_API_KEY` | unset | API key when provider is `openai` |
|
|
262
|
+
| `DOCKET_TEXT_MODEL` | `deepseek-v4.1-flash:cloud` | Model for classification and extraction |
|
|
263
|
+
| `DOCKET_VISION_MODEL` | `deepseek-v4.1-flash:cloud` | Model for transcribing scans |
|
|
264
|
+
| `OLLAMA_HOST` | `http://localhost:11434` | Where Ollama is listening |
|
|
265
|
+
| `DOCKET_OCR_LANG` | `eng` | Tesseract languages, e.g. `eng+deu+fra+spa+ita` |
|
|
266
|
+
| `DOCKET_ENABLE_THINKING` | `false` | Reasoning tokens; off is markedly faster for this task |
|
|
267
|
+
| `DOCKET_MIN_CONFIDENCE` | `0.55` | Classification confidence below which a document goes to review |
|
|
268
|
+
| `DOCKET_TFIDF_CONFIDENCE_FLOOR` | `0.65` | TF-IDF confidence needed to skip the LLM tier |
|
|
269
|
+
| `DOCKET_OCR_QUALITY_CHECK` | `true` | Ask a cheap model whether a scan is usable before extracting |
|
|
270
|
+
| `DOCKET_VISION_TIMEOUT_S` | `300` | Vision call timeout |
|
|
271
|
+
| `DOCKET_MAX_FILE_BYTES` | `20971520` | Upload limit for the API |
|
|
272
|
+
| `DOCKET_MAX_PDF_PAGES` | `100` | Page ceiling per document |
|
|
273
|
+
| `DOCKET_API_KEY` | unset | Bearer token; the API refuses requests without it when set |
|
|
274
|
+
| `DOCKET_REVIEW_QUEUE_ENABLED` | `true` | Write flagged documents to the file-based review queue |
|
|
275
|
+
| `DOCKET_REVIEW_QUEUE` | `data/review_queue.jsonl` | Review journal path |
|
|
276
|
+
|
|
277
|
+
Full list in [`src/docket/config.py`](https://github.com/KazKozDev/docket/blob/master/src/docket/config.py); `LANGFUSE_PUBLIC_KEY` and
|
|
278
|
+
`LANGFUSE_SECRET_KEY` enable optional tracing.
|
|
279
|
+
|
|
280
|
+
## Requirements
|
|
281
|
+
|
|
282
|
+
- Python 3.10+
|
|
283
|
+
- macOS or Linux
|
|
284
|
+
- Tesseract OCR on PATH
|
|
285
|
+
- An LLM: a running Ollama with one text and one vision model pulled, or an OpenAI-compatible API (Mistral La Plateforme keeps data in the EU)
|
|
286
|
+
|
|
287
|
+
## Limitations
|
|
288
|
+
|
|
289
|
+
- Four document types: invoice, receipt, contract, boarding pass.
|
|
290
|
+
- Keyword rules and the TF-IDF corpus cover English and Spanish only.
|
|
291
|
+
- The vision model has been observed altering digits to make a page reconcile — a printed `450.00` read three times out of three as `480.00`. No fix for that is in this repo.
|
|
292
|
+
- Line items carry no source citations, so the cited-source check does not cover them.
|
|
293
|
+
- The review queue is one file: durable on one node, not across hosts.
|
|
294
|
+
- Windows is untested; CI runs Linux only. 3.6–9.5 s per document, more when a page needs the vision model.
|
|
295
|
+
|
|
296
|
+
<details>
|
|
297
|
+
<summary>Manual installation, Docker, development setup</summary>
|
|
298
|
+
|
|
299
|
+
### Install options
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
pip install docket-idp # library + CLI
|
|
303
|
+
pip install "docket-idp[api]" # + HTTP service (docket-api)
|
|
304
|
+
pip install "docket-idp[all]" # + Streamlit UI, terminal UI, Langfuse tracing
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### From source
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
git clone https://github.com/KazKozDev/docket.git
|
|
311
|
+
cd docket && python3 -m venv .venv && source .venv/bin/activate
|
|
312
|
+
pip install -e ".[dev]"
|
|
313
|
+
cp .env.example .env
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
On macOS, double-clicking `start.command` creates the venv, starts Ollama if
|
|
317
|
+
needed, frees ports 8000/8501 and opens the UI.
|
|
318
|
+
|
|
319
|
+
### Docker
|
|
320
|
+
|
|
321
|
+
```bash
|
|
322
|
+
docker run -p 8000:8000 -v docket-data:/app/data ghcr.io/kazkozdev/docket
|
|
323
|
+
# or build it yourself: docker build -t docket .
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
The image ships Tesseract with the main EU language packs and talks to Ollama
|
|
327
|
+
on the host by default; set the `DOCKET_LLM_*` variables to use a hosted API
|
|
328
|
+
instead.
|
|
329
|
+
|
|
330
|
+
### Development
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
pytest # none need a running LLM
|
|
334
|
+
python eval/run_eval.py # accuracy, P/R/F1, latency on the golden set
|
|
335
|
+
python eval/benchmark_methods.py # the rules vs TF-IDF vs LLM comparison
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
</details>
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
<div align="center">
|
|
343
|
+
|
|
344
|
+
 
|
|
345
|
+
|
|
346
|
+
 [](https://pypi.org/project/docket-idp/) [](https://github.com/KazKozDev/docket/blob/master/LICENSE) [](https://github.com/KazKozDev/docket/actions)
|
|
347
|
+
|
|
348
|
+
[Issues](https://github.com/KazKozDev/docket/issues) · [ARCHITECTURE](https://github.com/KazKozDev/docket/blob/master/docs/ARCHITECTURE.md) · [CONTRIBUTING](https://github.com/KazKozDev/docket/blob/master/CONTRIBUTING.md) · [CHANGELOG](https://github.com/KazKozDev/docket/blob/master/CHANGELOG.md) · [LICENSE](https://github.com/KazKozDev/docket/blob/master/LICENSE) · [LinkedIn](https://www.linkedin.com/in/kazkozdev/)
|
|
349
|
+
|
|
350
|
+
</div>
|