{"library":"rtfparse","title":"rtfparse: RTF Parser","description":"rtfparse is a Python library for parsing Microsoft Rich Text Format (RTF) documents. It constructs an in-memory object representing the RTF document's tree structure. The library currently provides a renderer (HTML_Decapsulator) to extract encapsulated HTML, particularly useful for processing HTML-formatted emails from Microsoft Outlook, which often use RTF compression. It aims to support custom renderers for diverse RTF processing needs. The library is actively maintained, with version 0.9.5 focusing on bug fixes and documentation, and future plans for version 1.x to include image embedding.","language":"python","status":"active","last_verified":"Sun May 17","install":{"commands":["pip install rtfparse"],"cli":null},"imports":["from rtfparse.parser import Rtf_Parser","from rtfparse.renderers.de_encapsulate_html import De_encapsulate_HTML"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import pathlib\nfrom rtfparse.parser import Rtf_Parser\nfrom rtfparse.renderers.de_encapsulate_html import De_encapsulate_HTML\nimport os\nimport tempfile\n\n# Create a dummy RTF file for demonstration\n# In a real scenario, you would read an existing RTF file.\nrtf_content = r\"{\\rtf1\\ansi\\deff0 This is some {\\b bold} text and a line break.\\par This is a new line.}\"\ntemp_rtf_file = pathlib.Path(tempfile.gettempdir()) / \"dummy_example.rtf\"\ntemp_html_file = pathlib.Path(tempfile.gettempdir()) / \"extracted_example.html\"\n\ntry:\n    # Write dummy RTF content to a temporary file\n    with open(temp_rtf_file, \"w\", encoding=\"ascii\") as f:\n        f.write(rtf_content)\n\n    print(f\"Created temporary RTF file: {temp_rtf_file}\")\n\n    # Programmatic usage: Parse the RTF file\n    parser = Rtf_Parser(rtf_path=temp_rtf_file)\n    parsed_document = parser.parse_file()\n\n    # Render the parsed RTF to extract HTML content\n    renderer = De_encapsulate_HTML()\n    with open(temp_html_file, mode=\"w\", encoding=\"utf-8\") as html_file:\n        renderer.render(parsed_document, html_file)\n\n    print(f\"RTF parsed and HTML extracted to: {temp_html_file}\")\n\n    # Display the extracted HTML content\n    with open(temp_html_file, \"r\", encoding=\"utf-8\") as f:\n        print(\"\\nExtracted HTML content:\")\n        print(f.read())\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    # Clean up temporary files\n    if temp_rtf_file.exists():\n        os.remove(temp_rtf_file)\n        print(f\"Cleaned up {temp_rtf_file}\")\n    if temp_html_file.exists():\n        os.remove(temp_html_file)\n        print(f\"Cleaned up {temp_html_file}\")","lang":"python","description":"This quickstart demonstrates how to programmatically parse an RTF string (written to a temporary file for demonstration) and then use the `De_encapsulate_HTML` renderer to extract any embedded HTML content, saving it to another temporary file. The extracted HTML is then printed to the console.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-17","installed_version":"0.7.8","pypi_latest":"0.9.5","is_stale":true,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":4.9,"avg_import_s":0.06,"wheel_type":"sdist"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"rtfparse","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.04,"mem_mb":2.2,"disk_size":"47.9M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"rtfparse","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":4.9,"import_time_s":0.03,"mem_mb":2.2,"disk_size":"48M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"rtfparse","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.08,"mem_mb":2.5,"disk_size":"53.1M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"rtfparse","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":4.5,"import_time_s":0.07,"mem_mb":2.5,"disk_size":"54M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"rtfparse","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.06,"mem_mb":2.2,"disk_size":"42.6M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"rtfparse","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":5.2,"import_time_s":0.06,"mem_mb":2.2,"disk_size":"43M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"rtfparse","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.05,"mem_mb":2.3,"disk_size":"42.3M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"rtfparse","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":4.8,"import_time_s":0.06,"mem_mb":2.1,"disk_size":"43M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"rtfparse","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.05,"mem_mb":2.7,"disk_size":"47.9M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"rtfparse","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":5.3,"import_time_s":0.05,"mem_mb":2.7,"disk_size":"48M"}]}}