Fast, typed Python library for Persian language localization
Project description
Persian
A fast Python toolkit for Persian (Farsi) text normalization, number/character conversion, and localization utilities.
Installation
pip install persian
Quick Start
import persian
persian.convert_ar_characters("علي") # 'علی'
persian.convert_fa_numbers("۱۳۷۱") # '1371'
persian.convert_en_numbers("345") # '۳۴۵'
persian.convert_en_characters("sghl") # 'سلام'
persian.convert_fa_spaces("آمده ای") # 'آمدهای'
persian.decode_url("https://.../%D8%B5%D9%81%D8%AD%D9%87") # 'https://.../صفحه'
Need a one-stop helper? Use normalize_persian("سلام ٣٤٥ می آیم")
to get سلام ۳۴۵ میآیم.
Performance
Version 1.0.0 includes major speedups:
- 3–5× faster number and keyboard conversions via
str.translate - 2–3× faster spacing fixes using pre-compiled regular expressions
- ~50% lower memory usage on large strings thanks to fewer temporary objects
See docs/PERFORMANCE.md for benchmark methodology and charts.
Type Safety & Tooling
The package ships with native type hints (py.typed) and strict type checking.
Static analyzers know the exact return type of every function:
from persian import convert_en_numbers
result: str = convert_en_numbers("123") # ✔️ type checker is satisfied
Error Handling
All public functions validate inputs and raise clear exceptions:
import persian
persian.convert_en_numbers(None) # ValueError: input_str cannot be None
persian.convert_en_numbers(123) # TypeError: input_str must be str, got int
Empty strings are accepted and return empty strings.
API Overview
| Category | Functions |
|---|---|
| Numbers | convert_en_numbers, convert_fa_numbers, convert_ar_numbers |
| Characters | convert_en_characters, convert_ar_characters, remove_arabic_diacritics |
| Spacing & URLs | convert_fa_spaces, decode_url |
| Utilities | normalize_persian, contains_persian_digits, contains_arabic_digits, is_persian_text |
A detailed description is available in docs/API.md.
Deprecated Functions
CamelCase helpers remain available but emit DeprecationWarning:
enToPersianNumb()→convert_en_numbers()enToPersianChar()→convert_en_characters()arToPersianNumb()→convert_ar_numbers()arToPersianChar()→convert_ar_characters()
Documentation
Contributors
Contributing
See docs/CONTRIBUTING.md for setup instructions and code style rules.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file persian-1.1.0.tar.gz.
File metadata
- Download URL: persian-1.1.0.tar.gz
- Upload date:
- Size: 73.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29c6f97040854239f1e09569d08e9b36bc1f2dbc78ae5184710dfad73fc032eb
|
|
| MD5 |
bcc275ea654ee864e89cbe1f31b4b987
|
|
| BLAKE2b-256 |
49c54f379cf8bbe8ff14d38e67871a15145967857f9188077fb56f1798f3046a
|
Provenance
The following attestation bundles were made for persian-1.1.0.tar.gz:
Publisher:
publish.yml on rezkam/persian
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
persian-1.1.0.tar.gz -
Subject digest:
29c6f97040854239f1e09569d08e9b36bc1f2dbc78ae5184710dfad73fc032eb - Sigstore transparency entry: 821274527
- Sigstore integration time:
-
Permalink:
rezkam/persian@708e407749d288348ecf02364cf00d52d96adaf8 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/rezkam
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@708e407749d288348ecf02364cf00d52d96adaf8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file persian-1.1.0-py3-none-any.whl.
File metadata
- Download URL: persian-1.1.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83a6f3b65b0d25e7ae083bdb51c873cdcb1876a25d31b688ab8c51e4b5892cc5
|
|
| MD5 |
0b17404c11aec61bccbf94af8c7d78ee
|
|
| BLAKE2b-256 |
988c91479432290e7facb2b8fb2caf5f8d678f4b4dc8c9d6439e0411222433ff
|
Provenance
The following attestation bundles were made for persian-1.1.0-py3-none-any.whl:
Publisher:
publish.yml on rezkam/persian
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
persian-1.1.0-py3-none-any.whl -
Subject digest:
83a6f3b65b0d25e7ae083bdb51c873cdcb1876a25d31b688ab8c51e4b5892cc5 - Sigstore transparency entry: 821274530
- Sigstore integration time:
-
Permalink:
rezkam/persian@708e407749d288348ecf02364cf00d52d96adaf8 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/rezkam
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@708e407749d288348ecf02364cf00d52d96adaf8 -
Trigger Event:
push
-
Statement type: