Skip to main content

تبدیل اعداد به حروف فارسی

Project description

📦 Persian Number To Words

تبدیل اعداد به حروف فارسی و انگلیسی به صورت حرفه‌ای، مالی و قابل استفاده در پروژه‌های واقعی.


✨ امکانات

  • ✅ پشتیبانی از int، float و str
  • ✅ پشتیبانی از اعداد فارسی و انگلیسی
  • ✅ تبدیل به حروف فارسی 🇮🇷
  • ✅ تبدیل به حروف انگلیسی 🇬🇧
  • ✅ حالت مالی (تومان / ریال / دلار / سنت)
  • ✅ خروجی ساختاریافته (Dataclass)
  • ✅ جدا کردن عدد با کاما
  • ✅ پشتیبانی از CLI (خط فرمان)
  • ✅ Type Hints کامل
  • ✅ تست‌پذیر و توسعه‌پذیر

📥 نصب

نصب از PyPI

pip install persian-number-to-words

نصب در حالت توسعه (لوکال)

git clone https://github.com/p7deli/persian-number-to-words.git
cd persian-number-to-words
pip install -e .

🚀 استفاده سریع

from persian_number_to_words import number_to_words

result = number_to_words(123456)

print(result.formatted)
# 123,456

print(result.words)
# صد و بیست و سه هزار و چهارصد و پنجاه و شش

📌 ساختار خروجی

تابع number_to_words یک شیء از نوع NumberResult برمی‌گرداند:

NumberResult(
    formatted="123,456",
    words="صد و بیست و سه هزار و چهارصد و پنجاه و شش",
    language="fa",
    currency=None
)

دسترسی به مقادیر

result.formatted
result.words
result.language
result.currency

تبدیل به دیکشنری (مناسب API)

result.to_dict()

🔢 انواع ورودی

پکیج از انواع مختلف ورودی پشتیبانی می‌کند:

عدد صحیح

number_to_words(1000)

عدد اعشاری

number_to_words(1234.56)

رشته عددی انگلیسی

number_to_words("123456")
number_to_words("1,234,567")

رشته عددی فارسی

number_to_words("۱۲۳۴۵۶")

سیستم به صورت خودکار:

  • کاما را حذف می‌کند
  • اعداد فارسی را تبدیل می‌کند
  • مقدار را نرمال‌سازی می‌کند

🌍 انتخاب زبان

فارسی (پیش‌فرض)

number_to_words(123456, lang="fa")

انگلیسی

number_to_words(123456, lang="en")

خروجی:

one hundred twenty three thousand four hundred fifty six

💰 استفاده از واحد پول

number_to_words(5000, currency="تومان")

خروجی:

پنج هزار تومان

🧾 حالت مالی (Financial Mode)

مناسب برای سیستم‌های حسابداری، فروشگاهی و صدور فاکتور.

number_to_words(
    12500.75,
    currency="تومان",
    mode="financial"
)

خروجی:

12,500.75
دوازده هزار و پانصد تومان و هفتاد و پنج ریال

در حالت انگلیسی:

number_to_words(
    12500.75,
    lang="en",
    currency="dollars",
    mode="financial"
)

خروجی:

twelve thousand five hundred dollars and seventy five cents

➖ اعداد منفی

number_to_words(-2500)

خروجی:

منفی دو هزار و پانصد

🖥 استفاده در خط فرمان (CLI)

پس از نصب پکیج:

pnum 123456

مثال با پارامترها:

pnum 12500.75 --currency تومان --mode financial

پارامترهای قابل استفاده

گزینه توضیح
--lang انتخاب زبان (fa یا en)
--currency تعیین واحد پول
--mode حالت normal یا financial

📦 استفاده در پروژه Django

price = number_to_words(150000, currency="تومان")
label.setText(price.words)

🌐 استفاده در FastAPI

from fastapi import FastAPI
from persian_number_to_words import number_to_words

app = FastAPI()

@app.get("/convert/{number}")
def convert(number: str):
    result = number_to_words(number)
    return result.to_dict()

🌸 استفاده در پروژه‌های دسکتاپ (PyQt / Tkinter)

result = number_to_words(45000)
label.setText(result.words)

🧠 نکات مهم

  • برای اعداد بسیار بزرگ، می‌توان scale جدید به constants.py اضافه کرد.
  • خروجی همیشه یک شیء ساختاریافته است.
  • برای API از متد to_dict() استفاده کنید.
  • پکیج با Type Hint کامل نوشته شده است.

🧪 اجرای تست‌ها

pytest

👨‍💻 پیشنهادات

  • برای پروژه‌های مالی همیشه از حالت financial استفاده کنید.
  • برای API خروجی را با to_dict() ارسال کنید.
  • CLI برای تبدیل سریع در خط فرمان مناسب است.

📜 لایسنس

MIT


نویسنده

Poriya Delavariyan

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_number_to_word-1.0.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

persian_number_to_word-1.0.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file persian_number_to_word-1.0.0.tar.gz.

File metadata

  • Download URL: persian_number_to_word-1.0.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for persian_number_to_word-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e514b4057adc9b7752c6124899a43140180148ecd785d1fd335820d124a99934
MD5 c276431ec036de8a74eb7947b3b64d46
BLAKE2b-256 0c937f3ca826a7de2924e4f1b98f9381472f89e1a601ff4973182ead7f5d220b

See more details on using hashes here.

File details

Details for the file persian_number_to_word-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for persian_number_to_word-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 980d13eeebd69be89c6d74d2af64e3b9ff57f09652cab859093d68f501355967
MD5 8d3dae04ee75a7c3e0d8fe08f6719833
BLAKE2b-256 4dbde431888c62405a70712d04100f53eee4695e3da7093ea160d0cccb01a07f

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