fastdocparse 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,132 @@
1
+ Metadata-Version: 2.4
2
+ Name: fastdocparse
3
+ Version: 0.1.0
4
+ Summary: Extract structured data from semi-structured documents using any OpenAI-compatible LLM, with per-field grounding and confidence.
5
+ License-Expression: MIT
6
+ Requires-Python: <3.13,>=3.9
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: pydantic>=2.0
10
+ Requires-Dist: openai>=1.0
11
+ Requires-Dist: pymupdf>=1.24
12
+ Requires-Dist: pillow>=10.0
13
+ Requires-Dist: rapidocr-onnxruntime>=1.3
14
+ Requires-Dist: typer>=0.12
15
+ Requires-Dist: PyYAML>=6.0
16
+ Provides-Extra: dev
17
+ Requires-Dist: pytest; extra == "dev"
18
+ Dynamic: license-file
19
+
20
+ # docextract
21
+
22
+ Extract structured data from semi-structured documents — invoices, bills, tax forms, resumes, bank statements, shipment manifests — using any OpenAI-compatible LLM (OpenAI, Ollama, vLLM, Groq, etc.), with **per-field grounding and confidence**, not just raw extraction.
23
+
24
+ ## Why this, not just another parser
25
+
26
+ Most extractors give you a value and no way to know if it's real. This one tells you:
27
+
28
+ - **`grounded`** — the value was found verbatim (or near-verbatim) in the source document text.
29
+ - **`ungrounded`** — the value doesn't appear in the source — likely a hallucination. Flag for human review.
30
+ - **`missing_required`** — a field you marked required came back empty.
31
+ - **`invalid_format`** — the value doesn't match a pattern/enum constraint you declared (e.g. a shipment status outside the allowed list).
32
+ - **`failed_check`** — a custom cross-field rule failed (e.g. line items don't sum to the stated total).
33
+
34
+ No extra LLM call for any of this — it's deterministic, string/rule-based validation against text you already extracted.
35
+
36
+ **Where it fits:** semi-structured documents with recurring fields (invoices, bills, tax forms, resumes, statements), and prose documents where *proving* a value came from the source matters (contracts, legal clauses, insurance claims). It is not a vision-LLM pipeline — it works from extracted text (digital PDF text layer, or local OCR for scans/images), which is what keeps it fast, cheap, and usable with small local models. Messy handwritten forms or complex multi-column layouts are a known weaker spot (see [document-extractor-spec.md](document-extractor-spec.md)).
37
+
38
+ ## Two ways to use it
39
+
40
+ | | Who it's for | How |
41
+ |---|---|---|
42
+ | **CLI** | No coding needed | `docextract extract <file> <schema.json>` |
43
+ | **Python API** | Building it into your own app | `DocumentParser(client).extract(document_bytes, schema)` |
44
+
45
+ Defining *what* to extract also has two paths — hand-write a JSON/YAML schema file, or describe it in plain English and let the LLM draft the schema for you.
46
+
47
+ ## Install
48
+
49
+ ```bash
50
+ git clone <this repo>
51
+ cd document-extractor
52
+ python -m venv venv
53
+ source venv/bin/activate # Windows: venv\Scripts\activate
54
+ pip install -e .
55
+ ```
56
+
57
+ (Not yet published to PyPI — see [Status](#status). Until then, install from a local clone as above.)
58
+
59
+ You also need access to an LLM. Either:
60
+ - An OpenAI API key (`export OPENAI_API_KEY=...` or pass `--api-key`), or
61
+ - A local model via [Ollama](https://ollama.com/) — no API key, no cloud, documents never leave your machine.
62
+
63
+ ## Quickstart — CLI (no coding)
64
+
65
+ ```bash
66
+ # 1. Extract using one of the bundled example schemas
67
+ docextract extract sample_invoice.png src/docextract/schemas/invoice.json \
68
+ --model gpt-4o-mini --api-key sk-...
69
+
70
+ # Or with a local model via Ollama (no API key needed):
71
+ docextract extract sample_invoice.png src/docextract/schemas/invoice.json \
72
+ --model llama3.2 --base-url http://localhost:11434/v1 --api-key ollama
73
+ ```
74
+
75
+ Output is JSON, printed to stdout (or saved with `--output result.json`):
76
+
77
+ ```json
78
+ {
79
+ "_meta": { "truncated": false, "truncation_reason": null },
80
+ "invoice_number": { "value": "INV-9011", "confidence": "high", "flags": ["grounded"] },
81
+ "total_price": { "value": 100.0, "confidence": "high", "flags": ["grounded"] }
82
+ }
83
+ ```
84
+
85
+ Don't want to write JSON at all? Describe the fields in plain English instead:
86
+
87
+ ```bash
88
+ docextract schema-from-text \
89
+ "I want the invoice number, total price, and vendor name. Invoice number and total are required." \
90
+ --output my_invoice_schema.json
91
+
92
+ # review my_invoice_schema.json, then:
93
+ docextract extract my_invoice.pdf my_invoice_schema.json
94
+ ```
95
+
96
+ ## Quickstart — Python API
97
+
98
+ ```python
99
+ from docextract import Schema, Field, LLMClient, DocumentParser
100
+
101
+ schema = Schema(
102
+ name="Invoice",
103
+ fields=[
104
+ Field(name="invoice_number", description="The invoice number", required=True),
105
+ Field(name="total_price", description="Total amount due", type="number", required=True),
106
+ ],
107
+ )
108
+
109
+ client = LLMClient(model="gpt-4o-mini", api_key="sk-...")
110
+ # or: LLMClient(base_url="http://localhost:11434/v1", api_key="ollama", model="llama3.2")
111
+
112
+ parser = DocumentParser(client=client)
113
+
114
+ with open("invoice.pdf", "rb") as f:
115
+ result = parser.extract(f.read(), schema)
116
+
117
+ print(result["invoice_number"]) # {'value': 'INV-9011', 'confidence': 'high', 'flags': ['grounded']}
118
+ ```
119
+
120
+ ## Full documentation
121
+
122
+ - [Getting Started](docs/getting-started.md) — step-by-step install, CLI, and API walkthroughs
123
+ - [Schema Guide](docs/schema-guide.md) — every field option (`type`, `required`, `pattern`, `enum`, `sub_fields`, few-shot `examples`), for JSON, YAML, and plain-English authoring
124
+ - [Output & Validation](docs/output-format.md) — the full result shape, what each confidence flag means, and how to write custom cross-check rules
125
+ - [Architecture](docs/architecture.md) — diagrams of the pipeline, the module dependency graph, and where to plug in a contribution
126
+ - [Project spec](document-extractor-spec.md) — architecture, phased roadmap, honest competitive positioning
127
+
128
+ Want to contribute? Start with [docs/architecture.md](docs/architecture.md) for the map, then [CONTRIBUTING.md](CONTRIBUTING.md) for the process.
129
+
130
+ ## Status
131
+
132
+ Core extraction, grounding, chunking, both CLI/API paths, and real packaging (`pip install -e .` installs a working `docextract` command and a proper `docextract.*` import namespace — verified with a from-scratch build and a clean-virtualenv install) are implemented and tested (74 tests, `pytest -v`). Not yet done: actually publishing to PyPI and a hosted API — see [document-extractor-spec.md](document-extractor-spec.md) for the roadmap.
@@ -0,0 +1,24 @@
1
+ docextract/__init__.py,sha256=o7Zr_o8-BbVdp_G0g0tI0weqnmvgbhrW-CTQtjuSS6Y,1660
2
+ docextract/cache.py,sha256=vhVlCbef7Zz554Ur6eawpJBfvmp85S8PYUh1XI9hj2A,3030
3
+ docextract/cli.py,sha256=6XxdTCoy999bun_hzB7HMqNO8hKnTdCS2Z4vDlhPPO4,6707
4
+ docextract/config.py,sha256=ptXseRewPutmOB8JkJFoHfDlCG5rbuLqvClLHafs_QA,2021
5
+ docextract/example_schemas.py,sha256=kxrPHIXpCKyZrzollVd6HtBFGnOT5q2YcdksV6a-yIc,414
6
+ docextract/grounding.py,sha256=wbmmXOWnKWrsQWIML2fVYKuI0xqjc3UL2tYKPJ4plhc,11773
7
+ docextract/json_repair.py,sha256=CYpUHw2GMr34oXQiPSYYRaCGsny8V4cPKCB9-YatmAA,2475
8
+ docextract/llm_client.py,sha256=5j4oVRsNW3M-KwzQL3vWA9cr3I1CEVubUfV23LkGmUY,3462
9
+ docextract/ocr_engine.py,sha256=IFtDccMozoUJSvrfZdDnbMmK7BjP2VGIiNanbb98Ji0,3518
10
+ docextract/parser.py,sha256=qmZhI6ZOYQGjtrcnUcIonQl4vLKntwvxzVSThDY2T04,13322
11
+ docextract/pdf_utils.py,sha256=ubjLDK0xrlDKb-TElVCNqwoJ0EwBwBjDcC0CwiKIgJQ,9915
12
+ docextract/prompt_compiler.py,sha256=Chah4Fy05jgcYu5dNJNLnTAUF-tvjrZ2-DzpzNyxXVA,4078
13
+ docextract/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ docextract/result.py,sha256=HHsT84DEwVyE9ILgwYB11bbiuqcMD4mdSvJw-wsXK6g,1348
15
+ docextract/schema.py,sha256=emooO7tkh9br5ycwVPBfKlrqjjvVIkzU6QWk5qTwEQo,3683
16
+ docextract/schema_compiler.py,sha256=5MwAOtuzDQlCtNxvSYRpHGOgmEc0WbKUYaYrk9WaGr0,2992
17
+ docextract/schemas/invoice.json,sha256=Um3GV_4fLcixhSqs1FeK9SF463qvF7zcdl-eV62g0HE,2779
18
+ docextract/schemas/shipment_manifest.json,sha256=g8qAs-2GFkL3PzFOxDUeGps_Sn1-8VwpOiCbjdoh-cY,1067
19
+ fastdocparse-0.1.0.dist-info/licenses/LICENSE,sha256=pmOG2pg2FX08pkVqOpjolZxKXQNk6u0ZDGuOtUtoWH4,1071
20
+ fastdocparse-0.1.0.dist-info/METADATA,sha256=2Xrk2UEl8njs95u_Q7uGNoED2AwFm4JLzfcHrE6tcW4,6291
21
+ fastdocparse-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
22
+ fastdocparse-0.1.0.dist-info/entry_points.txt,sha256=8QsCzit5mgKHi_H1-8GNP5uvCZDYnZNEF8vy9BV_ugs,50
23
+ fastdocparse-0.1.0.dist-info/top_level.txt,sha256=17vpR7l-bwzr5okQuOGZJcj33NQJqXOFIVqwxQdnatU,11
24
+ fastdocparse-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ docextract = docextract.cli:app
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pranjal Parmar
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.
@@ -0,0 +1 @@
1
+ docextract