Browse documentation
DocsAPI module

lokit.export & document.export

Write a parsed or streaming document to a supported output format through a module function or a document-bound method.

01

Two equivalent synchronous forms

Every parsed BaseStructure and StreamingStructure has an export proxy. The proxy is the concise form when a document is already in hand; lokit.export is useful when the function itself is being passed around or imported. They call the same synchronous writers.

export.py
import lokit
document = lokit.parse.tmx("memory.tmx", target_language="fr")
# Module form: document is the first argument.lokit.export.xliff(document, "messages.fr.xliff")
# Bound form: the document is already attached.document.export.xliff("messages.fr.xliff")
02

Export surface by format

OutputModule functionDocument methodImportant arguments
CSVlokit.export.csv(document, path)document.export.csv(path)Header style, column names, included fields, column order
XLSXlokit.export.xlsx(document, path)document.export.xlsx(path)Same tabular controls as CSV
TMXlokit.export.tmx(document, path)document.export.tmx(path)
XLIFFlokit.export.xliff(document, path)document.export.xliff(path)group_by_resource
PO / POTlokit.export.po(document, path)document.export.po(path)Canonical Gettext output
JSON i18nlokit.export.json_i18n(document, path)document.export.json_i18n(path)nested; json is an alias
.lokitlokit.export.lokit(document, path)document.export.lokit(path)
HTMLlokit.export.html(document, path)document.export.html(path)Optional source_html
IDMLlokit.export.idml(document, path, source_idml)document.export.idml(path, source_idml)Original IDML package is required
DOCXlokit.export.docx(document, path)document.export.docx(path)Optional source_docx, target_locale
PPTXlokit.export.pptx(document, path)document.export.pptx(path)Optional source_pptx, target_locale
03

Bound exports and streaming documents

document.export is synchronous and is available on both document types. Most writers can consume a StreamingStructure once without first building a document-sized dictionary. Exporting consumes that stream, so do not attempt a second pass over it. IDML is the exception: its story replacement needs a BaseStructure, and the bound helper materializes a streaming input before writing.

stream_export.py
import lokit
stream = lokit.stream.tmx("large-memory.tmx")stream.export.lokit("large-memory.lokit")
# The one-shot stream has now been consumed.
04

Asynchronous exports

Await the functions under lokit.export.async_; there is no asynchronous method on document.export. TMX, XLIFF, HTML, .lokit, DOCX, and PPTX accept materialized or streaming documents. The async CSV, XLSX, PO, JSON, JSON i18n, and IDML functions require a BaseStructure. Function names do not gain an _async suffix inside this namespace.

async_export.py
import lokit

async def write_catalog() -> None:    document = lokit.parse.tmx("memory.tmx", target_language="fr")    await lokit.export.async_.xliff(        document,        "messages.fr.xliff",        group_by_resource=True,    )
05

Control CSV and XLSX output

CSV and XLSX share the full synchronous tabular options. header_style="locale" uses the document locales as source and target headings; generic writes conventional field names. Use column_order to arrange any enabled id, source, target, status, and comment columns. The compact async CSV and XLSX functions currently accept only the document and output path.

export_xlsx.py
document.export.xlsx(    "review.fr.xlsx",    header_style="locale",    include_comment=False,    column_order=("id", "source", "target", "status"),)
06

Formats that can use an original file

HTML can either create a minimal document or apply translations to source_html. IDML always needs the original package. DOCX and PPTX accept an optional original path or bytes plus target_locale; pass the source explicitly when producing a translated Office deliverable. For a uniform original-to-localized-file workflow across formats, use the separate regeneration API.

source_backed_export.py
document.export.html(    "site/index.fr.html",    source_html="site/index.html",)document.export.docx(    "contract.fr.docx",    source_docx="contract.docx",    target_locale="fr-FR",)
07

Writer aliases and return values

lokit.write.<format>() and lokit.parse.write.<format>() expose the same synchronous writer implementations as lokit.export.<format>(). These public convenience wrappers return None; a successful return means the output was written. Use the lower-level lokit.office API when an Office workflow needs its structured OfficeExportResult rather than the standard convenience contract.