Aspose.Words FOSS
A lightweight, open-source Python library for converting DOCX, DOC, RTF, TXT, and MD files to DOCX, Markdown, plain text, and PDF without requiring Microsoft Word.
A free, lightweight version of Aspose.Words for Python via .NET with a compatible API (Document, SaveFormat, SaveOptions).
Features
- DOCX Read/Write: Pure Python reader using only the standard library (
zipfile,xml.etree) - DOC Support: Word 97-2003 binary format reader via
olefile - RTF Support: Rich Text Format reader via OLE2 delegation
- Markdown Import:
.mdis parsed into the document model, not read as literal text — headings, bold/italic/strikethrough/inline code, ordered and nested lists, tables, block quotes, fenced code blocks, links, and base64-embedded images all become proper nodes, so Markdown converts to DOCX and PDF like any other input - Plain Text Input: Read
.txtfiles - File or Stream Input: DOCX, DOC and RTF are auto-detected from magic bytes (anything else falls back to plain text);
LoadOptions.load_formatoverrides the guess - Markdown Export: Rich formatting — headings, bold/italic/strikethrough/underline, ordered and unordered lists (including nested), tables, block quotes, code blocks, and hyperlinks. Encoding and paragraph break sequence are configurable
- PDF Export: Generate PDF output via
fpdf2. AppliedPdfSaveOptionsfields:compliance,image_compression,jpeg_quality,outline_options,export_document_structure,export_bookmarks_outline,zoom_behavior,zoom_factor,display_doc_title - Plain Text Export: Extract document text content
Installation
From PyPI:
pip install aspose-words-foss
Nightly (latest from GitHub):
pip install git+https://github.com/aspose-words-foss/Aspose.Words-FOSS-for-Python.git
Quick Start
Convert a document to Markdown
import aspose.words_foss as aw
doc = aw.Document("input.docx") # or .doc, .rtf, .txt, .md
doc.save("output.md", aw.SaveFormat.MARKDOWN)
Export to PDF
import aspose.words_foss as aw
doc = aw.Document("input.docx")
doc.save("output.pdf", aw.SaveFormat.PDF)
Export to DOCX
import aspose.words_foss as aw
doc = aw.Document("input.docx") # or .doc, .rtf
doc.save("output.docx", aw.SaveFormat.DOCX)
Extract plain text
import aspose.words_foss as aw
doc = aw.Document("input.docx")
text = doc.get_text()
Load from a stream
import io
import aspose.words_foss as aw
with io.FileIO("input.docx") as stream:
doc = aw.Document(stream) # DOCX / DOC / RTF from magic bytes
opts = aw.LoadOptions()
opts.load_format = aw.LoadFormat.MARKDOWN # needed for .md, which has no magic bytes
with io.FileIO("input.md") as stream:
doc = aw.Document(stream, opts)
Save with options
import aspose.words_foss as aw
from aspose.words_foss.saving import (
MarkdownSaveOptions,
OoxmlSaveOptions,
PdfSaveOptions,
CompressionLevel,
)
doc = aw.Document("input.docx")
# Markdown: underline, encoding, paragraph break
md_opts = MarkdownSaveOptions()
md_opts.export_underline_formatting = True
md_opts.encoding = "utf-8-sig" # write a UTF-8 BOM
md_opts.paragraph_break = "\r\n" # CRLF between paragraphs
doc.save("output.md", md_opts)
# DOCX: compression level
ooxml_opts = OoxmlSaveOptions()
ooxml_opts.compression_level = CompressionLevel.MAXIMUM
doc.save("output.docx", ooxml_opts)
pdf_opts = PdfSaveOptions()
doc.save("output.pdf", pdf_opts)
Requirements
- Python 3.10 or higher
- olefile >= 0.46
- fpdf2 >= 2.7.5
- pydantic >= 2.0.0
API Examples
Runnable examples demonstrating the aspose.words_foss API live in the ApiExamples/ folder.
The examples are written against the API both libraries share, so the same
sources run on aspose-words too — replacing aspose.words_foss with
aspose.words in the imports is the only edit needed.
Files
| File | What it shows |
|---|---|
convert_document.py |
Every input format (DOCX, DOC, RTF, TXT, MD) to every output format (Markdown, PDF, TXT) |
loading_document.py |
Loading documents from a file path and from a binary stream, with LoadOptions |
loading_markdown.py |
Reading Markdown from in-memory content |
working_with_markdown_save_options.py |
MarkdownSaveOptions — export_underline_formatting, encoding, paragraph_break |
working_with_ooxml_save_options.py |
OoxmlSaveOptions for DOCX export — pretty_format, compression_level, zip_64_mode |
working_with_pdf_save_options.py |
PDF export from all input formats |
working_with_txt_save_options.py |
Plain-text export and get_text() |
working_with_images.py |
Image-containing documents to all output formats |
Running
# Individual scripts
python ApiExamples/convert_document.py
# All via pytest
python -m pytest ApiExamples/ -v --rootdir=ApiExamples -c ApiExamples/pytest.ini
Input / Output
- Input:
tests/data/input/(shared test fixtures) - Output:
ApiExamples/output/(git-ignored)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- Issues: GitHub Issues
Release files for aspose-words-foss 26.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aspose_words_foss-26.7.0.tar.gz | 623.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aspose_words_foss-26.7.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 959.1 kB
Release files / aspose_words_foss-26.7.0.tar.gz
| Download URL | aspose_words_foss-26.7.0.tar.gz |
|---|---|
| Size | 623.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
def68f0e42cdf11da9c847bf9bf00210a73ee5caf756fbdbc00e03b403abbeb7
|
|
BLAKE2b-256 checksum How to use checksums |
bf6e137e2cad5c38815bb2c12ec887a20d94a359778d2ef183ee469b94c01280
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / aspose_words_foss-26.7.0-py3-none-any.whl
| Download URL | aspose_words_foss-26.7.0-py3-none-any.whl |
|---|---|
| Size | 335.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bca18c134f03e15d32c247d99ec6dee97c07e565e2c9d126a9c65f0e1b29b82f
|
|
BLAKE2b-256 checksum How to use checksums |
b7c1a301c5c95a573c7fd7a47c4e494ae40d411bd7fc7467e85d5a1120b17959
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|