Python Bidi

0.6.7 · active · verified Thu Apr 09

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.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `get_display` to correctly render BiDi text. The function takes a string and returns the layout for display.

from bidi import get_display

# Example Hebrew text (read as: 'Shalom')
HEBREW_TEXT = ''.join([
    'ש', # Shin
    'ל', # Lamed
    'ו', # Vav
    'ם'  # Final Mem
])

displayed_text = get_display(HEBREW_TEXT)
print(f"Original: {HEBREW_TEXT}")
print(f"Displayed: {displayed_text}")

# Example with mixed LTR/RTL
mixed_text = "Hello שלום World"
displayed_mixed = get_display(mixed_text)
print(f"Original: {mixed_text}")
print(f"Displayed: {displayed_mixed}")

view raw JSON →