{"id":9285,"library":"rtfunicode","title":"rtfunicode","description":"rtfunicode is a Python library (version 2.3) that provides an encoder for Unicode to RTF 1.5 command sequences. It allows for generating valid RTF output that includes international characters by registering a new `rtfunicode` codec, which can then be used directly with `str.encode()`. The library is actively maintained, with a focus on modern Python versions.","status":"active","version":"2.3","language":"en","source_language":"en","source_url":"https://github.com/mjpieters/rtfunicode","tags":["rtf","unicode","encoding","codec","python"],"install":[{"cmd":"pip install rtfunicode","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for execution, version >=3.10.","package":"python","optional":false}],"imports":[{"note":"Importing the rtfunicode module registers the 'rtfunicode' codec, making it available for string encoding.","symbol":"rtfunicode","correct":"import rtfunicode"}],"quickstart":{"code":"import rtfunicode\n\n# Encode a Unicode string to RTF using the 'rtfunicode' codec\nunicode_string = 'Hello, RTF and unicode mix just fine! \\u263A'\nrtf_output = unicode_string.encode('rtfunicode')\n\nprint(f\"Original Unicode: {unicode_string}\")\nprint(f\"Encoded RTF: {rtf_output!r}\")\n\n# The output includes the \\uN? sequence for Unicode characters\n# For example, \\u263A (smiling face) becomes \\u9786? (N=9786 in signed 16-bit int)\nassert rtf_output == b'Hello, RTF and unicode mix just fine! \\\\u9786?'","lang":"python","description":"This quickstart demonstrates how to import `rtfunicode` to register its codec, and then use the `encode('rtfunicode')` method on a standard Python string to convert Unicode characters into their RTF 1.5 command sequences."},"warnings":[{"fix":"Upgrade Python to 3.10+ or install `pip install rtfunicode==2.2` for Python 3.9.","message":"rtfunicode version 2.3 dropped support for Python 3.9. Users on Python 3.9 must use `rtfunicode==2.2` or upgrade their Python environment.","severity":"breaking","affected_versions":">=2.3"},{"fix":"Ensure your Python environment is 3.10 or newer. If legacy Python is required, use `rtfunicode<2.1`.","message":"rtfunicode version 2.1 and later require Python 3.10 or newer. Earlier versions (pre-2.1) supported Python 3.3-3.9. Attempting to install or run v2.1+ on Python versions older than 3.10 will fail.","severity":"breaking","affected_versions":">=2.1"},{"fix":"Verify that custom tooling or internal module references are compatible with the package structure. The main usage (`import rtfunicode`) is unaffected.","message":"In version 2.1, rtfunicode was converted from a single module to a package. While the primary `import rtfunicode` remains functional, any tools or custom setups relying on `rtfunicode.py` as a direct file or internal module paths might require adjustments.","severity":"gotcha","affected_versions":">=2.1"},{"fix":"Be aware of the fixed placeholder. For specific fallback character requirements, inspect the RTF output and implement post-processing if necessary.","message":"The RTF standard uses `\\uN?` where `N` is a signed 16-bit integer and `?` is a placeholder for older RTF readers. rtfunicode consistently sets this placeholder to `'?'`. If strict compliance with specific RTF readers requires a different fallback character (e.g., `\\uN\\'` plus a hex value), post-processing might be needed.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Add `import rtfunicode` at the beginning of your script. Importing the module registers the codec.","cause":"The 'rtfunicode' codec is not registered. This occurs when the `rtfunicode` module has not been imported.","error":"LookupError: unknown encoding: rtfunicode"},{"fix":"Upgrade your Python environment to 3.10 or newer. Alternatively, install a compatible older version like `pip install rtfunicode==2.2` for Python 3.9.","cause":"Attempting to install `rtfunicode` version 2.1 or newer on a Python environment older than 3.10.","error":"ERROR: Package 'rtfunicode' requires Python '>=3.10' but the running Python is 3.9.x"},{"fix":"Ensure your Python environment is 3.10 or newer when using rtfunicode versions 2.1+. Upgrade Python if necessary.","cause":"rtfunicode versions 2.1+ utilize modern Python syntax (e.g., type annotations) compatible with Python 3.10+. Running these versions on older Python interpreters will result in syntax errors.","error":"SyntaxError: invalid syntax (when running code from rtfunicode)"}]}