Skip to main content

refigure

Converters where figures survive.

CI Coverage License: Apache 2.0 Python 3.10+

DOCX / XLSX → Markdown converters that treat embedded charts, composite diagrams and infographics as single semantic objects instead of silently dropping or fragmenting them: native OOXML chart-data extraction (no rasterize/OCR/VLM) plus positioned machine-readable markers as the zero-loss floor, optional VLM interpretation (prose + mermaid) on top, cached and reproducible offline.

Demo

Optional VLM interpretation — for a figure with no native chart data at all (a screenshot, not an OOXML chart part) AND no matching mermaid construct either (a dense radial sunburst — nothing in the 4 original mermaid types could represent it), --vlm both recovers the real content and produces a genuinely renderable diagram, not just recovered text:

A real docx image (a dense wireless-technology sunburst chart with no native chart data) converted by refigure.docx.convert(use_vlm=True) into a rich VLM-generated description and a real rendered mermaid mindmap diagram, laid out radially instead of the unreadable flat strip a generic flowchart construct would have produced

Native chart-data extraction — real OOXML numCache, not a screenshot, not OCR:

A real xlsx bar chart converted by refigure.xlsx.convert() into Markdown, shown both as the raw text an LLM reads and as the same data re-rendered as a diagram

Same extraction, from DOCX — Word embeds native charts too, not just Excel; refigure reads the same cached OOXML data either way:

A real docx pie chart from an EU labour-platform survey converted by refigure.docx.convert() into Markdown, shown both as the raw text an LLM reads (mermaid fence + data table) and as the same data re-rendered as a diagram

Composite figures — positioned, zero-loss, even when the figure itself can't be rendered (no incumbent does this — see Docling issue #1287, open >1 year):

A real docx composite figure (a grouped diagram refigure.docx.convert() can't render) converted into a positioned zero-loss marker that keeps the figure's own caption/legend text

Quickstart

pip install "refigure[docx,xlsx]"
refigure report.docx                      # markdown to stdout
from refigure.docx import convert

result = convert("report.docx")
print(result.markdown)
print(f"{result.charts_found} charts, {result.groups_found} composite figures")

Optional VLM interpretation, for a composite figure the chart engine can't reconstruct on its own (see Features below):

pip install "refigure[docx,vlm]"
export OPENROUTER_API_KEY=...                 # or --vlm-api-key-file/--vlm-provider
refigure report.docx --vlm                    # needs the system soffice/LibreOffice binary too

Features

  • Native chart-data extraction — reads OOXML numCache/strCache directly; no rasterize/OCR/VLM step for charts, real numbers every time.
  • Positioned zero-loss markers for composite figures (DOCX) — grouped shapes/infographics that mammoth would otherwise silently fragment into disconnected pieces get a clean marker instead, with position and any caption text preserved. Absent even in well-funded incumbents — see Docling issue #1287.
  • Optional VLM interpretation (DOCX composite figures, [vlm] extra, --vlm/Config(use_vlm=True)) — cloud description + a real rendered mermaid diagram (26 supported diagram types — flowcharts, pie/xy charts, sequence/state/ER diagrams, Gantt/timeline/sankey/treemap and more, see Status below) on top of the zero-loss floor, for figures with no native chart data at all (e.g. a dashboard screenshot). Provider-agnostic — OpenRouter by default, or direct OpenAI/Ollama/vLLM/LM Studio/Anthropic via --vlm-provider ([vlm-direct] extra). --strict upgrades one specific failure (the system soffice/LibreOffice binary missing) from a graceful skip to a hard error; every other VLM failure still degrades.
  • Rich, typed resultConversionResult (markdown + warnings + chart/group counts + vlm_used), not a bare string.
  • CLI includedrefigure console command, stdin/stdout-first, native batch mode, typed exit codes (see below).

CLI

refigure installs a console command — a thin wrapper over the same convert() used programmatically, no separate logic:

refigure report.docx                      # markdown to stdout
refigure report.docx -o report.md         # markdown to a file
cat report.docx | refigure --format docx  # stdin, format hint required
refigure reports/ -o out/                 # batch: directory, walked recursively
refigure a.docx b.xlsx -o out/            # batch: 2+ explicit sources

Batch mode (2+ sources, or a single directory) requires -o DIR, keeps going past a failed source by default (--fail-fast aborts on the first one instead), and always prints a summary (N/M converted, K failed) to stderr. --json emits the full result — markdown plus chart/group counts and warnings — instead of plain markdown. -v/-q control verbosity; --strict is forwarded to the same Config.strict the Python API uses.

Exit codes:

Code Meaning
0 success
1 batch mode: 1+ sources failed (keep-going default)
2 usage error (bad arguments/flags)
3 input isn't a valid document of its format
4 input isn't a valid/safe archive
5 the format's extra ([docx]/[xlsx]) isn't installed
6 unexpected internal error

Real examples

Full convert() output on real, openly-licensed documents — not cherry-picked snippets. Each file's own header states its source, license and attribution.

Source Demonstrates Output
hackair-d7.7-pilot-evaluation.docx native chart extraction — 8 charts, 6 render as mermaid diagrams examples/hackair-native-charts.md
swd2018-254-marine-litter-ia-annex.docx combo: 1 chart (table-only — real verify+fallback in action, not every chart maps to mermaid) + 2 composite-figure zero-loss markers examples/swd2018-combo.md
govtech-2025-charts.xlsx XLSX at scale — 55 charts, 33 render as mermaid diagrams examples/govtech-xlsx-charts.md
swd2021-396-platform-work-ia.docx native pie chart — real EU-survey labels, all 8 charts render (3 as mermaid) examples/swd2021-pie-chart.md
efsa-trichinella-dashboard-guide.docx --vlm interpretation — 27 figures with no native chart data, real numbers recovered from screenshots examples/efsa-trichinella-vlm.md

Open any of these on GitHub and both views are right there: the raw ```mermaid fence an LLM/RAG pipeline would read, and its native GitHub rendering — no extra step, that's GitHub's own Markdown support.

Status

Published on PyPI as refigure. Tested against 27 real documents (15 DOCX + 12 XLSX) — 407 native charts found (400 rendered), 35 composite figures recovered as positioned zero-loss markers — see tests/integration/fixtures/manifest.yaml for provenance, licenses and attribution. CI gates on a combined unit+integration test-coverage floor of 95%.

The converters were extracted from a working document-analysis pipeline (government AI-policy corpus) into a single package with per-format extras ([docx] / [xlsx]). VLM interpretation of composite figures the chart engine can't reconstruct ([vlm] extra, Config(use_vlm=True), provider-agnostic — direct OpenAI/Anthropic via [vlm-direct], also needs the system soffice/LibreOffice binary, not installable via pip) is fully implemented, tested, and exposed through the refigure CLI (--vlm and friends — see CLI above and Quickstart). Mermaid-diagram recognition on top of that varies by diagram type and by what's actually on the source figure — common types (flowcharts, pie/xy charts) are picked reliably; more specialized ones depend on the figure carrying an unambiguous visual cue, and not every figure produces a diagram at all — a plain text description is a valid, honest fallback when it doesn't.

PDF is out of scope, on purpose — a boundary, not a gap. PDF has no equivalent of OOXML's cached chart data (numCache/strCache) for any mainstream chart generator, so the native, rasterize-free extraction this project is built on doesn't transfer to it — confirmed by research into PDF's own structure and how leading PDF converters handle charts today, not assumed. For mixed-format corpora, route by extension instead of expecting one tool to cover everything — Docling or MarkItDown for PDF, refigure for DOCX/XLSX where the chart data actually survives in the file:

import refigure.docx
import refigure.xlsx

if path.suffix == ".pdf":
    markdown = docling_convert(path)      # or any PDF-capable converter
elif path.suffix == ".docx":
    markdown = refigure.docx.convert(path).markdown
else:
    markdown = refigure.xlsx.convert(path).markdown

v0.1.0 published via trusted publishing (GitHub↔PyPI, no stored tokens). refigure-md is a reserved alternate name, not an active release.

License

Apache-2.0 — see LICENSE and NOTICE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

refigure-0.2.0.tar.gz (149.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

refigure-0.2.0-py3-none-any.whl (87.3 kB view details)

Uploaded Python 3

File details

Details for the file refigure-0.2.0.tar.gz.

File metadata

  • Download URL: refigure-0.2.0.tar.gz
  • Upload date:
  • Size: 149.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for refigure-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8efdb64bc43224125ba081a5e4a7f4a7c2c614de14b853a5b5eadfa8c4310700
MD5 4dab5a5411d89cf5c1d81a5c22aa6270
BLAKE2b-256 b9862c27b884a512e1cdc1157feda6679935e804fceaacb73f3f61c7af3a1050

See more details on using hashes here.

Provenance

The following attestation bundles were made for refigure-0.2.0.tar.gz:

Publisher: publish.yml on HelgDemidov/refigure

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file refigure-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: refigure-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 87.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for refigure-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 34850dfd71807a632cc18f60d8655947d946e4b763f23a05187d41594e2ffa2d
MD5 06ea0848b07ec84380c722796e7d3bbf
BLAKE2b-256 1bd6bc17af522a241aebb10395712f021f07881eded36ac70c5f16fc411d105d

See more details on using hashes here.

Provenance

The following attestation bundles were made for refigure-0.2.0-py3-none-any.whl:

Publisher: publish.yml on HelgDemidov/refigure

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

This release

0.2.0 This release

2 files

0.1.0

2 files

0.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page