Convert any document, text, or URL into LLM-ready data format
Project description
LLM Data Converter
Convert any document, text, or URL into LLM-ready data format.
Installation
pip install llm-data-converter
Requirements:
- Python 3.8 or higher
System Dependencies for OCR
For OCR functionality to work properly, you may need to install additional system dependencies:
Ubuntu/Debian:
sudo apt update
sudo apt install -y libgl1-mesa-glx libglib2.0-0
macOS:
# Usually not needed, but if you encounter OpenGL issues:
brew install mesa
Note: The package will automatically detect if OpenGL is available and provide helpful warnings if system dependencies are missing.
Quick Start
from llm_converter import FileConverter
# Basic conversion
converter = FileConverter()
result = converter.convert("document.pdf").to_markdown()
print(result)
Features
- Multiple Input Formats: PDF, DOCX, TXT, HTML, URLs, Excel files, and more
- Multiple Output Formats: Markdown, HTML, JSON, Plain Text
- LLM Integration: Seamless integration with LiteLLM and other LLM libraries
- Local Processing: Process documents locally without external dependencies
- Layout Preservation: Maintain document structure and formatting
Usage Examples
Convert PDF to Markdown
from llm_converter import FileConverter
converter = FileConverter()
result = converter.convert("document.pdf").to_markdown()
print(result)
Convert URL to HTML
from llm_converter import FileConverter
converter = FileConverter()
result = converter.convert("https://example.com").to_html()
print(result)
Convert Excel to JSON
from llm_converter import FileConverter
converter = FileConverter()
result = converter.convert("data.xlsx").to_json()
print(result)
Chain with LLM
from llm_converter import FileConverter
from litellm import completion
converter = FileConverter()
document_content = converter.convert("report.pdf").to_markdown()
# Use with any LLM
response = completion(
model="openai/gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant that analyzes documents."},
{"role": "user", "content": f"Summarize this document:\n\n{document_content}"}
]
)
print(response.choices[0].message.content)
Supported Formats
Input Formats
- Documents: PDF, DOCX, TXT
- Web: URLs, HTML files
- Data: Excel (XLSX, XLS), CSV
- Images: PNG, JPG, JPEG (with OCR capabilities)
Output Formats
- Markdown: Clean, structured markdown
- HTML: Formatted HTML with styling
- JSON: Structured JSON data
- Plain Text: Simple text extraction
Advanced Usage
Custom Configuration
from llm_converter import FileConverter
converter = FileConverter()
result = converter.convert("document.pdf").to_markdown()
print(result)
Batch Processing
from llm_converter import FileConverter
converter = FileConverter()
files = ["doc1.pdf", "doc2.docx", "doc3.xlsx"]
results = []
for file in files:
result = converter.convert(file).to_markdown()
results.append(result)
API Reference
FileConverter
Main class for converting documents to LLM-ready formats.
Methods
convert(file_path: str) -> ConversionResult: Convert a file to internal formatconvert_url(url: str) -> ConversionResult: Convert a URL to internal formatconvert_text(text: str) -> ConversionResult: Convert plain text to internal format
ConversionResult
Result object with methods to export to different formats.
Methods
to_markdown() -> str: Export as markdownto_html() -> str: Export as HTMLto_json() -> dict: Export as JSONto_text() -> str: Export as plain text
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT License - see LICENSE file for details.
Third-Party Dependencies
This project uses several third-party libraries:
- PaddleOCR - Apache 2.0 License (https://github.com/PaddlePaddle/PaddleOCR)
- PyMuPDF - GNU Affero General Public License v3.0
- python-docx - MIT License
- pandas - BSD 3-Clause License
- Pillow - HPND License
All dependencies are used in accordance with their respective licenses.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_data_converter-0.4.0.tar.gz.
File metadata
- Download URL: llm_data_converter-0.4.0.tar.gz
- Upload date:
- Size: 41.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc36e61372db9cd63606b692bde8810b6220c87f8349aea6ea415a6e9478112a
|
|
| MD5 |
e7299a8f580cf21dc2378bc44419edd9
|
|
| BLAKE2b-256 |
03512f887a06f299a959561bbce75a9afcdf0eabc28049743946e5ff42348d7a
|
File details
Details for the file llm_data_converter-0.4.0-py3-none-any.whl.
File metadata
- Download URL: llm_data_converter-0.4.0-py3-none-any.whl
- Upload date:
- Size: 32.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c2330821f1533fc23a43b8fa1a481cc7ba8c5e308c9cd3268d34262eabeb910
|
|
| MD5 |
e83225af52f3f4715ceb33a706a096aa
|
|
| BLAKE2b-256 |
35eae447b963cbfc2cf142b696fffbcc774983724e041950f7d93d8351f15970
|