doc-vision-parser 0.1.3__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,215 @@
1
+ Metadata-Version: 2.4
2
+ Name: doc-vision-parser
3
+ Version: 0.1.3
4
+ Summary: Production-ready document parsing with Vision Language Models
5
+ Project-URL: Homepage, https://github.com/fahmiaziz98/doc-vision-parser
6
+ Project-URL: Repository, https://github.com/fahmiaziz98/doc-vision-parser
7
+ Project-URL: Issues, https://github.com/fahmiaziz98/doc-vision-parser/issues
8
+ Author-email: Fahmi Aziz Fadhil <fahmiazizfadhil09@gmail.com>
9
+ License: Apache License 2.0
10
+ License-File: LICENSE
11
+ Keywords: agentic,document-parsing,ocr,pdf,vision-language-model,vlm
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Requires-Python: >=3.10
20
+ Requires-Dist: langgraph>=1.0.7
21
+ Requires-Dist: numpy>=2.0.2
22
+ Requires-Dist: openai>=2.16.0
23
+ Requires-Dist: opencv-python>=4.13.0
24
+ Requires-Dist: pillow>=11.3.0
25
+ Requires-Dist: pymupdf>=1.26.7
26
+ Provides-Extra: dev
27
+ Requires-Dist: black>=23.0.0; extra == 'dev'
28
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
29
+ Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
30
+ Requires-Dist: pytest>=7.4.0; extra == 'dev'
31
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
32
+ Description-Content-Type: text/markdown
33
+
34
+ # DocVision Parser
35
+
36
+ Production-ready document parsing framework powered by Vision Language Models (VLMs).
37
+
38
+ [![Tests](https://github.com/fahmiaziz98/doc-vision-parser/workflows/Tests/badge.svg)](https://github.com/fahmiaziz98/doc-vision-parser/actions)
39
+ [![PyPI version](https://badge.fury.io/py/doc-vision-parser.svg)](https://badge.fury.io/py/doc-vision-parser)
40
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
41
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-yellow.svg)](https://opensource.org/licenses/Apache-2.0)
42
+
43
+ ## Overview
44
+
45
+ DocVision Parser is a robust Python library designed to extract high-quality structured text and markdown from documents (images and PDFs) using state-of-the-art Vision Language Models like GPT-4o. It goes beyond simple OCR by leveraging the reasoning capabilities of VLMs to understand layout, context, and complex formatting.
46
+
47
+ The framework supports two primary modes:
48
+ 1. **VLM Mode**: Fast, single-shot parsing for standard documents.
49
+ 2. **Agentic Mode**: A self-correcting, iterative workflow using sophisticated graph logic to handle token limits, repetition loops, and incomplete outputs, ensuring the highest possible accuracy for complex documents.
50
+
51
+ ## Features
52
+
53
+ - **Agentic Workflow**: Self-correcting parsing loop that automatically detects and fixes issues like token truncation and repetitive generation.
54
+ - **Async Support**: Built-in high-throughput asynchronous methods for processing large batches of documents efficiently.
55
+ - **Smart Preprocessing**: Intelligent content-aware cropping, DPI management, and dynamic image optimization to ensure the VLM receives the best possible input.
56
+ - **OpenAI-Compatible**: Designed to work with any OpenAI-compatible API, including standard OpenAI endpoints, Azure OpenAI, and self-hosted models via vLLM or SGLang.
57
+ - **Production-Ready**: Includes robust error handling, automatic retries with exponential backoff, and strict output validation.
58
+
59
+ ## Installation
60
+
61
+ Install using `pip`:
62
+
63
+ ```bash
64
+ pip install doc-vision-parser
65
+ ```
66
+
67
+ Or using `uv`:
68
+
69
+ ```bash
70
+ uv add doc-vision-parser
71
+ ```
72
+
73
+ ## Quick Start
74
+
75
+ ### Basic Usage
76
+
77
+ The simplest way to parse an image is using the `DocumentParsingAgent` in VLM mode.
78
+
79
+ ```python
80
+ import os
81
+ from docvision import DocumentParsingAgent
82
+
83
+ # Initialize the agent
84
+ agent = DocumentParsingAgent(
85
+ base_url="https://api.openai.com/v1",
86
+ model_name="gpt-4o-mini",
87
+ api_key=os.getenv("OPENAI_API_KEY"),
88
+ )
89
+
90
+ # Parse an image synchronously
91
+ result = agent.parse_image("path/to/document.jpg")
92
+
93
+ print(result.content)
94
+ print(f"Processing time: {result.processing_time:.2f}s")
95
+ ```
96
+
97
+ ## Advanced Usage
98
+
99
+ ### Asynchronous & Batch Processing
100
+
101
+ For processing PDFs or multiple files efficiently, use the asynchronous efficiency of the agent.
102
+
103
+ ```python
104
+ import asyncio
105
+ from docvision import DocumentParsingAgent, ParsingMode
106
+
107
+ async def main():
108
+ agent = DocumentParsingAgent(
109
+ base_url="https://api.openai.com/v1",
110
+ model_name="gpt-4o-mini",
111
+ api_key=os.getenv("OPENAI_API_KEY"),
112
+ )
113
+
114
+ # Parse a PDF asynchronously
115
+ result = await agent.aparse_pdf(
116
+ "path/to/document.pdf",
117
+ mode=ParsingMode.VLM,
118
+ max_concurrent=3
119
+ )
120
+
121
+ print(f"Processed {result.total_pages} pages in {result.total_time:.2f}s")
122
+ for page in result.results:
123
+ print(f"Page {page.page_number} length: {len(page.content)}")
124
+
125
+ if __name__ == "__main__":
126
+ asyncio.run(main())
127
+ ```
128
+
129
+ ### Agentic Mode (Self-Correcting)
130
+
131
+ Use `ParsingMode.AGENTIC` for critical documents where accuracy is paramount. This mode enables the self-correcting workflow that validates output and continues generation if cut off.
132
+
133
+ ```python
134
+ # Agentic mode is always async
135
+ result = await agent.aparse_image(
136
+ "path/to/complex_document.jpg",
137
+ mode=ParsingMode.AGENTIC
138
+ )
139
+
140
+ # Access metadata about the generation process
141
+ print(result.metadata["generation_history"])
142
+ print(f"Iterations needed: {result.metadata['iterations']}")
143
+ ```
144
+
145
+ ### Structured Output with Pydantic
146
+
147
+ You can force the model to return structured JSON data by providing a Pydantic model.
148
+
149
+ ```python
150
+ from pydantic import BaseModel
151
+
152
+ class Invoice(BaseModel):
153
+ invoice_number: str
154
+ total_amount: float
155
+ date: str
156
+
157
+ system_prompt = "You are a financial analyst."
158
+
159
+ result = agent.parse_image(
160
+ "invoice.jpg",
161
+ output_schema=Invoice,
162
+ system_prompt=system_prompt
163
+ )
164
+
165
+ invoice_data = result.content # This will be an instance of Invoice
166
+ print(invoice_data.total_amount)
167
+ ```
168
+
169
+ ## Configuration
170
+
171
+ The `DocumentParsingAgent` is highly configurable.
172
+
173
+ | Parameter | Type | Default | Description |
174
+ | :--- | :--- | :--- | :--- |
175
+ | `model_name` | `str` | `"gpt-4o-mini"` | The VLM model to use. |
176
+ | `api_key` | `str` | `None` | API key. Uses `OPENAI_API_KEY` env var if not set. |
177
+ | `timeout` | `float` | `300.0` | Request timeout in seconds. |
178
+ | `max_tokens` | `int` | `2048` | Maximum tokens for the response. |
179
+ | `auto_crop` | `bool` | `False` | Enable intelligent content cropping. |
180
+ | `resize` | `bool` | `True` | Resize large images to `max_dimension`. |
181
+ | `max_dimension` | `int` | `2048` | Max width/height for resizing. |
182
+ | `dpi` | `int` | `300` | DPI for PDF to image conversion. |
183
+ | `image_format` | `str` | `"jpeg"` | Image encoding format ("jpeg" or "png"). |
184
+
185
+ ## Architecture
186
+
187
+ The framework is built on three core components:
188
+
189
+ 1. **VLMClient**: A reliable wrapper around the OpenAI API that handles connection pooling, retries, and error mapping.
190
+ 2. **ImageProcessor**: Handles the visual pipeline, including PDF rendering, smart cropping, and optimization to maximize model potential.
191
+ 3. **AgenticWorkflow**: A LangGraph-based state machine that orchestrates the cognitive process of parsing, verifying, and correcting output.
192
+
193
+ ## Development
194
+
195
+ To set up the development environment:
196
+
197
+ 1. Install dependencies:
198
+ ```bash
199
+ uv sync --dev
200
+ ```
201
+
202
+ 2. Run linting and formatting:
203
+ ```bash
204
+ make lint
205
+ make format
206
+ ```
207
+
208
+ 3. Run tests:
209
+ ```bash
210
+ make test
211
+ ```
212
+
213
+ ## License
214
+
215
+ This project is licensed under the Apache 2.0 License.
@@ -0,0 +1,18 @@
1
+ docvision/__init__.py,sha256=ynTzsh__7Y67hPxfxwWL5Rl1ilmurUmtrjCcV7m_oiE,155
2
+ docvision/__version__.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
3
+ docvision/core/__init__.py,sha256=nyHIpy2T_YGmgwavoPco1_hW8-JwheV9U7X3h-JO418,356
4
+ docvision/core/client.py,sha256=GWEsZIucOS6gYNVcOC0tLJugGtOF2SWkeb3yKIyWWAA,8033
5
+ docvision/core/parser.py,sha256=ukN6lNiraxDvTXz69jbT9Rx7i0C1HLIQ7yd4Y31RA3Q,16588
6
+ docvision/core/types.py,sha256=XRWS9F3Iwvswe42fl3jN6l5FOu3wCUSIzCVHsdT2MYg,2391
7
+ docvision/processing/__init__.py,sha256=5N_mFvDZoPhFAcOGlhTeN_wUuCwctt3rBdjFLp9LWLc,115
8
+ docvision/processing/crop.py,sha256=5ymj7NQUfr99yviIasXrMYD5NmcHVyi5d5L0qXLoq-8,4706
9
+ docvision/processing/image.py,sha256=BZbfz-aW-SNaQEzFn85UZB8ZpNq-BMWLvw6GPreonnY,6667
10
+ docvision/utils/__init__.py,sha256=EH9r1Y-xJQdMtB2W5Az2hVDZ4Pxqx6o74kGO74fw1oM,271
11
+ docvision/utils/helper.py,sha256=18Fe2XjC-VhldTleO8vg6h8eR7eR3DWQ6ptN6n_9MMY,2822
12
+ docvision/workflows/__init__.py,sha256=8MgFTKt2L2HHF4Xv0poKmHHPD5CemXt9vWzcEb69ybU,324
13
+ docvision/workflows/graph.py,sha256=gBk8XCPcLDwd_YenYGPMRy9H2asQhj9oYeDuNliBpCE,7963
14
+ docvision/workflows/prompts.py,sha256=wG5iGgYpATA5Zp5xgfJKAgYaJAvzsevQPvJmZLFZY_Q,1124
15
+ doc_vision_parser-0.1.3.dist-info/METADATA,sha256=SH8b8nkLo-Wmwc1_Lm7XQgMbXpvAMukVj8xvuGNjJd0,7541
16
+ doc_vision_parser-0.1.3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
17
+ doc_vision_parser-0.1.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
18
+ doc_vision_parser-0.1.3.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.28.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -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 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.
docvision/__init__.py ADDED
@@ -0,0 +1,4 @@
1
+ from .__version__ import __version__
2
+ from .core import DocumentParsingAgent, ParsingMode
3
+
4
+ __all__ = ["__version__", "DocumentParsingAgent", "ParsingMode"]
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,19 @@
1
+ from .client import VLMClient
2
+ from .parser import DocumentParsingAgent
3
+ from .types import (
4
+ AgenticParseState,
5
+ BatchParseResult,
6
+ ImageFormat,
7
+ ParseResult,
8
+ ParsingMode,
9
+ )
10
+
11
+ __all__ = [
12
+ "VLMClient",
13
+ "DocumentParsingAgent",
14
+ "ImageFormat",
15
+ "ParsingMode",
16
+ "ParseResult",
17
+ "BatchParseResult",
18
+ "AgenticParseState",
19
+ ]