ArabPy - Write Python in Arabic
A professional Python library that allows writing Python code completely in Arabic while maintaining full compatibility with standard Python.
Features
-
Comprehensive Translation Dictionary: 500+ entries covering:
- Python keywords (if, for, while, class, def, etc.)
- Built-in functions (print, len, range, etc.)
- Built-in exceptions (ValueError, TypeError, etc.)
- Standard library modules (os, sys, math, json, etc.)
- String, list, dict, set, and tuple methods
- Math, random, time, and datetime functions
- Regex, CSV, SQLite, and JSON helpers
- Async/await syntax
- Match/case syntax
- Magic methods (init, str, etc.)
- Decorators and context managers
- And much more!
-
Tokenizer-Based Translation: Preserves user-defined identifiers, strings, and comments
-
Bidirectional Translation: Convert Python ↔ Arabic
-
Unicode Support: Full support for Arabic identifiers
-
Easy to Extend: Simply add more translations to the dictionary
-
Production Quality: Clean, maintainable, well-tested code
Installation
pip install arabpy
Quick Start
Translating Python to Arabic
from arabpy import ArabPyTranslator
translator = ArabPyTranslator()
# Python code
python_code = """
def greet(name):
if name:
print(f"Hello, {name}!")
else:
print("Hello, World!")
for i in range(5):
greet(f"User {i}")
"""
# Translate to Arabic
arabic_code = translator.to_arabic(python_code)
print(arabic_code)
Output:
تعريف greet(name):
إذا name:
طباعة(f"Hello, {name}!")
وإلا:
طباعة("Hello, World!")
لكل i في مدى(5):
greet(f"User {i}")
Translating Arabic to Python
from arabpy import ArabPyTranslator
translator = ArabPyTranslator()
# Arabic code (with user-defined identifiers in Arabic)
arabic_code = """
تعريف جمع(أ، ب):
إرجاع أ + ب
نتيجة = جمع(10، 20)
طباعة(نتيجة)
"""
# Translate back to Python
python_code = translator.to_python(arabic_code)
print(python_code)
Output:
def sum(a, b):
return a + b
result = sum(10, 20)
print(result)
Executing Arabic Code
from arabpy import ArabPyTranslator
translator = ArabPyTranslator()
# Write and execute Arabic code
arabic_code = """
تعريف factorial(n):
إذا n <= 1:
إرجاع 1
وإلا:
إرجاع n * factorial(n - 1)
طباعة(factorial(5))
"""
# Translate and execute
namespace = translator.translate_and_execute(arabic_code, to_arabic=True)
Direct Arabic Code Execution
from arabpy import arabic_code_runner
code = """
تعريف factorial(n):
إذا n <= 1:
إرجاع 1
وإلا:
إرجاع n * factorial(n - 1)
طباعة(factorial(5))
"""
# Execute Arabic code directly
namespace = arabic_code_runner(code)
File Translation
from arabpy import ArabPyTranslator
translator = ArabPyTranslator()
# Translate Python file to Arabic
translator.translate_file('script.py', 'script_arabic.py', to_arabic=True)
# Translate Arabic file back to Python
translator.translate_file('script_arabic.py', 'script_restored.py', to_arabic=False)
Translation Statistics
from arabpy import ArabPyTranslator
translator = ArabPyTranslator()
stats = translator.get_translation_stats(python_code, to_arabic=True)
print(f"Total tokens: {stats['total_tokens']}")
print(f"Translated: {stats['translated_count']}")
print(f"Percentage: {stats['translation_percentage']:.1f}%")
What Gets Translated
The translator converts Python language constructs and standard library identifiers while preserving:
- User-defined variable names:
my_varstaysmy_var - User-defined function names:
my_functionstaysmy_function - User-defined class names:
MyClassstaysMyClass - String literals:
"Hello"stays"Hello" - Comments:
# commentstays# comment
What does get translated:
- Keywords:
if→إذا,for→لكل,def→تعريف - Built-in functions:
print→طباعة,len→طول - Standard library:
math.sqrt→جذر_تربيعي - Methods:
list.append→إضافة - Exceptions:
ValueError→خطأ_قيمة - Magic methods:
__init__→__تهيئة__ - And 500+ more entries!
Examples
Basic Python Constructs
# Python
if x > 0:
print("Positive")
elif x < 0:
print("Negative")
else:
print("Zero")
# Arabic (keywords translated, user identifiers preserved)
إذا x > 0:
طباعة("Positive")
وإلا_إذا x < 0:
طباعة("Negative")
وإلا:
طباعة("Zero")
Loops
# Python
for i in range(10):
print(i)
while condition:
do_something()
# Arabic (keywords translated, user identifiers preserved)
لكل i في مدى(10):
طباعة(i)
بينما condition:
do_something()
Functions and Classes
# Python
class Person:
def __init__(self, name):
self.name = name
def greet(self):
return f"Hello, {self.name}"
# Arabic (keywords and magic methods translated, user identifiers preserved)
فئة Person:
تعريف __تهيئة__(self, name):
self.name = name
تعريف greet(self):
إرجاع f"Hello, {self.name}"
List Operations
# Python
numbers = [1, 2, 3, 4, 5]
numbers.append(6)
numbers.sort()
total = sum(numbers)
# Arabic (methods translated, user identifiers preserved)
numbers = [1, 2, 3, 4, 5]
numbers.إضافة(6)
numbers.ترتيب()
total = مجموع(numbers)
Exception Handling
# Python
try:
result = risky_operation()
except ValueError as e:
print(f"Error: {e}")
finally:
cleanup()
# Arabic (keywords and exceptions translated, user identifiers preserved)
جرب:
result = risky_operation()
باستثناء خطأ_قيمة كـ e:
طباعة(f"Error: {e}")
أخيرا:
cleanup()
Async/Await
# Python
async def fetch_data():
data = await api_call()
return data
async with context:
await process()
# Arabic (keywords translated, user identifiers preserved)
غير_متزامن تعريف fetch_data():
data = انتظر api_call()
إرجاع data
غير_متزامن مع context:
انتظر process()
Match/Case (Python 3.10+)
# Python
match value:
case 1:
print("One")
case 2:
print("Two")
case _:
print("Other")
# Arabic (keywords translated, user identifiers preserved)
طابق value:
حالة 1:
طباعة("One")
حالة 2:
طباعة("Two")
حالة _:
طباعة("Other")
Extending the Dictionary
To add more translations, simply edit arabpy/dictionary.py:
ARABIC_TRANSLATIONS = {
# Add your custom translations here
"my_function": "دالتي",
"MyClass": "فئتي",
# ...
}
The reverse mapping is automatically generated.
How It Works
ArabPy uses Python's built-in tokenizer to:
- Parse source code into tokens
- Identify keywords, names, and operators
- Translate only language constructs and library identifiers
- Preserve user-defined identifiers, strings, and comments
- Reconstruct the translated code
This approach ensures accurate translation without breaking user code.
Requirements
- Python 3.8 or higher
- No external dependencies (uses only Python standard library)
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Areas for improvement:
- Add more translations to the dictionary
- Improve tokenizer accuracy
- Add more test cases
- Enhance documentation
- Support for more Python features
Acknowledgments
Built with the Python standard library's tokenizer module for accurate parsing and translation.
Support
- GitHub Issues: https://github.com/arabpy/arabpy/
- Documentation: https://arabpy-docs.vercel.app/
Metadata
Release files for arabpy 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| arabpy-1.0.1.tar.gz | 57.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| arabpy-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 113.4 kB
Release files / arabpy-1.0.1.tar.gz
| Download URL | arabpy-1.0.1.tar.gz |
|---|---|
| Size | 57.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8aef10f7f680d3ad8820ecd267b56fc550c1d27c681a05e6cd816f37724c12d7
|
|
BLAKE2b-256 checksum How to use checksums |
be6447c641947abdc19afadc4cc8f3115a0936e3cf3ed5e995edb903af3acece
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / arabpy-1.0.1-py3-none-any.whl
| Download URL | arabpy-1.0.1-py3-none-any.whl |
|---|---|
| Size | 55.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d456fef19fc01e00c63f0bf2becca7a9ce6ddad4ae60f90f4e3d10b27bb30ccd
|
|
BLAKE2b-256 checksum How to use checksums |
2ea9dafa7fe86525df25ad3bfce928720a17b0069b10bb026057f49a28dbbdbd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for arabpy 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.