Arabic Reshaper

3.0.0 · active · verified Thu Apr 09

Arabic Reshaper is a Python library designed to reconstruct Arabic sentences for use in applications that do not natively support Arabic script rendering. It handles the complex shaping rules of Arabic, converting disjointed characters into their correctly connected forms (initial, medial, final, isolated) and managing ligatures. The library is actively maintained, with its latest major release being v3.0.0, and typically releases updates as needed.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to perform basic Arabic text reshaping using the top-level `reshape` function, and then how to use the `ArabicReshaper` class for more granular control over the reshaping process, such as preserving diacritics (harakat). Note that for proper display in environments that don't support RTL, you might need to combine this with a bidirectional (bidi) algorithm library like `python-bidi`.

import arabic_reshaper

# Basic reshaping
text_to_be_reshaped = 'اللغة العربية رائعة'
reshaped_text = arabic_reshaper.reshape(text_to_be_reshaped)
print(f"Original: {text_to_be_reshaped}")
print(f"Reshaped: {reshaped_text}")

# Reshaping with custom configuration
from arabic_reshaper import ArabicReshaper

configuration = {
    'delete_harakat': False, # Keep diacritics
    'support_ligatures': True,
}
reshaper = ArabicReshaper(configuration=configuration)

text_with_harakat = 'الْعَرَبيَّةُ'
reshaped_text_custom = reshaper.reshape(text_with_harakat)
print(f"Original (with harakat): {text_with_harakat}")
print(f"Reshaped (custom): {reshaped_text_custom}")

view raw JSON →