llm-markdown-tools
Small, reusable Python utilities for turning HTML, documents, and images into clean Markdown using an OpenAI-compatible API.
Why this package exists
This package provides conversion to markdown from image, html and text. The user must provide an OpenAI compatible server.
- HTML to Markdown conversion
- image OCR / extraction into Markdown
- text and document conversion into Markdown
- retry and fallback handling for model failures
Installation
pip install llm-markdown-tools
Quick start
from llm_markdown_tools import MarkdownClientConfig, MarkdownExtractor
cfg = MarkdownClientConfig(
base_url="http://localhost:1234/v1",
api_key="not-needed",
model="qwen/qwen3.5-9b",
)
extractor = MarkdownExtractor(cfg)
markdown = extractor.from_html("<h1>Hello</h1><p>World</p>")
print(markdown)
Configuration
Prefer passing a MarkdownClientConfig object directly instead of loading local project files.
cfg = MarkdownClientConfig(
base_url="https://api.openai.com/v1",
api_key="YOUR_API_KEY",
model="gpt-4o-mini",
timeout=60.0,
)
Example YAML
llm:
endpoint: http://localhost:1234/v1
api_key: not-needed
model: qwen/qwen3.5-9b
timeout: 60
This package does not use a config file; use a template file or environment variables in your own application.
Public API
from llm_markdown_tools import MarkdownClientConfig, MarkdownExtractor
The extractor exposes methods such as:
from_html(html_text: str) -> strfrom_text(text: str) -> strfrom_image(image_base64: str, mime_type: str | None = None) -> strfrom_image_path(path: str | Path) -> strfrom_document_path(path: str | Path) -> str
from_html(...)
from llm_markdown_tools import MarkdownClientConfig, MarkdownExtractor
cfg = MarkdownClientConfig(
base_url="http://localhost:1234/v1",
api_key="not-needed",
model="qwen/qwen3.5-9b",
)
extractor = MarkdownExtractor(cfg)
html = "<html><body><h1>Quarterly Report</h1><p>Revenue grew 18%.</p></body></html>"
markdown = extractor.from_html(html)
print(markdown)
from_text(...)
from llm_markdown_tools import MarkdownClientConfig, MarkdownExtractor
cfg = MarkdownClientConfig(
base_url="http://localhost:1234/v1",
api_key="not-needed",
model="qwen/qwen3.5-9b",
)
extractor = MarkdownExtractor(cfg)
text = "Invoice 1234\nCustomer: Acme Corp\nTotal: $1,250.00"
markdown = extractor.from_text(text)
print(markdown)
from_image(...)
import base64
from llm_markdown_tools import MarkdownClientConfig, MarkdownExtractor
cfg = MarkdownClientConfig(
base_url="http://localhost:1234/v1",
api_key="not-needed",
model="qwen/qwen3.5-9b",
)
extractor = MarkdownExtractor(cfg)
with open("receipt.png", "rb") as fh:
image_bytes = fh.read()
image_b64 = base64.b64encode(image_bytes).decode("utf-8")
markdown = extractor.from_image(image_b64, mime_type="image/png")
print(markdown)
from_image_path(...)
from pathlib import Path
from llm_markdown_tools import MarkdownClientConfig, MarkdownExtractor
cfg = MarkdownClientConfig(
base_url="http://localhost:1234/v1",
api_key="not-needed",
model="qwen/qwen3.5-9b",
)
extractor = MarkdownExtractor(cfg)
markdown = extractor.from_image_path(Path("images/scan-01.png"))
print(markdown)
from_document_path(...)
from pathlib import Path
from llm_markdown_tools import MarkdownClientConfig, MarkdownExtractor
cfg = MarkdownClientConfig(
base_url="http://localhost:1234/v1",
api_key="not-needed",
model="qwen/qwen3.5-9b",
)
extractor = MarkdownExtractor(cfg)
markdown = extractor.from_document_path(Path("sample.pdf"))
print(markdown)
from_html_simple(...)
from llm_markdown_tools import MarkdownClientConfig, MarkdownExtractor
cfg = MarkdownClientConfig(
base_url="http://localhost:1234/v1",
api_key="not-needed",
model="qwen/qwen3.5-9b",
)
extractor = MarkdownExtractor(cfg)
html = "<h2>Notes</h2><p>Simple conversion fallback.</p>"
markdown = extractor.from_html_simple(html)
print(markdown)
from_html_with_fallback(...)
from llm_markdown_tools import MarkdownClientConfig, MarkdownExtractor
cfg = MarkdownClientConfig(
base_url="http://localhost:1234/v1",
api_key="not-needed",
model="qwen/qwen3.5-9b",
)
extractor = MarkdownExtractor(cfg)
html = "<div><h1>Fallback Example</h1><p>Try the LLM first, then fall back.</p></div>"
markdown = extractor.from_html_with_fallback(html, "email body conversion")
print(markdown)
License
MIT
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_markdown_tools-0.1.0.tar.gz.
File metadata
- Download URL: llm_markdown_tools-0.1.0.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fed78d1a12ea73b931300776f75c0c4d234052be99f824b769c5f70fb7dbbe8
|
|
| MD5 |
06a9187281db244f5019778255fe26bf
|
|
| BLAKE2b-256 |
fcea308d336daa5cca4cb8cc468d3e596505a365bbe126f3fc6a021cda64e0e3
|
File details
Details for the file llm_markdown_tools-0.1.0-py3-none-any.whl.
File metadata
- Download URL: llm_markdown_tools-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03a697c53a8cec61d595b865cd148110bb4fc94c7fca73324f64680cc99a2a4b
|
|
| MD5 |
1f364e1b868ad0ca8359246b568d8064
|
|
| BLAKE2b-256 |
a9023a35e018e79acff102bfd1faf38de2a60082a5e6c820e8a6470fcc0d3231
|