Skip to main content

Professional Iran System encoding library with Persian/English support

Project description

Iran System Encoding 🇮🇷

PyPI version License: MIT Python Versions

A high-performance, professional Python library for the legacy Iran System character encoding. This package provides symmetrical encoding and decoding with automatic locale detection, smart number handling, and an exact port of the original C logic.


🚀 Key Features

  • ✅ Bidirectional Conversion: Seamlessly convert between Unicode and Iran System encoding.
  • ✅ Pure Python Core: Zero external dependencies. We removed arabic_reshaper and python-bidi to provide a faster and more stable internal implementation.
  • ✅ C Extension Support: Includes a high-performance C source for optional compilation, delivering maximum speed.
  • ✅ Intelligent Locale Detection:
    • Context-Aware: Automatically detects if the text is Persian (fa) or English (en).
    • Smart Numbers: Automatically converts digits to Iran System format in Persian contexts, and keeps them as ASCII in English contexts.
  • ✅ Precise Visual Ordering: Implements the exact rule-based reshaping and visual layout logic from original legacy C systems.
  • ✅ Command-Line Interface (CLI): A built-in tool for quick terminal-based operations.

📦 Installation

pip install iran-encoding

🛠 Usage Guide

Python API

import iran_encoding

# 1. Encoding (Unicode -> Iran System)
# Automatically handles reshaping and visual ordering
text = "سلام دنیا 123"
encoded = iran_encoding.encode(text)
print(encoded.hex())

# 2. Decoding (Iran System -> Unicode)
decoded = iran_encoding.decode(encoded)
print(decoded) # Output: "سلام دنیا ۱۲۳"

# 3. Smart Locale Detection
# Persian letters trigger the 'fa' locale
print(iran_encoding.detect_locale("Hello سلام")) # 'fa'

# If only English text and numbers are present, it uses 'en'
# and converts Persian digits to ASCII if necessary.
print(iran_encoding.detect_locale("Hello ۱۲۳")) # 'en'

Command-Line Interface

The library includes a CLI tool named iran-encoding:

# Encode text to hex
iran-encoding encode "سلام دنیا"

# Decode Iran System hex to Unicode
iran-encoding decode-hex "a8 f3 91 f4"

# Decode raw byte string literal
iran-encoding decode "b'\xa8\xf3\x91\xf4'"

⚙️ Technical Overview

Unlike modern Unicode, Iran System is a visual encoding. This means the specific byte code for a letter depends on its shape (initial, medial, final, or isolated).

This library utilizes a verified port of legacy C algorithms to:

  1. Reshape characters based on surrounding context.
  2. Order the visual layout for right-to-left display.
  3. Handle Alphanumeric sequences correctly within bi-directional text.

Our implementation ensures 100% compatibility with legacy databases and hardware terminals.


🧪 Testing & Quality

We prioritize reliability. Our test suite covers 100% of the core conversion logic:

python3 -m pytest tests/

📄 License & Support

Contributions are welcome! Please feel free to open an issue or submit a pull request on our GitHub repository.

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

iran_encoding-1.1.2.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

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

iran_encoding-1.1.2-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file iran_encoding-1.1.2.tar.gz.

File metadata

  • Download URL: iran_encoding-1.1.2.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for iran_encoding-1.1.2.tar.gz
Algorithm Hash digest
SHA256 d968eb5ebda2f042d88393f3f245b985253f67f3ee6c6e876a4bd0d829134c23
MD5 b121416a0eddb4777f0cc7785189272e
BLAKE2b-256 d71e713d09ab1db3e666e99dad373b4ced924bdb739f8667300acc8e3821c357

See more details on using hashes here.

File details

Details for the file iran_encoding-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: iran_encoding-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for iran_encoding-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4208ccbec1fdd26283e915d9b70dca64d576e774b43879fab96a9cda430a9f96
MD5 7f3e8170b48dd078909603a8553e6a41
BLAKE2b-256 3b4790f9824f5ac74c080afaad72de56b24ec7b688b7c31114084e6b80b5b2e3

See more details on using hashes here.

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