Install & Compatibility
Where this runs
tested against v0.47.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.1MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 1.7s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Document
✓ from PyRTF import Document
✗ from PyRTF import Document
This quickstart creates a basic RTF document with two paragraphs of text and saves it to a file named 'simple_pyrtf3_document.rtf'. It demonstrates the core Document, Section, Paragraph, and Text objects.
import os
from pyrtf.document import Document, Section, Paragraph, Text
def create_simple_rtf():
doc = Document()
section = Section()
doc.append(section)
section.append(Paragraph(Text('Hello, PyRTF3!')))
section.append(Paragraph(Text('This is a simple RTF document generated with Python.')))
output_filename = 'simple_pyrtf3_document.rtf'
with open(output_filename, 'wb') as f:
doc.write(f)
print(f"RTF document '{output_filename}' created successfully.")
if __name__ == '__main__':
create_simple_rtf()
Debug
Known issues
gotchaThe PyPI package name is `pyrtf3`, but the top-level Python package you import is `pyrtf`. Attempting to `import pyrtf3` or `from pyrtf3 import ...` will result in a `ModuleNotFoundError`.fixAlways use `import pyrtf` or `from pyrtf.document import ...` for all imports after installing `pyrtf3`.
affects: All pyrtf3 versions (0.x.x)
breakingIf migrating from the original `pyrtf` library (which is no longer maintained), import paths and some API structures have changed significantly. For example, `PyRTF.Document()` becomes `pyrtf.document.Document()`.fixReview `pyrtf3` documentation and examples for updated import paths and class structures. Expect to refactor existing `pyrtf` code.
affects: Migration from original pyrtf to pyrtf3
gotchaThe `Document.write()` method requires a binary file-like object (opened with 'wb'), not a string path. Passing a string path or a text file object will cause a `TypeError` or unexpected behavior.fixEnsure you open the output file in binary write mode: `with open('filename.rtf', 'wb') as f: doc.write(f)`. affects: All pyrtf3 versions (0.x.x)
Upgrade
Version history
0.47.5latest on PyPI · released May 19, 2017
Audit
Dependencies
No dependency data recorded yet.