{"id":10131,"library":"pyrtf3","title":"PyRTF3","description":"PyRTF3 is a fork of the original PyRTF library, providing a Pythonic way to generate Rich Text Format (RTF) documents. It allows users to programmatically create complex RTF files including text, paragraphs, sections, tables, lists, and styling. The current version is 0.47.5, with releases occurring periodically to address issues and maintain compatibility.","status":"active","version":"0.47.5","language":"en","source_language":"en","source_url":"https://github.com/xoviat/pyrtf","tags":["rtf","document generation","text processing","rich text format"],"install":[{"cmd":"pip install pyrtf3","lang":"bash","label":"Install pyrtf3"}],"dependencies":[],"imports":[{"note":"The installed package is `pyrtf3`, but the top-level import namespace is `pyrtf`.","wrong":"from pyrtf3.document import Document","symbol":"Document","correct":"from pyrtf.document import Document"},{"symbol":"Section","correct":"from pyrtf.document import Section"},{"symbol":"Paragraph","correct":"from pyrtf.document import Paragraph"},{"symbol":"Text","correct":"from pyrtf.document import Text"},{"symbol":"Table","correct":"from pyrtf.document import Table"}],"quickstart":{"code":"import os\nfrom pyrtf.document import Document, Section, Paragraph, Text\n\ndef create_simple_rtf():\n    doc = Document()\n    section = Section()\n    doc.append(section)\n\n    section.append(Paragraph(Text('Hello, PyRTF3!')))\n    section.append(Paragraph(Text('This is a simple RTF document generated with Python.')))\n\n    output_filename = 'simple_pyrtf3_document.rtf'\n    with open(output_filename, 'wb') as f:\n        doc.write(f)\n\n    print(f\"RTF document '{output_filename}' created successfully.\")\n\nif __name__ == '__main__':\n    create_simple_rtf()","lang":"python","description":"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."},"warnings":[{"fix":"Always use `import pyrtf` or `from pyrtf.document import ...` for all imports after installing `pyrtf3`.","message":"The 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`.","severity":"gotcha","affected_versions":"All pyrtf3 versions (0.x.x)"},{"fix":"Review `pyrtf3` documentation and examples for updated import paths and class structures. Expect to refactor existing `pyrtf` code.","message":"If 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()`.","severity":"breaking","affected_versions":"Migration from original pyrtf to pyrtf3"},{"fix":"Ensure you open the output file in binary write mode: `with open('filename.rtf', 'wb') as f: doc.write(f)`.","message":"The `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.","severity":"gotcha","affected_versions":"All pyrtf3 versions (0.x.x)"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Change your import statements from `import pyrtf3` or `from pyrtf3 import ...` to `import pyrtf` or `from pyrtf.document import ...`.","cause":"You are trying to import using the PyPI package name (`pyrtf3`) instead of the actual top-level package name (`pyrtf`).","error":"ModuleNotFoundError: No module named 'pyrtf3'"},{"fix":"Use the `write()` method with an opened file object: `with open('output.rtf', 'wb') as f: doc.write(f)`.","cause":"You are looking for a convenience method like `save()`, but `pyrtf3` uses a `write()` method that expects a file object.","error":"AttributeError: 'Document' object has no attribute 'save'"},{"fix":"Provide a file-like object opened in binary write mode, e.g., `with open('my_document.rtf', 'wb') as f: doc.write(f)`.","cause":"You called `doc.write()` without providing the required file-like object, or you passed an incorrect argument type (e.g., a string path).","error":"TypeError: write() missing 1 required positional argument: 'file'"},{"fix":"Update your import statements to use the `pyrtf` package structure, e.g., `from pyrtf.document import Document` instead of `import PyRTF` or `from PyRTF import Document`.","cause":"You are attempting to use import paths from the very old, unmaintained `PyRTF` library, which `pyrtf3` is a fork of.","error":"ModuleNotFoundError: No module named 'PyRTF'"}]}