super-document-processor 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. super_document_processor-0.1.3/LICENSE +21 -0
  2. super_document_processor-0.1.3/PKG-INFO +376 -0
  3. super_document_processor-0.1.3/README.md +338 -0
  4. super_document_processor-0.1.3/__init__.py +28 -0
  5. super_document_processor-0.1.3/document_processors/process_docx.py +824 -0
  6. super_document_processor-0.1.3/document_processors/process_images.py +39 -0
  7. super_document_processor-0.1.3/document_processors/process_msg.py +62 -0
  8. super_document_processor-0.1.3/document_processors/process_pdf.py +715 -0
  9. super_document_processor-0.1.3/document_processors/process_plain_text.py +25 -0
  10. super_document_processor-0.1.3/document_processors/process_pptx.py +367 -0
  11. super_document_processor-0.1.3/main.py +826 -0
  12. super_document_processor-0.1.3/processor.py +135 -0
  13. super_document_processor-0.1.3/pyproject.toml +72 -0
  14. super_document_processor-0.1.3/setup.cfg +4 -0
  15. super_document_processor-0.1.3/super_document_processor.egg-info/PKG-INFO +376 -0
  16. super_document_processor-0.1.3/super_document_processor.egg-info/SOURCES.txt +31 -0
  17. super_document_processor-0.1.3/super_document_processor.egg-info/dependency_links.txt +1 -0
  18. super_document_processor-0.1.3/super_document_processor.egg-info/entry_points.txt +2 -0
  19. super_document_processor-0.1.3/super_document_processor.egg-info/requires.txt +14 -0
  20. super_document_processor-0.1.3/super_document_processor.egg-info/top_level.txt +1 -0
  21. super_document_processor-0.1.3/utils/aspose_slide_renderer.py +103 -0
  22. super_document_processor-0.1.3/utils/chunker.py +127 -0
  23. super_document_processor-0.1.3/utils/docx_image_utils.py +167 -0
  24. super_document_processor-0.1.3/utils/docx_xml_parser.py +73 -0
  25. super_document_processor-0.1.3/utils/optimizer.py +49 -0
  26. super_document_processor-0.1.3/utils/pdf_image_utils.py +90 -0
  27. super_document_processor-0.1.3/utils/pdf_table_utils.py +627 -0
  28. super_document_processor-0.1.3/utils/pptx_components_extract.py +2197 -0
  29. super_document_processor-0.1.3/utils/pptx_converter.py +170 -0
  30. super_document_processor-0.1.3/utils/vlm.py +176 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Cinderfox
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,376 @@
1
+ Metadata-Version: 2.4
2
+ Name: super-document-processor
3
+ Version: 0.1.3
4
+ Summary: High-fidelity multi-format document parsing and chunking engine for RAG pipelines
5
+ Author: Cinderfox
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Cinderfox/Super-Document-Processor
8
+ Project-URL: Repository, https://github.com/Cinderfox/Super-Document-Processor
9
+ Keywords: document-processing,rag,pdf,docx,pptx,xlsx,multimodal,vlm,chunking,parsing
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
13
+ Classifier: Topic :: Text Processing :: General
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Operating System :: OS Independent
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: PyMuPDF==1.28.2
25
+ Requires-Dist: python-docx==1.2.0
26
+ Requires-Dist: python-pptx==1.0.2
27
+ Requires-Dist: extract-msg==0.56.1
28
+ Requires-Dist: lxml==6.1.3
29
+ Requires-Dist: aspose-slides==26.7.0
30
+ Requires-Dist: python-dotenv==1.2.3
31
+ Requires-Dist: fastapi==0.141.1
32
+ Requires-Dist: uvicorn==0.52.4
33
+ Requires-Dist: python-multipart==0.0.32
34
+ Provides-Extra: dev
35
+ Requires-Dist: build>=1.0.0; extra == "dev"
36
+ Requires-Dist: twine>=5.0.0; extra == "dev"
37
+ Dynamic: license-file
38
+
39
+ # Super Document Processor
40
+
41
+ A high-fidelity, multi-format document parsing and chunking engine tailored for Retrieval-Augmented Generation (RAG) pipelines. It extracts structured text, preserves tables, optionally transcribes embedded charts and images with Vision LLMs, and outputs boundary-aligned chunks.
42
+
43
+ Available as a **Python library**, **CLI tool**, and **FastAPI microservice** (with Docker support).
44
+
45
+ ---
46
+
47
+ ## Supported Formats
48
+
49
+ | Category | Formats | Features Extracted |
50
+ |---|---|---|
51
+ | **Documents** | `.pdf`, `.docx` | Headings, paragraphs, markdown/HTML tables, hyperlinks, embedded images |
52
+ | **Presentations** | `.pptx` | Slide text, shapes, notes, multi-table separation, smart-art, charts |
53
+ | **Emails** | `.msg` | Headers (From, To, Subject, Date) and formatted email body |
54
+ | **Images** | `.jpg`, `.jpeg`, `.png`, `.jfif` | Full VLM vision analysis and table transcription |
55
+ | **Code & Text** | `.txt`, `.md`, `.json`, `.csv`, `.py`, `.js`, `.ts`, `.html`, etc. | Natural paragraph and token-bounded chunking |
56
+
57
+ ---
58
+
59
+ ## Quickstart
60
+
61
+ ### 1. Local Setup
62
+ ```bash
63
+ git clone https://github.com/Cinderfox/Super-Document-Processor.git
64
+ cd Super-Document-Processor
65
+
66
+ # Setup environment
67
+ python -m venv .venv
68
+ source .venv/bin/activate # On Windows: .\.venv\Scripts\activate
69
+ pip install -r requirements.txt
70
+
71
+ # Configure environment (optional, required only for Vision LLMs)
72
+ cp .env.example .env
73
+ ```
74
+
75
+ ### 2. Docker Setup
76
+ ```bash
77
+ docker build -t super-document-processor:latest .
78
+ docker run -d --name doc-processor -p 8000:8000 -v ${PWD}/data:/data super-document-processor:latest
79
+ ```
80
+
81
+ ---
82
+
83
+ ## 1. Python Library Usage
84
+
85
+ ```python
86
+ from super_document_processor import process_file
87
+
88
+ # 1. Standard text & table extraction (zero LLM calls, ultra-fast)
89
+ chunks = process_file("annual_report.pdf")
90
+
91
+ # 2. Extract with Vision LLM (describes embedded charts, diagrams, and photos)
92
+ chunks_with_vision = process_file(
93
+ file_path="pitch_deck.pptx",
94
+ process_images=True,
95
+ model="google-gemini-3-flash" # e.g. "gpt-4o", "google-gemini-3-flash", etc.
96
+ )
97
+
98
+ for chunk in chunks:
99
+ print(f"--- Chunk {chunk['chunkIndex']} ({chunk['filename']}) ---")
100
+ print(chunk["content"])
101
+ ```
102
+
103
+ ### Chunk Data Structure
104
+ ```json
105
+ [
106
+ {
107
+ "content": "==================== Slide 1 ====================\nSlide Text:\n- Performance Scorecard...",
108
+ "chunkIndex": 1,
109
+ "filename": "pitch_deck.pptx"
110
+ }
111
+ ]
112
+ ```
113
+
114
+ ### Direct Chunker Access & Default Limits
115
+ Text-based document processors (`.docx`, `.msg`, `.txt` etc) use `ChunkCollector` for token-safe output partitioning:
116
+ - **Default Max Size**: `6,000` characters per chunk
117
+ - **Default Overlap**: `0` characters (zero duplicated text across chunks)
118
+
119
+ ```python
120
+ from super_document_processor.utils.chunker import collector, chunk_text
121
+
122
+ # Using standalone utility with custom values:
123
+ chunks = chunk_text(text="Your long text...", chunk_size=6000, overlap=200)
124
+
125
+ # Or collecting and retrieving chunked texts:
126
+ collector.add("First section text...")
127
+ chunks = collector.get_chunked_texts(max_size=6000, overlap=200)
128
+ collector.clear()
129
+ ```
130
+
131
+ ### PPTX Slide Rendering & Image Conversion
132
+ Export PowerPoint slides directly to SVGs or PNGs:
133
+
134
+ ```python
135
+ from utils.pptx_converter import convert_pptx, create_pptx_render_zip
136
+
137
+ # 1. Convert all slides to SVGs (returns list of clean SVG strings)
138
+ res = convert_pptx("presentation.pptx", format="svg")
139
+ for s in res["slides"]:
140
+ print(f"Slide {s['slide']}: {s['svg'][:80]}...")
141
+
142
+ # 2. Convert specific slide to high-res PNG bytes
143
+ res_png = convert_pptx("presentation.pptx", format="png", slide=1, scale=2.0)
144
+ with open("slide_1.png", "wb") as f:
145
+ f.write(res_png["raw_bytes"])
146
+
147
+ # 3. Create a downloadable ZIP containing all rendered slides
148
+ zip_bytes = create_pptx_render_zip("presentation.pptx", format="png")
149
+ with open("presentation_pngs.zip", "wb") as f:
150
+ f.write(zip_bytes)
151
+ ```
152
+
153
+ ---
154
+
155
+ ## 2. CLI Usage
156
+
157
+ ```bash
158
+ # Basic extraction to terminal (stdout)
159
+ python main.py document.pdf
160
+
161
+ # Save raw JSON chunks to a file
162
+ python main.py report.docx --json -o output.json
163
+
164
+ # Process embedded images using a Vision Model
165
+ python main.py slides.pptx --process-images --model google-gemini-3-flash --json -o output.json
166
+
167
+ # Convert all PPTX slides to clean SVG files in a directory
168
+ python main.py slides.pptx --convert-pptx --format svg -o ./output_svgs
169
+
170
+ # Convert specific slide to PNG
171
+ python main.py slides.pptx --convert-pptx --format png --slide 1 -o slide_1.png
172
+
173
+ # Convert PPTX and package all slides into a ZIP archive
174
+ python main.py slides.pptx --convert-pptx --format png --as-zip -o slides.zip
175
+
176
+ # Start the REST API server
177
+ python main.py --serve --port 8000
178
+ ```
179
+
180
+ | Flag | Short | Default | Description |
181
+ |---|---|---|---|
182
+ | `file` | | *None* | Path to document or image file |
183
+ | `--json` | | `False` | Output as raw JSON chunks or JSON slide array |
184
+ | `--output` | `-o` | `stdout` | Destination file path or directory for output |
185
+ | `--convert-pptx` | `-c` | `False` | Convert PPTX slides to SVG or PNG images |
186
+ | `--format` | `-f` | `svg` | Target conversion format (`svg` or `png`) |
187
+ | `--slide` | | *All* | Specific 1-based slide index to convert |
188
+ | `--scale` | | `2.0` | Resolution scale factor for PPTX rendering |
189
+ | `--as-zip` | | `False` | Bundle all converted slides into a single `.zip` file |
190
+ | `--process-images` | | `False` | Enable AI vision processing for images/tables |
191
+ | `--model` | `-m` | *None* | Vision model name (required if `--process-images` is set) |
192
+ | `--serve` | `-s` | `False` | Start the FastAPI HTTP microservice |
193
+ | `--port` | `-p` | `8000` | Server listening port |
194
+
195
+ ---
196
+
197
+ ## 3. REST API Microservice
198
+
199
+ Start the server with `python main.py --serve --port 8000` or via Docker.
200
+ - **Swagger Docs**: `http://localhost:8000/docs`
201
+ - **Health Check**: `http://localhost:8000/health`
202
+
203
+ ### 1. Document Parsing & Chunking: `POST /process`
204
+
205
+ Accepts **either** a file upload (`multipart/form-data`) **or** a local/volume file path (`application/json`). Providing both or neither returns an HTTP 400 error.
206
+
207
+ #### Option A: File Upload (Multipart Form)
208
+ ```bash
209
+ # Basic upload
210
+ curl -X POST "http://localhost:8000/process" \
211
+ -F "file=@/path/to/contract.pdf"
212
+
213
+ # With Vision LLM processing
214
+ curl -X POST "http://localhost:8000/process?process_images=true&model=google-gemini-3-flash" \
215
+ -F "file=@/path/to/presentation.pptx"
216
+ ```
217
+
218
+ #### Option B: Local File Path or Mounted Volume Path (JSON)
219
+ ```bash
220
+ # Running locally:
221
+ curl -X POST "http://localhost:8000/process" \
222
+ -H "Content-Type: application/json" \
223
+ -d '{"file_path": "./test_docs/report.pdf"}'
224
+
225
+ # Running in Docker:
226
+ curl -X POST "http://localhost:8000/process" \
227
+ -H "Content-Type: application/json" \
228
+ -d '{"file_path": "/data/report.pdf", "process_images": true, "model": "gpt-4o"}'
229
+ ```
230
+
231
+ ---
232
+
233
+ ### 2. PPTX to SVG / PNG Conversion: `POST /convert/pptx`
234
+
235
+ Renders PowerPoint slides into SVG or PNG images.
236
+
237
+ #### Stream Single Slide Directly as Image (`image/svg+xml` or `image/png`)
238
+ Ideal for embedding directly in `<img>` tags or displaying in browsers:
239
+ ```bash
240
+ # Get Slide 1 as direct SVG
241
+ curl -X POST "http://localhost:8000/convert/pptx?slide=1&format=svg" \
242
+ -F "file=@presentation.pptx" > slide_1.svg
243
+
244
+ # Get Slide 2 as direct high-res PNG
245
+ curl -X POST "http://localhost:8000/convert/pptx?slide=2&format=png&scale=2.0" \
246
+ -F "file=@presentation.pptx" > slide_2.png
247
+ ```
248
+
249
+ #### Download All Slides as a ZIP Archive
250
+ ```bash
251
+ curl -X POST "http://localhost:8000/convert/pptx?format=png&as_zip=true" \
252
+ -F "file=@presentation.pptx" -o presentation_slides.zip
253
+ ```
254
+
255
+ #### Convert Mounted Volume Path via JSON Body
256
+ ```bash
257
+ curl -X POST "http://localhost:8000/convert/pptx" \
258
+ -H "Content-Type: application/json" \
259
+ -d '{"file_path": "/data/presentation.pptx", "format": "svg"}'
260
+ ```
261
+
262
+ #### Python Client Example
263
+ ```python
264
+ import requests
265
+
266
+ url = "http://localhost:8000/convert/pptx"
267
+
268
+ # 1. Download Slide 1 directly as image
269
+ with open("pitch_deck.pptx", "rb") as f:
270
+ resp = requests.post(url, files={"file": f}, params={"slide": 1, "format": "png"})
271
+ with open("slide_1.png", "wb") as out:
272
+ out.write(resp.content)
273
+
274
+ # 2. Get all slides as JSON payload (contains SVGs or base64 PNGs)
275
+ with open("pitch_deck.pptx", "rb") as f:
276
+ resp = requests.post(url, files={"file": f}, params={"format": "svg", "response_type": "json"})
277
+ data = resp.json()
278
+ print(f"Rendered {data['total_slides']} slides.")
279
+ ```
280
+
281
+ ---
282
+
283
+ ### 3. Async Processing: `POST /process-async` & `GET /jobs/{job_id}`
284
+
285
+ For large files or heavy multimodal extraction, submit jobs asynchronously to prevent client gateway timeouts. No Redis required (backed by persistent `/data/jobs` storage).
286
+
287
+ #### 1. Submit Job (`POST /process-async`)
288
+ ```bash
289
+ curl -X POST "http://localhost:8000/process-async" \
290
+ -F "file=@large_document.pdf"
291
+ ```
292
+ ```json
293
+ {
294
+ "job_id": "e8d7a12b-34c5-4f67-8901-abcdef123456",
295
+ "filename": "large_document.pdf",
296
+ "status": "processing",
297
+ "poll_url": "/jobs/e8d7a12b-34c5-4f67-8901-abcdef123456"
298
+ }
299
+ ```
300
+
301
+ #### 2. Poll Status & Fetch Result (`GET /jobs/{job_id}`)
302
+ ```bash
303
+ curl "http://localhost:8000/jobs/e8d7a12b-34c5-4f67-8901-abcdef123456"
304
+ ```
305
+ - **In Progress**: `{"status": "processing", "progress": 0}`
306
+ - **Completed**: Returns the full JSON payload (`"status": "completed"`, `total_chunks`, `chunks`). The job file is automatically deleted from disk upon successful retrieval.
307
+
308
+ ---
309
+
310
+ ## 4. Docker Deployment
311
+
312
+ The container image includes all rendering dependencies (`libicu`, `ca-certificates`, etc.).
313
+
314
+ ### Run as an API Server
315
+ ```bash
316
+ # Port 8000 exposed, local ./data folder mounted to /data in container
317
+ docker run -d \
318
+ --name doc-processor \
319
+ -p 8000:8000 \
320
+ --env-file .env \
321
+ -v ${PWD}/data:/data \
322
+ super-document-processor:latest
323
+ ```
324
+
325
+ ### Run as One-Off CLI Tool & Save Output to Host
326
+ Files created inside Docker default to the container's isolated layer. To save the output JSON directly on your host machine, use either **Volume Mounting** or **Shell Redirection**:
327
+
328
+ ```bash
329
+ # Method 1: Mount folder and write with -o (appears in your host folder)
330
+ docker run --rm -v ${PWD}:/data super-document-processor:latest \
331
+ python main.py /data/report.pdf --json -o /data/output.json
332
+
333
+ # Method 2: Stream stdout directly to host file (works with docker run or docker exec)
334
+ docker run --rm -v ${PWD}:/data super-document-processor:latest \
335
+ python main.py /data/report.pdf --json > output.json
336
+
337
+ # Method 3: Run against an already active container
338
+ docker exec doc-processor python main.py /data/report.pdf --json > output.json
339
+ ```
340
+
341
+ ### Docker Compose
342
+ ```yaml
343
+ version: "3.8"
344
+
345
+ services:
346
+ doc-processor:
347
+ image: super-document-processor:latest
348
+ container_name: doc-processor
349
+ restart: unless-stopped
350
+ ports:
351
+ - "8000:8000"
352
+ env_file:
353
+ - .env
354
+ volumes:
355
+ - ./data:/data
356
+ ```
357
+
358
+ ```bash
359
+ docker compose up -d
360
+ ```
361
+
362
+ ---
363
+
364
+ ## Environment Variables
365
+
366
+ | Variable | Default | Description |
367
+ |---|---|---|
368
+ | `PORT` | `8000` | HTTP port when running in server mode |
369
+ | `OPENAI_API_KEY` | *None* | API key for Vision LLM extraction |
370
+ | `OPENAI_BASE_URL` | `https://api.openai.com/v1` | Custom gateway URL (LiteLLM, Ollama, Gemini, Groq, etc.) |
371
+
372
+ ---
373
+
374
+ ## License
375
+
376
+ [MIT License](LICENSE) © [Cinderfox](https://github.com/Cinderfox)