DOCX generation library with fluent API
Project description
DocMarQ
DOCX generation with a fluent API. Core is lean (just python-docx). Optional [md] extra adds markdown-to-DOCX rendering with banner headers, mermaid, GitHub callouts and more. Sibling library to pdfmarq with the same API shape and .docx output.
Philosophy
DocMarQ wraps python-docx (OOXML zip plumbing, content types, relationships) into a fluent paragraph/run API. You describe document flow; Word handles layout, pagination, and reflow on open.
- Fluent paragraph/run model:
doc.para("First.")opens a paragraph,doc.text(" with bold", bold=True)appends a styled run. Close withenter()or let the next block auto-open one. - One way per feature:
doc.table(),doc.image(),doc.bullet(),doc.link(), no overloaded call signatures - Markdown is optional: core → 1 dep (
python-docx),[md]addsmarkdown-it-py,mdit-py-plugins,PyYAML - Cross-library parity: API shape mirrors
pdfmarq, includingTableStyle,Styles,parse_color,rgb255, page sizes, andlang_style()for i18n. The same markdown source can target both PDF and DOCX. - Word-native output: opens cleanly in Word, LibreOffice, Google Docs. Templates
.dotx/.docxare respected, so themes and styles carry over.
Trade-offs:
- No cursor or coordinate control. Word owns layout. Great for content-driven documents, not for pixel-perfect grids (use
pdfmarqif you need that). - No math support. Word's equation editor is OOXML-native and out of scope. For math-heavy docs use
pdfmarqwith matplotlib. - Syntax highlighting in code blocks is not rendered yet. The
languageargument is accepted but ignored. - The dep tree is small but
python-docxis the only path to OOXML. If it can't express something (e.g. complex equation OMML), neither can DocMarQ. Drop todoc.docfor rawpython-docxaccess.
Install
pip install docmarq # core: python-docx
pip install docmarq[md] # + markdown rendering stack
Examples
from docmarq import DOCX
# Fluent core API
with DOCX("report.docx") as doc:
doc.font("Calibri", 20, "Bold").para("Quarterly Report")
doc.font(size=11, mode="Regular")
doc.para("Revenue up 23% year-over-year.")
doc.table(
[["Q1", "120k"], ["Q2", "148k"], ["Q3", "172k"]],
header=["Quarter", "Revenue"],
aligns=["C", "R"],
)
doc.image("chart.png", width=180, height=80)
doc.link("google.com", url="https://google.com")
from docmarq.md import md_to_docx, MarkdownStyle
# Markdown to DOCX
style = MarkdownStyle(
body_family="Calibri",
mono_family="Consolas",
line_height=1.4,
)
md_to_docx(open("doc.md").read(), "doc.docx", style=style)
See example.py for an end-to-end CLI script: language preset, Word-native fonts, link_root for cross-document references, and base_dir for relative images.
Markdown features
- GitHub-flavored markdown (tables, fenced code, lists, strikethrough)
- YAML frontmatter rendered as a page-1 banner (logo, status badge, version, sign block)
- Nested
render:block in frontmatter controls page geometry, fonts, banner toggles, locale (seemd-guide) - Built-in language presets (en|pl|de|fr|es|it|cs|sk) via
lang_style(): covers banner labels, callouts, date format - Skip-duplicate-title: drops
# Xwhen it matches frontmattertitle - Auto-slugged headings with clickable
[text](#anchor)internal links (unicode-aware) - Local-path links configurable via
link_root+link_base(or per-doc YAMLbase:) - Mermaid diagrams via
mermaid-cli(local) ormermaid.ink(network fallback), with a shared cache withpdfmarq - Footnotes, emoji shortcodes
:rocket:, nested lists, blockquotes, GitHub callouts (> [!NOTE],> [!WARNING], …) - Images with size caps for block and inline use (
works inline at x-height) - Headerless single-row tables for label/value cards
- Setext-heading-with-image recovery:
\n---renders as block image +<hr>instead of a thumbnail-sized setext h2
Not supported (use pdfmarq if you need them): math formulas, syntax highlighting in code blocks, deferred Page N/M totals (Word's page-numbering fields compute live).
Modules
| Module | Description | Docs |
|---|---|---|
docmarq |
Core DOCX API (fluent paragraph/run model) | docmarq/readme.md |
docmarq.md |
Markdown-to-DOCX renderer (optional [md] extra) |
docmarq/md/readme.md |
See also
Need PDF instead of .docx? Check PDFMarQ, the sibling library with the same API shape and PDF output. It adds math formulas, syntax highlighting, and pre-measured page breaks. Otherwise feature parity (banner, callouts, mermaid, lang presets).
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 docmarq-0.1.1.tar.gz.
File metadata
- Download URL: docmarq-0.1.1.tar.gz
- Upload date:
- Size: 57.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
219df0b5c40a5cb2f092e084c1f9c9d620975eee2d206817f26950f09a2799ca
|
|
| MD5 |
c8655fad44903ea0928ceed387aa3fc6
|
|
| BLAKE2b-256 |
2e14033de2cb9408e3290fa3cd0ffa0f2e5ff34c4dc1d42e26fb9aca5f1523a3
|
Provenance
The following attestation bundles were made for docmarq-0.1.1.tar.gz:
Publisher:
publish.yml on Xaeian/DocMarQ
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docmarq-0.1.1.tar.gz -
Subject digest:
219df0b5c40a5cb2f092e084c1f9c9d620975eee2d206817f26950f09a2799ca - Sigstore transparency entry: 1661744610
- Sigstore integration time:
-
Permalink:
Xaeian/DocMarQ@46194b8bfa93415c68cee08e51eec8f539adedb3 -
Branch / Tag:
refs/tags/0.1.1 - Owner: https://github.com/Xaeian
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@46194b8bfa93415c68cee08e51eec8f539adedb3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file docmarq-0.1.1-py3-none-any.whl.
File metadata
- Download URL: docmarq-0.1.1-py3-none-any.whl
- Upload date:
- Size: 63.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46f2145600f5e110f0e7d933cc1bd7874bd58648cf0a00cca45ebc566ac15ba2
|
|
| MD5 |
9367c1481914e0d34dbd0f90dd8f034d
|
|
| BLAKE2b-256 |
bbcb33aacfb93b5bc8cdddad1ad9655154ed26f979dc6c8a1335e3e8258b7f99
|
Provenance
The following attestation bundles were made for docmarq-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on Xaeian/DocMarQ
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docmarq-0.1.1-py3-none-any.whl -
Subject digest:
46f2145600f5e110f0e7d933cc1bd7874bd58648cf0a00cca45ebc566ac15ba2 - Sigstore transparency entry: 1661744776
- Sigstore integration time:
-
Permalink:
Xaeian/DocMarQ@46194b8bfa93415c68cee08e51eec8f539adedb3 -
Branch / Tag:
refs/tags/0.1.1 - Owner: https://github.com/Xaeian
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@46194b8bfa93415c68cee08e51eec8f539adedb3 -
Trigger Event:
release
-
Statement type: