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.
pip install arabic-reshaperVerified import paths — ran on the pinned version, not inferred.
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`.
Upgrade your Python environment to Python 3.x. If unable to upgrade, pin `arabic-reshaper<3.0.0`.
Install `arabic-reshaper` with the `[with-fonttools]` extra: `pip install --upgrade arabic-reshaper[with-fonttools]`.
After reshaping the text with `arabic-reshaper`, pass the output to a bidi algorithm library. Example: `from bidi.algorithm import get_display; bidi_text = get_display(reshaped_text)`.
When initializing `ArabicReshaper`, pass `configuration={'delete_harakat': False}`. For example: `reshaper = ArabicReshaper(configuration={'delete_harakat': False})`.Set `use_unshaped_instead_of_isolated=True` in your `ArabicReshaper` configuration: `reshaper = ArabicReshaper(configuration={'use_unshaped_instead_of_isolated': True})`.Install the module using pip: 'pip install arabic-reshaper'.
Use the correct function name: 'from arabic_reshaper import ArabicReshaper'.
Use the 'reshape' method of the 'ArabicReshaper' instance: 'reshaper.reshape(text)'.
Create an instance of 'ArabicReshaper' and use its 'reshape' method: 'reshaper = ArabicReshaper(); reshaper.reshape(text)'.
Ensure that the input to 'reshape' is a string: 'reshaper.reshape("your text")'.