Skip to main content

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.

Tests

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

persian-1.1.0.tar.gz (73.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

persian-1.1.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

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

Hashes for persian-1.1.0.tar.gz
Algorithm Hash digest
SHA256 29c6f97040854239f1e09569d08e9b36bc1f2dbc78ae5184710dfad73fc032eb
MD5 bcc275ea654ee864e89cbe1f31b4b987
BLAKE2b-256 49c54f379cf8bbe8ff14d38e67871a15145967857f9188077fb56f1798f3046a

See more details on using hashes here.

Provenance

The following attestation bundles were made for persian-1.1.0.tar.gz:

Publisher: publish.yml on rezkam/persian

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for persian-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83a6f3b65b0d25e7ae083bdb51c873cdcb1876a25d31b688ab8c51e4b5892cc5
MD5 0b17404c11aec61bccbf94af8c7d78ee
BLAKE2b-256 988c91479432290e7facb2b8fb2caf5f8d678f4b4dc8c9d6439e0411222433ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for persian-1.1.0-py3-none-any.whl:

Publisher: publish.yml on rezkam/persian

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page