MDify: Convert any document to Markdown
MDify is a powerful Python library for converting documents into clean, structured Markdown.
Unlike other tools, MDify can accurately extract tables, charts, and images, even offering the option to save them separately for further use.
This is particularly useful when working with documents like financial statements, spreadsheets, and data-rich reports, which usually have lots of tables and images.
MDify categorizes images into general pictures and charts and extracts tables of any kind, even complex ones with merged cells and sparse data.
Whether you're working with research papers, reports, or general documents, MDify ensures the data is extracted in a structured, clean, and machine-readable format, making it ideal for tasks like fine-tuning, question answering, and document analysis in the context of Large Language Models (LLMs).
By converting complex PDFs into well-structured Markdown, this tool helps streamline the input process for LLM applications, reducing the time spent on manual cleaning and formatting. With features like table extraction, image preservation, and high-quality OCR, MDify is a perfect fit for preparing large volumes of data for AI models.
IMPORTANT: Currently this tools only supports PDFs and images (such as text extracts, document scans, etc.) written in English.
🚀 Installation
First, install MDify via PyPI:
pip install mdify
⚡ Quickstart
Convert a document to Markdown with just a few lines of code:
from mdify import DocumentParser
parser = DocumentParser()
parser.parse('PATH_TO_YOUR_DOCUMENT')
Or parse multiple documents from one folder at once simply by changing the last line to:
parser.parse_directory('PATH_TO_YOUR_FOLDER')
Alternatively, you can also pass the document in bytes to the parse() method, but in this case you must also provide the document name and type manually:
with open('PATH_TO_YOUR_DOCUMENT', 'rb') as f:
document_bytes = f.read()
parser.parse(document_bytes, document_name='YOUR_DOCUMENT_NAME', document_type='pdf')
You can then choose the outputs to save using DocumentParser(save_artifacts=...), or you can set the write mode to embedded, placeholder or described by passing the write_mode parameter to the parse() function.
NB: To make the best use of this library and extract meaning from images, use the following code:
from mdify import WriteMode
parser.parse('PATH_TO_YOUR_DOCUMENT', write_mode=WriteMode.DESCRIBED)
🔹 Key Features
- ✔️ Handles complex layouts - Extracts text, tables, and visual elements with precision
- 🖼️ Preserves images & charts - Gives the option to save and reuse extracted visuals for Computer Vision tasks
- 🎯 Optimized for accuracy - Combines layout detection and OCR to extract text from documents
- 🤖 Preprocessing for LLM applications - Converts documents to Markdown, which is popular for LLM training and fine-tuning tasks
- 🛠️ Debug mode - Save intermediate document elements as images for analysis
NB:
- The first run will take ~2 minutes to download the necessary models.
- Diagrams are not supported yet, therefore if you use the
DESCRIBEDwrite mode they may be analyzed incorrectly.
📄 Documentation
For more information, please refer to the official documentation.
🤝 Contributing
MDify is an independent, open-source project developed and maintained by passionate developers. Your support is highly valued, and any contributions — whether through issues, bug reports, feature requests, or pull requests — are more than welcome!
If you are interested in improving this library or adding new features, please don't hesitate to get involved!
💖 Support
Being an independent developer, I would much appreciate it if you could
Thank you!
⚖️ License
This project is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License.
You can find the full text of the license here: CC BY-NC 4.0
❞ Citation
If you use this project, please download the citation from Zenodo (scroll all the way down and then choose the format you prefer (e.g. Bibtex) from the Export dropdown).
🔗 Acknowledgments
This project leverages several open-source repositories for different components:
- pypdfium2 – PDF loading
- Ultralytics – YOLO-based layout detection
- Supervision – Rendering layout elements
- Surya – Text recognition (primary OCR, though it's currently a bottleneck)
- EasyOCR – Recognizing text headers and titles (solves Surya's issue with them)
- PaddleOCR – Table recognition
- Optimum – Formula extraction model integration
- YOLOv10-Document-Layout-Analysis – YOLO model parameters
- ChartDet – Chart detection model parameters
- DePlot – Model for chart deconstruction
- BLIP Image Captioning – Image captioning model
- Pix2Text-MFR – Formula recognition model
A huge thanks to the developers and maintainers of these projects!
Metadata
Release files for mdify 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mdify-0.3.2.tar.gz | 23.9 kB | With provenance | Details for mdify-0.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mdify-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for mdify-0.3.2-py3-none-any.whl |
Total release size: 48.4 kB
Release files / mdify-0.3.2.tar.gz
| Download URL | mdify-0.3.2.tar.gz |
|---|---|
| Size | 23.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27770a6e359e19a5c8d6c219a534d09205688c16f76a468c12d524e234f7accf
|
|
BLAKE2b-256 checksum How to use checksums |
a99d2be5bc9f3b9988e260fa6fe2b1e6c693a123d53427b7b25dc68f12195205
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 24, 2025.
Transparency logRelease files / mdify-0.3.2-py3-none-any.whl
| Download URL | mdify-0.3.2-py3-none-any.whl |
|---|---|
| Size | 24.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e48d693ebdc85979dd79c00361e7b6fcee665132e2eb26a38ec7dd0294cca7f5
|
|
BLAKE2b-256 checksum How to use checksums |
74bc5847943fc70bd570db24cffd62b6415067f01c40813d9016cb840faf3a90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 24, 2025.
Transparency logSecurity for mdify 0.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for mdify-0.3.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 24, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.