Skip to main content

postext for Python

Typeset books from Python with Postext: a print-ready PDF, HTML pages, an EPUB, page images or a Word document from a .postext book, a book folder or loose Markdown files.

pip install postext
import postext

report = postext.pdf("book.postext", out="book.pdf", set={"page.dpi": 300})
print(report.output.pages, "pages")
for warning in report.warnings:
    print(warning)            # warning missingFont (chapters/02.md:14): …

pdf = postext.pdf_bytes(open("book.postext", "rb").read())   # bytes in, bytes out

The package drives the self-contained postext command line, the same executable as brew install drnachio/postext/postext or npx postext-cli: the layout is the Sandbox's, and the same book breaks into the same pages. The wheel is pure Python with no dependencies. The executable of your system (185 to 230 MB, too large for a wheel) is downloaded on first use from the GitHub Release of the package's version, checked against the release's SHA256SUMS and kept in the cache:

System Executable
macOS, Apple silicon / Intel postext-macos-arm64 / postext-macos-x64
Linux x86-64 / ARM64 (glibc) postext-linux-x64 / postext-linux-arm64
Linux x86-64, musl (Alpine) postext-linux-x64-musl
Windows x64 (and ARM, emulated) postext-windows-x64.exe
Environment variable Effect
POSTEXT_BIN Run this executable instead (Homebrew, Scoop, a local build); nothing is downloaded
POSTEXT_CACHE_DIR Cache folder (default ~/.cache/postext, %LOCALAPPDATA%\postext\cache on Windows); executables go in bin/<version>/, downloaded fonts in fonts/
POSTEXT_RELEASE_URL Download from a mirror: a URL with {version} where the release's files are

python -m postext pdf book.postext -o book.pdf runs the command line itself.

Commands

Every command of the command line is a function. Each runs the command with --json and returns its report.

Function Command Returns
pdf(book, out=…, pdfx=…, profile=…, color_space=…) postext pdf Report
html(book, out=…, mode=…, assets=…) postext html Report
epub(book, out=…, layout=…, cover=…) postext epub Report
image(book, page="#1", out=…, dpi=…, format=…) postext image ImageReport
images(book, out="pages/", pages=…, pattern=…) postext images Report
docx(book, out=…, variant=…) postext docx Report
import_docx(docx, book=None, out=…, dry_run=…) postext import-docx ImportDocxReport
pack(book, out=…) / unpack(bundle, out=…) postext pack / unpack Report / UnpackReport
info(book, pages=True) postext info InfoReport
check(book, strict=True) postext check CheckReport
build(book, pdf=…, html=…, epub=…, images=…, docx=…) postext build Report

book is a path (a .postext file, a book folder, a Markdown file), a list of Markdown files (the chapters, in order), or the bytes of a .postext bundle. The commands that read a book take the book options:

postext.pdf(
    ["01.md", "02.md"],
    out="notes.pdf",
    name="Notes",                      # --name
    config={"page": {"sizePreset": "A5"}},   # --config (a dict or a file)
    set={"bodyText.fontSize.value": 11},     # --set, one per key
    locale="es",                       # --locale
    chapters=range(1, 3),              # --chapters 1-2 (also 3, "1,3-5", [1, 3])
    resources="img/", fonts="fonts/",  # --resources, --fonts
    font_dirs=["~/Fonts"],             # --font-dir
    offline=True,                      # --offline: never download fonts
)

Reports and warnings

A Report has ok, command, version, exit_code, pages, book (name, id, locale, chapters), outputs (Output: kind, path, size, pages), warnings (Diagnostic: kind, message, severity, at, page, data), timings and raw, the whole JSON object. InfoReport adds chapters, resources and fonts; CheckReport adds passed, error_count, warning_count, contrast, reflow and preflight.

Bytes out

out="-" (or postext.STDOUT) writes to stdout and returns the bytes in report.content; pdf_bytes, html_bytes, epub_bytes, image_bytes, docx_bytes and pack_bytes return them directly. A book given as bytes with no out comes back as bytes.

Errors

Exception When
PostextError The command failed (exit code 1); err.report and err.stderr say why
UsageError A wrong option or value (exit code 2)
ProblemsFound check found an error (any warning with strict), or import_docx could not apply an edit (exit code 3); raise_on_problems=False returns the report instead
BinaryNotFound No executable for this system, a failed download or checksum, or a POSTEXT_BIN that is not a file

One executable, many runs

postext.Postext(binary=None, cwd=None, env=None, timeout=None, offline=None, font_dirs=None) has the same methods with its own executable, folder, environment and timeout. Postext().run(["build", "book/", "--pdf", "b.pdf", "--watch"], capture=False) runs any command as typed.

Each call starts the executable again. A mode that keeps one engine running between calls is planned.

Docs

MIT licence.

Metadata

Release files for postext 1.70.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for postext 1.70.5
File Size Uploaded Provenance Actions
postext-1.70.5.tar.gz 22.6 kB With provenance Details for postext-1.70.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for postext 1.70.5
File Interpreter ABI Platform Actions
postext-1.70.5-py3-none-any.whl Python 3 none any Details for postext-1.70.5-py3-none-any.whl

Total release size: 43.8 kB

Release files / postext-1.70.5.tar.gz

Download URL postext-1.70.5.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a5c7aa6f3ac10d88767f68b65b8cc2033887136d538168b02f810015f51a1712
BLAKE2b-256 checksum
How to use checksums
9df5c928d77bf0d1b2b6db074cbb652a086af5f3c8b23cd427ada96dbf002196
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 6, 2026.

Transparency log

Release files / postext-1.70.5-py3-none-any.whl

Download URL postext-1.70.5-py3-none-any.whl
Size 21.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1836d5aaebeb6ff062310fe07a04d68c3c68f75144be2d70f4e639fce29e6a66
BLAKE2b-256 checksum
How to use checksums
f6c079c677a20ff9abc0111f384871efad281d2e80909091da159e53c0f54475
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 6, 2026.

Transparency log

Security for postext 1.70.5

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for postext-1.70.5.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 Nov 6, 2026.

Transparency log

A 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.

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