Metadata-Version: 2.4
Name: llm-markdownify
Version: 0.1.0
Summary: Convert documents (PDF, DOCX) to high-quality Markdown using Vision LLMs via LiteLLM
Project-URL: Homepage, https://github.com/sethupavan12/Markdownify
Project-URL: Repository, https://github.com/sethupavan12/Markdownify
Project-URL: Issues, https://github.com/sethupavan12/Markdownify/issues
Author: Sethu Pavan Venkata Reddy Pastula
License: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Keywords: docx,litellm,llm,markdown,ocr,pdf,vision
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Text Processing :: Markup
Classifier: Topic :: Utilities
Requires-Python: >=3.10
Requires-Dist: litellm[proxy]>=1.43.0
Requires-Dist: pillow>=10.3.0
Requires-Dist: pydantic>=2.7.0
Requires-Dist: pypdfium2>=4.30.0
Requires-Dist: tqdm>=4.66.0
Requires-Dist: typer>=0.12.3
Provides-Extra: dev
Requires-Dist: pre-commit>=3.6.0; extra == 'dev'
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
Requires-Dist: pytest>=8.2.0; extra == 'dev'
Requires-Dist: ruff>=0.5.6; extra == 'dev'
Provides-Extra: docx
Requires-Dist: docx2pdf>=0.1.8; extra == 'docx'
Description-Content-Type: text/markdown

## Markdownify

Mardownify is a super easy-to-use PDF to high-quality Markdown converter using Vision LLMs. It supports text, images, signatures, tables, charts, flowcharts and preserves document structure (Headings, numbered lists etc).

Tables become Markdown tables, charts become Mermaid diagrams, and images get concise summaries. Use as a CLI or Python library. Works with 100+ LLMs. Recommended to use with `gpt-5-mini` or `gpt-4.1-mini` or even better models for better performance. 

### Features
- High-quality complex markdown generation powered by LLMs. 
- Supports Text, Images, Tables, Charts.
- Built-in prompts tuned for clean Markdown, Mermaid, and structured headings along with ability to customise.
- Supports multi-page tables, charts and images.
- High-fidelity page rendering from PDF.
- Optional DOCX→PDF conversion using MS word installation.
- Works seamlessly with 100+ LLMs with LiteLLM Intergration.

### Install
```bash
uv pip install llm-markdownify
# or
pip install llm-markdownify
```

### Quickstart (CLI)
```bash
markdownify run input.pdf -o output.md --model gpt-5-mini
```

### Python API (one-liner)
```python
from llm_markdownify import convert

convert(
    "input.pdf",
    "output.md",
    model="gpt-5-mini",   # optional; can rely on env/provider defaults
    dpi=72,
    profile="contracts",    # or path to JSON profile
)
```

Optional DOCX support (macOS/Windows via Word):
```bash
pip install llm-markdownify[docx]
```

### Configure your provider (via LiteLLM)
Pick one of the following. See the full providers list and details in the LiteLLM docs: [Supported Providers](https://docs.litellm.ai/docs/providers).

- **OpenAI**
  - Set your API key:
    ```bash
    export OPENAI_API_KEY="sk-..."
    ```
  - Example usage:
    ```bash
    markdownify run input.pdf -o output.md --model gpt-5-mini
    ```

- **Google Gemini**
  - Set your API key (Google AI Studio key):
    ```bash
    export GOOGLE_API_KEY="..."
    ```
  - Example usage (pick a Gemini vision-capable model):
    ```bash
    markdownify run input.pdf -o output.md --model gemini/gemini-2.5-flash
    ```

- **Azure OpenAI**
  - Set these environment variables (values from your Azure OpenAI resource):
    ```bash
    export AZURE_API_KEY="..."
    export AZURE_API_BASE="https://<your-resource>.openai.azure.com"
    export AZURE_API_VERSION=""
    ```
  - Use your deployment name via the `azure/<deployment_name>` model syntax:
    ```bash
    markdownify run input.pdf -o output.md --model azure/<deployment_name>
    ```
  - See: [LiteLLM Azure OpenAI](https://docs.litellm.ai/docs/providers/azure_openai)

- **OpenAI-compatible APIs**
  - Many providers expose an OpenAI-compatible REST API. Set your API key and base URL:
    ```bash
    export OPENAI_API_KEY="..."
    export OPENAI_API_BASE="https://your-openai-compatible-endpoint.com/v1"
    ```
  - Use the model name supported by that endpoint:
    ```bash
    markdownify run input.pdf -o output.md --model <model-name>
    ```
  - Reference: [LiteLLM Providers](https://docs.litellm.ai/docs/providers)

For additional providers and advanced configuration (fallbacks, cost tracking, streaming), see the LiteLLM docs: [Getting Started](https://docs.litellm.ai/).

### Configuration flags
- `--model`: LiteLLM model (e.g., `gpt-5-mini`, `azure/<deployment>`, `gemini/gemini-2.5-flash`)
- `--dpi`: Render DPI (default 72)
- `--max-group-pages`: Max pages to merge for continued content (default 3)
- `--no-grouping`: Disable LLM-based grouping
- `--temperature`, `--max-tokens`: LLM generation params

### Dev tooling
- Install pre-commit and enable the license header hook:
  ```bash
  pip install pre-commit
  pre-commit install
  # run on all files once
  pre-commit run --all-files
  ```
  This inserts the header:
  ```
  # Copyright (c) 2025 Sethu Pavan Venkata Reddy Pastula
  # Licensed under the Apache License, Version 2.0. See LICENSE file for details.
  # SPDX-License-Identifier: Apache-2.0
  ```

### Attribution & License
This project uses the Apache 2.0 License, which includes an attribution/NOTICE requirement. If you distribute or use this project, please keep the `LICENSE` and `NOTICE` files intact, crediting the original author, Sethu Pavan Venkata Reddy Pastula.

- Project repository: https://github.com/sethupavan12/Markdownify

### Development
- Requires Python 3.10+
- Use `uv` for fast installs: `uv sync`
- Run tests: `pytest`
- Lint: `ruff check src tests`

### Releasing
GitHub Actions are configured to:
- Run tests on PRs/pushes
- Build & publish to PyPI on tagged releases (requires `PYPI_API_TOKEN` secret)
