Registry / data / arabic-reshaper

arabic-reshaper

JSON →
library3.0.1pypypi✓ verified 24d ago

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-reshaper
INSTALL
IMPORT
SIG · ARABIC-RESHAPER
A
arabic-reshaper
datapythonv3.0.1
Install
2.1s avg
Import
65ms
Disk
40MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.068s · 39.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.1s · import 0.061s · 43MB
40MB installed
● package 40MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

reshape
import arabic_reshaper reshaped_text = arabic_reshaper.reshape('text')
ArabicReshaper
from arabic_reshaper import ArabicReshaper reshaper = ArabicReshaper(configuration={'support_ligatures': True}) reshaped_text = reshaper.reshape('text')
config_for_true_type_font
from arabic_reshaper import ArabicReshaper, config_for_true_type_font, ENABLE_ALL_LIGATURES reshaper = ArabicReshaper(config_for_true_type_font('/path/to/font.ttf', ENABLE_ALL_LIGATURES))
ArabicReshaper(configuration={'font_file': '/path/to/font.ttf'})
Font-based configuration requires the dedicated `config_for_true_type_font` function and the `[with-fonttools]` extra. It's not a direct setting in the `configuration` dict.

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}")
Debug
Known issues
breakingPython 2.x support has been completely dropped in version 3.0.0. Applications targeting Python 2 must use an older version (e.g., 2.x.x) or migrate to Python 3.
fix
Upgrade your Python environment to Python 3.x. If unable to upgrade, pin `arabic-reshaper<3.0.0`.
affects: >=3.0.0
gotchaUsing `config_for_true_type_font` requires the `fonttools` package to be installed as an extra dependency (`pip install arabic-reshaper[with-fonttools]`). Without it, attempting to use this function will result in an `ImportError` or `ModuleNotFoundError`.
fix
Install `arabic-reshaper` with the `[with-fonttools]` extra: `pip install --upgrade arabic-reshaper[with-fonttools]`.
affects: >=2.1.0
gotchaArabic Reshaper focuses solely on character shaping. For correct Right-to-Left (RTL) text display, especially when mixing Arabic and LTR languages, you will likely need to use a bidirectional (bidi) algorithm library (e.g., `python-bidi`) in conjunction with `arabic-reshaper`.
fix
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)`.
affects: All versions
gotchaBy default, `delete_harakat` is `True`, meaning diacritics (tashkeel) are removed from the text during reshaping. If you need to preserve harakat, you must explicitly set `delete_harakat=False` in your `ArabicReshaper` instance configuration.
fix
When initializing `ArabicReshaper`, pass `configuration={'delete_harakat': False}`. For example: `reshaper = ArabicReshaper(configuration={'delete_harakat': False})`.
affects: All versions
gotchaSome fonts may be missing the isolated forms for certain Arabic letters, leading to incorrect rendering even after reshaping. The `use_unshaped_instead_of_isolated` configuration option can mitigate this by forcing the use of unshaped forms instead.
fix
Set `use_unshaped_instead_of_isolated=True` in your `ArabicReshaper` configuration: `reshaper = ArabicReshaper(configuration={'use_unshaped_instead_of_isolated': True})`.
affects: >=2.0.14
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'arabic_reshaper'
The 'arabic_reshaper' module is not installed in the Python environment.
fix
Install the module using pip: 'pip install arabic-reshaper'.
ImportError: cannot import name 'reshape' from 'arabic_reshaper'
The function 'reshape' does not exist in the 'arabic_reshaper' module.
fix
Use the correct function name: 'from arabic_reshaper import ArabicReshaper'.
TypeError: 'ArabicReshaper' object is not callable
Attempting to call an instance of 'ArabicReshaper' directly as a function.
fix
Use the 'reshape' method of the 'ArabicReshaper' instance: 'reshaper.reshape(text)'.
AttributeError: module 'arabic_reshaper' has no attribute 'reshape'
The 'arabic_reshaper' module does not have a 'reshape' attribute.
fix
Create an instance of 'ArabicReshaper' and use its 'reshape' method: 'reshaper = ArabicReshaper(); reshaper.reshape(text)'.
ValueError: Input text must be a string
The input provided to the 'reshape' method is not a string.
fix
Ensure that the input to 'reshape' is a string: 'reshaper.reshape("your text")'.
Upgrade
Version history
3.0.1latest on PyPI · released Apr 28, 2026
Audit
Dependencies
fonttoolsoptionalRequired for generating configuration based on a TrueType font file, enabling automatic ligature and character form detection. It's an optional extra installation.
Agent activity
39 hits · last 30 days
node
32
OpenAI (training)
1
Resources
arabic-reshaper — pip install arabic-reshaper · libregistry