{"id":1673,"library":"python-bidi","title":"Python Bidi","description":"Python Bidi is a library for handling bi-directional (BiDi) text layout, primarily for Right-to-Left (RTL) languages like Arabic and Hebrew. It offers two implementations: a pure Python algorithm and a more performant wrapper around the Rust `unicode-bidi` crate. Currently at version 0.6.7, it maintains an active development and release cadence.","status":"active","version":"0.6.7","language":"en","source_language":"en","source_url":"https://github.com/MeirKriheli/python-bidi","tags":["bidi","rtl","text processing","unicode","layout","i18n"],"install":[{"cmd":"pip install python-bidi","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"For versions 0.5.0 and later, this imports the newer, Rust-based implementation. The older 'bidi.algorithm' import is for the pure Python implementation and is used for backward compatibility or specific use cases (e.g., Buildozer, older Python versions).","wrong":"from bidi.algorithm import get_display","symbol":"get_display","correct":"from bidi import get_display"},{"note":"This explicitly imports the pure Python implementation of the algorithm. It is compatible with older versions and can be useful in environments where the Rust-based wheels might cause issues, or when needing the `upper_is_rtl` parameter (though it's ignored by the Rust impl).","symbol":"get_display (Python algo)","correct":"from bidi.algorithm import get_display"}],"quickstart":{"code":"from bidi import get_display\n\n# Example Hebrew text (read as: 'Shalom')\nHEBREW_TEXT = ''.join([\n    'ש', # Shin\n    'ל', # Lamed\n    'ו', # Vav\n    'ם'  # Final Mem\n])\n\ndisplayed_text = get_display(HEBREW_TEXT)\nprint(f\"Original: {HEBREW_TEXT}\")\nprint(f\"Displayed: {displayed_text}\")\n\n# Example with mixed LTR/RTL\nmixed_text = \"Hello שלום World\"\ndisplayed_mixed = get_display(mixed_text)\nprint(f\"Original: {mixed_text}\")\nprint(f\"Displayed: {displayed_mixed}\")","lang":"python","description":"This example demonstrates how to use `get_display` to correctly render BiDi text. The function takes a string and returns the layout for display."},"warnings":[{"fix":"Ensure your project uses Python 3.9+ and update import statements. If you require the Python implementation or the `upper_is_rtl` parameter, explicitly import `from bidi.algorithm import get_display` (note: `upper_is_rtl` is ignored by the Rust implementation).","message":"Version 0.5.0 introduced significant breaking changes, including dropping support for Python versions older than 3.9. The primary import path for `get_display` changed to `from bidi import get_display` (for the Rust-based implementation), and the `upper_is_rtl` parameter was removed from this new implementation.","severity":"breaking","affected_versions":"0.5.0 and later"},{"fix":"Upgrade to a newer PyPy version (e.g., PyPy3.9+) or use a CPython environment.","message":"Version 0.6.6 removed support for PyPy3.7 and PyPy3.8 due to an upgrade of the underlying `pyo3` library.","severity":"breaking","affected_versions":"0.6.6 and later"},{"fix":"Try forcing `pip` to install from source using `pip install --no-binary python-bidi python-bidi`. Alternatively, consider temporarily downgrading to an older pure-Python version (e.g., `python-bidi==0.4.2`) if source build issues persist.","message":"When building `python-bidi` for platforms like Android using tools like Buildozer, issues may arise due to incompatible pre-built binary wheels (`.so` files). This can lead to runtime errors.","severity":"gotcha","affected_versions":"All versions, especially with PyO3/Rust backend"},{"fix":"Ensure consistent `utf-8` encoding is used throughout your text processing pipeline, particularly when reading from files (`open(file, 'r', encoding='utf8')`) before passing text to `get_display`.","message":"When integrating `python-bidi` with other text processing libraries like `arabic-reshaper`, incorrect handling of string encoding (especially when reading from or writing to files) can lead to unexpected display issues or `AssertionError: LRI not allowed here`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Avoid using `upper_is_rtl` with the default `get_display` import. If you need its specific behavior (which is generally for debugging), you must explicitly import and use the pure Python implementation via `from bidi.algorithm import get_display`.","message":"The `upper_is_rtl` argument in `get_display` was a debugging feature specific to the pure Python implementation of the algorithm. It is ignored by the default Rust-based implementation (from `bidi import get_display`) in versions 0.5.0 and later.","severity":"deprecated","affected_versions":"0.5.0 and later"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}