num2fa


Namenum2fa JSON
Version 2.0.1 PyPI version JSON
download
home_page
SummaryA library to convert numbers (ints, floats, and other standard numerical types) into Persian numbers or words.
upload_time2023-12-31 05:20:27
maintainer
docs_urlNone
authorEmad Rad
requires_python>=3.6
licenseAGPLv3
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Num2Fa

[![PyPI releases](https://img.shields.io/pypi/v/num2fa?logo=python&logoColor=white)](https://pypi.python.org/pypi/num2fa)
[![MIT License](https://img.shields.io/github/license/codewithemad/num2fa.svg?style=flat-square)](https://opensource.org/license/agpl-v3/)

`num2fa` is a versatile solution that enables the conversion of numbers (integers, floats, decimals, fractions, or strings) into their corresponding number or word form in Persian.

This repo is built upon the foundation of [num2faword](https://github.com/5j9/num2fawords), and I would like to express my gratitude to the [original developer](https://github.com/5j9) for their contributions.

## Installation

```bash
pip install num2fa
```

That's it!

## Usage

You can use `numbers`, `words`, and `ordinal_words` to convert numbers to their respective Persian forms, whether that be in numeric, word, or ordinal form.

```python
>>> from num2fa import numbers, words, ordinal_words
>>> numbers(1984)
'۱۹۸۴'
>>> numbers('1984')
'۱۹۸۴'
>>> numbers('1.1e-4')
>>> words(1984)
'یک هزار و نهصد و هشتاد و چهار'
>>> ordinal_words(1232)
'یک هزار و دویست و سی و دوم'
>>> ordinal_words(123)
'یکصد و بیست و سوم'
>>> words(1.1e-9)
'یک و یک دهم در ده به توان منفی نه'
```

`numbers` and `words` also accepts other common standard types:

```python

>>> from decimal import Decimal
>>> from fractions import Fraction

>>> numbers(Decimal('1.1'))
'۱٫۱'
>>> numbers(Fraction(-2, 5))
'-۲/۵'
>>> words(Decimal('1.1'))
'یک و یک دهم'
>>> words(Fraction(-2, 5))
'منفی دو پنجم'
>>> ordinal_words(123)
'یکصد و بیست و سوم'
```

## Customization

The default decimal separator for `numbers` is `٫` and for `words` is `و`. it can be changed to any other strings with `decimal_separator`:

```python
>>> numbers(19.75, decimal_separator='/')
'۱۹/۷۵'
>>> words(19.75, decimal_separator=' ممیز ')
'نوزده ممیز هفتاد و پنج صدم'
```

If you wanted to use different number characters for example `٦` instead of `۶`, you can just:

```python
from num2fa.constants import PERSIAN_DIGITS

PERSIAN_DIGITS.update({'6': '٦'})
numbers(19.66, decimal_separator='/')
'۱۹/٦٦'
```

Some people prefer, for example, "صد و هفتاد" over its other form "یکصد و هفتاد". This package uses the second form by default which is also used on official Iranian banknotes. But it can be changed:

```python
>>> from num2fa.constants import HUNDREDS
>>> words(170)
'یکصد و هفتاد'
>>> HUNDREDS[1] = 'صد'
>>> words(170)
'صد و هفتاد'
```

other customizations in `words`:

```python
>>> words(7, positive='مثبت ')
'مثبت هفت'
>>> words(-2, negative='منهای ')
'منهای دو'
>>> words('۱/۲')
'یک دوم'
>>> words('1/2', fraction_separator=' تقسیم بر ', ordinal_denominator=False)
'یک تقسیم بر دو'
>>> words(1.1e-9)
'یک و یک دهم در ده به توان منفی نه'
>>> words(1.1e-9, scientific_separator=' ضربدر ده به قوهٔ ')
'یک و یک دهم ضربدر ده به قوهٔ منفی نه'
```

`positive`, `negative`, `decimal_separator`, `fraction_separator` can be used in `numbers` too.

All above arguments can be used together. If you prefer to change the default argument values once and for all, use the `change_defaults_numbers` or `change_defaults_words` function:

```python
>>> from num2fa import change_numbers_defaults, change_words_defaults

>>> change_numbers_defaults(fraction_separator=' بر ', decimal_separator='.')
>>> numbers('1.89/23')
>>> '۱.۸۹ بر ۲۳'

>>> change_words_defaults(fraction_separator=' بخش بر ', ordinal_denominator=False)
>>> words('۱/۴')
'یک بخش بر چهار'
```

## Contributing

We welcome contributions! To learn how you can contribute, please check the [Contributing](https://github.com/codewithemad/num2fa/blob/master/docs/Contributing.md) document.

## License

This work is licensed under the terms of the [GNU Affero General Public License (AGPL)](https://github.com/codewithemad/num2fa/blob/master/LICENSE.txt).

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "num2fa",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "Emad Rad",
    "author_email": "codewithemad@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/4e/14/0cacea9bed4eaad513e695518d3db7becf2cb44720badc8d0414a2466e77/num2fa-2.0.1.tar.gz",
    "platform": null,
    "description": "# Num2Fa\n\n[![PyPI releases](https://img.shields.io/pypi/v/num2fa?logo=python&logoColor=white)](https://pypi.python.org/pypi/num2fa)\n[![MIT License](https://img.shields.io/github/license/codewithemad/num2fa.svg?style=flat-square)](https://opensource.org/license/agpl-v3/)\n\n`num2fa` is a versatile solution that enables the conversion of numbers (integers, floats, decimals, fractions, or strings) into their corresponding number or word form in Persian.\n\nThis repo is built upon the foundation of [num2faword](https://github.com/5j9/num2fawords), and I would like to express my gratitude to the [original developer](https://github.com/5j9) for their contributions.\n\n## Installation\n\n```bash\npip install num2fa\n```\n\nThat's it!\n\n## Usage\n\nYou can use `numbers`, `words`, and `ordinal_words` to convert numbers to their respective Persian forms, whether that be in numeric, word, or ordinal form.\n\n```python\n>>> from num2fa import numbers, words, ordinal_words\n>>> numbers(1984)\n'\u06f1\u06f9\u06f8\u06f4'\n>>> numbers('1984')\n'\u06f1\u06f9\u06f8\u06f4'\n>>> numbers('1.1e-4')\n>>> words(1984)\n'\u06cc\u06a9 \u0647\u0632\u0627\u0631 \u0648 \u0646\u0647\u0635\u062f \u0648 \u0647\u0634\u062a\u0627\u062f \u0648 \u0686\u0647\u0627\u0631'\n>>> ordinal_words(1232)\n'\u06cc\u06a9 \u0647\u0632\u0627\u0631 \u0648 \u062f\u0648\u06cc\u0633\u062a \u0648 \u0633\u06cc \u0648 \u062f\u0648\u0645'\n>>> ordinal_words(123)\n'\u06cc\u06a9\u0635\u062f \u0648 \u0628\u06cc\u0633\u062a \u0648 \u0633\u0648\u0645'\n>>> words(1.1e-9)\n'\u06cc\u06a9 \u0648 \u06cc\u06a9 \u062f\u0647\u0645 \u062f\u0631 \u062f\u0647 \u0628\u0647 \u062a\u0648\u0627\u0646 \u0645\u0646\u0641\u06cc \u0646\u0647'\n```\n\n`numbers` and `words` also accepts other common standard types:\n\n```python\n\n>>> from decimal import Decimal\n>>> from fractions import Fraction\n\n>>> numbers(Decimal('1.1'))\n'\u06f1\u066b\u06f1'\n>>> numbers(Fraction(-2, 5))\n'-\u06f2/\u06f5'\n>>> words(Decimal('1.1'))\n'\u06cc\u06a9 \u0648 \u06cc\u06a9 \u062f\u0647\u0645'\n>>> words(Fraction(-2, 5))\n'\u0645\u0646\u0641\u06cc \u062f\u0648 \u067e\u0646\u062c\u0645'\n>>> ordinal_words(123)\n'\u06cc\u06a9\u0635\u062f \u0648 \u0628\u06cc\u0633\u062a \u0648 \u0633\u0648\u0645'\n```\n\n## Customization\n\nThe default decimal separator for `numbers` is `\u066b` and for `words` is `\u0648`. it can be changed to any other strings with `decimal_separator`:\n\n```python\n>>> numbers(19.75, decimal_separator='/')\n'\u06f1\u06f9/\u06f7\u06f5'\n>>> words(19.75, decimal_separator=' \u0645\u0645\u06cc\u0632 ')\n'\u0646\u0648\u0632\u062f\u0647 \u0645\u0645\u06cc\u0632 \u0647\u0641\u062a\u0627\u062f \u0648 \u067e\u0646\u062c \u0635\u062f\u0645'\n```\n\nIf you wanted to use different number characters for example `\u0666` instead of `\u06f6`, you can just:\n\n```python\nfrom num2fa.constants import PERSIAN_DIGITS\n\nPERSIAN_DIGITS.update({'6': '\u0666'})\nnumbers(19.66, decimal_separator='/')\n'\u06f1\u06f9/\u0666\u0666'\n```\n\nSome people prefer, for example, \"\u0635\u062f \u0648 \u0647\u0641\u062a\u0627\u062f\" over its other form \"\u06cc\u06a9\u0635\u062f \u0648 \u0647\u0641\u062a\u0627\u062f\". This package uses the second form by default which is also used on official Iranian banknotes. But it can be changed:\n\n```python\n>>> from num2fa.constants import HUNDREDS\n>>> words(170)\n'\u06cc\u06a9\u0635\u062f \u0648 \u0647\u0641\u062a\u0627\u062f'\n>>> HUNDREDS[1] = '\u0635\u062f'\n>>> words(170)\n'\u0635\u062f \u0648 \u0647\u0641\u062a\u0627\u062f'\n```\n\nother customizations in `words`:\n\n```python\n>>> words(7, positive='\u0645\u062b\u0628\u062a ')\n'\u0645\u062b\u0628\u062a \u0647\u0641\u062a'\n>>> words(-2, negative='\u0645\u0646\u0647\u0627\u06cc ')\n'\u0645\u0646\u0647\u0627\u06cc \u062f\u0648'\n>>> words('\u06f1/\u06f2')\n'\u06cc\u06a9 \u062f\u0648\u0645'\n>>> words('1/2', fraction_separator=' \u062a\u0642\u0633\u06cc\u0645 \u0628\u0631 ', ordinal_denominator=False)\n'\u06cc\u06a9 \u062a\u0642\u0633\u06cc\u0645 \u0628\u0631 \u062f\u0648'\n>>> words(1.1e-9)\n'\u06cc\u06a9 \u0648 \u06cc\u06a9 \u062f\u0647\u0645 \u062f\u0631 \u062f\u0647 \u0628\u0647 \u062a\u0648\u0627\u0646 \u0645\u0646\u0641\u06cc \u0646\u0647'\n>>> words(1.1e-9, scientific_separator=' \u0636\u0631\u0628\u062f\u0631 \u062f\u0647 \u0628\u0647 \u0642\u0648\u0647\u0654 ')\n'\u06cc\u06a9 \u0648 \u06cc\u06a9 \u062f\u0647\u0645 \u0636\u0631\u0628\u062f\u0631 \u062f\u0647 \u0628\u0647 \u0642\u0648\u0647\u0654 \u0645\u0646\u0641\u06cc \u0646\u0647'\n```\n\n`positive`, `negative`, `decimal_separator`, `fraction_separator` can be used in `numbers` too.\n\nAll above arguments can be used together. If you prefer to change the default argument values once and for all, use the `change_defaults_numbers` or `change_defaults_words` function:\n\n```python\n>>> from num2fa import change_numbers_defaults, change_words_defaults\n\n>>> change_numbers_defaults(fraction_separator=' \u0628\u0631 ', decimal_separator='.')\n>>> numbers('1.89/23')\n>>> '\u06f1.\u06f8\u06f9 \u0628\u0631 \u06f2\u06f3'\n\n>>> change_words_defaults(fraction_separator=' \u0628\u062e\u0634 \u0628\u0631 ', ordinal_denominator=False)\n>>> words('\u06f1/\u06f4')\n'\u06cc\u06a9 \u0628\u062e\u0634 \u0628\u0631 \u0686\u0647\u0627\u0631'\n```\n\n## Contributing\n\nWe welcome contributions! To learn how you can contribute, please check the [Contributing](https://github.com/codewithemad/num2fa/blob/master/docs/Contributing.md) document.\n\n## License\n\nThis work is licensed under the terms of the [GNU Affero General Public License (AGPL)](https://github.com/codewithemad/num2fa/blob/master/LICENSE.txt).\n",
    "bugtrack_url": null,
    "license": "AGPLv3",
    "summary": "A library to convert numbers (ints, floats, and other standard numerical types) into Persian numbers or words.",
    "version": "2.0.1",
    "project_urls": {
        "Code": "https://github.com/codewithemad/num2fa",
        "Issue tracker": "https://github.com/codewithemad/num2fa/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4e140cacea9bed4eaad513e695518d3db7becf2cb44720badc8d0414a2466e77",
                "md5": "0e6594350cf50b624bd1a38eb2cb6426",
                "sha256": "5fd1065d7df4bfb1c6c837abe09d39fd32860bf117c220b595ceba40fe2eaef3"
            },
            "downloads": -1,
            "filename": "num2fa-2.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "0e6594350cf50b624bd1a38eb2cb6426",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 25615,
            "upload_time": "2023-12-31T05:20:27",
            "upload_time_iso_8601": "2023-12-31T05:20:27.617178Z",
            "url": "https://files.pythonhosted.org/packages/4e/14/0cacea9bed4eaad513e695518d3db7becf2cb44720badc8d0414a2466e77/num2fa-2.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-31 05:20:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "codewithemad",
    "github_project": "num2fa",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "num2fa"
}
        
Elapsed time: 0.16480s