{"id":28157075,"url":"https://github.com/opensource-nepal/py-nepali","last_synced_at":"2025-05-15T08:17:37.010Z","repository":{"id":43537153,"uuid":"152036890","full_name":"opensource-nepal/py-nepali","owner":"opensource-nepal","description":"py-nepali is a python package containing features that will be useful for Nepali projects.","archived":false,"fork":false,"pushed_at":"2025-04-04T12:16:36.000Z","size":386,"stargazers_count":26,"open_issues_count":2,"forks_count":14,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-05-04T17:16:28.678Z","etag":null,"topics":["ad-to-bs","bs-to-ad","django","kathmandu","nepal","nepali","nepali-date","nepali-date-converter","nepali-location","nepali-numbers","nepali-time","nepali-timezone","python","python3","timezone"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opensource-nepal.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-08T07:31:36.000Z","updated_at":"2025-04-21T16:14:53.000Z","dependencies_parsed_at":"2023-12-05T06:24:22.361Z","dependency_job_id":"21fb995c-a565-45db-9e2a-8c0561541c76","html_url":"https://github.com/opensource-nepal/py-nepali","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensource-nepal%2Fpy-nepali","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensource-nepal%2Fpy-nepali/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensource-nepal%2Fpy-nepali/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opensource-nepal%2Fpy-nepali/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opensource-nepal","download_url":"https://codeload.github.com/opensource-nepal/py-nepali/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254301583,"owners_count":22047907,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ad-to-bs","bs-to-ad","django","kathmandu","nepal","nepali","nepali-date","nepali-date-converter","nepali-location","nepali-numbers","nepali-time","nepali-timezone","python","python3","timezone"],"created_at":"2025-05-15T08:16:09.458Z","updated_at":"2025-05-15T08:17:36.993Z","avatar_url":"https://github.com/opensource-nepal.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nepali\n\n[![PyPI version](https://badge.fury.io/py/nepali.svg)](https://badge.fury.io/py/nepali)\n[![CI status](https://github.com/opensource-nepal/py-nepali/actions/workflows/python-package.yml/badge.svg?branch=main)](https://github.com/opensource-nepal/py-nepali/actions)\n[![Downloads](https://img.shields.io/pypi/dm/nepali.svg?maxAge=180)](https://pypi.org/project/nepali/)\n[![codecov](https://codecov.io/gh/opensource-nepal/py-nepali/branch/main/graph/badge.svg?token=PTUHYWCJ4I)](https://codecov.io/gh/opensource-nepal/py-nepali)\n\n`nepali` is a python package containing features that will be useful for Nepali projects.\n\nThe major feature of this package is nepalidatetime, which is compatible with python's datetime feature. It helps nepali date to english, parsing nepali datetime, nepali timezone, and timedelta support in nepali datetime.\n\n## Example\n\n```python\nimport datetime\nfrom nepali import phone_number\nfrom nepali.datetime import nepalidate, parser\n\nnepali_datetime = parser.parse('2079-02-15')\n# 2079-02-15 00:00:00\n\ndate = datetime.date(2017, 3, 15)\nnepali_date = nepalidate.from_date(date)\n# 2073-12-02\n\nphone_number.parse(\"+977-9845217789\")\n# {\n#     'type':      'Mobile',\n#     'number':    '9845217789',\n#     'operator':  \u003cOperator: Nepal Telecom\u003e\n# }\n```\n\n## Requirements\n\n    Python \u003e= 3\n\n## Installation\n\n    pip install nepali\n\n## Features\n\n1. [Date and Time](#date-and-time)\n   - [date_converter](#date_converter)\n   - [nepalidate](#nepalidate)\n   - [nepalidatetime](#nepalidatetime)\n   - [nepalihumanize](#nepalihumanize)\n   - [timezone](#timezone)\n   - [parse](#parse)\n   - [strftime() and strptime() Format Codes](#strftime-and-strptime-format-codes)\n1. [Numbers](#numbers)\n   - [nepalinumber](#nepalinumber)\n1. [Phone Number](#phone-number)\n1. [Locations](#locations)\n1. [For Django Template](#for-django-template)\n\n## Date and Time\n\n### date_converter\n\nDate converter module converts english date to nepali and nepali date to english. It doesn't contain any extra functionality.\n\n**Convert English date to Nepali date**\n\n```python\nfrom nepali.date_converter import converter\n\nnp_year, np_month, np_date = converter.english_to_nepali(en_year, en_month, en_date)\n```\n\nExample\n\n```python\nfrom nepali.date_converter import converter\n\nnp_year, np_month, np_date = converter.english_to_nepali(2023, 2, 7)\nprint(np_year, np_month, np_date) # 2079 10 24\n```\n\n**Convert Nepali date to English date**\n\n```python\nfrom nepali.date_converter import converter\n\nen_year, en_month, en_date = converter.nepali_to_english(np_year, np_month, np_date)\n```\n\nExample\n\n```python\nfrom nepali.date_converter import converter\n\nen_year, en_month, en_date = converter.nepali_to_english(2079, 10, 24)\nprint(en_year, en_month, en_date) # 2023 2 7\n```\n\n### nepalidate\n\n**Creating a new nepalidate object**\n\n```python\nfrom nepali.datetime import nepalidate\n\n# nepalidate object with year, month, day\nnp_date = nepalidate(year, month, day)\n\n# nepalidate object with today's date\nnp_date = nepalidate.today()\n\n# parse nepali date\nnp_date = nepalidate.strptime('2078-01-18', format='%Y-%m-%d')\n```\n\n**Getting nepalidate object from python datetime**\n\n```python\n# from date object\nnp_date = nepalidate.from_date(date_obj)\n\n# from datetime object\nnp_date = nepalidate.from_datetime(datetime_obj)\n```\n\n**Attributes and Methods**\n\n```python\nnp_date.year                       # 2078 (year)\nnp_date.month                      # 1 (month)\nnp_date.day                        # 18 (day)\n\nnp_date.to_date()                  # datetime.date object\nnp_date.to_datetime()              # datetime.datetime object\nnp_date.to_nepalidatetime()        # nepalidatetime object\n\nnp_date.strftime(\"%Y-%m-%d\")       # 2078-01-18\nnp_date.strftime_ne(\"%Y-%m-%d\")    # २०७८-०१-१८\n\nnp_date.weekday()                  # Sunday =\u003e 0, Monday =\u003e 1, ..., Saturday =\u003e 6\n```\n\n### nepalidatetime\n\n**Creating a new nepalidatetime object**\n\n```python\nfrom nepali.datetime import nepalidatetime\n\n# nepalidate object with year, month, day, hour, minute, second\nnp_datetime = nepalidatetime(year, month, day[, hour[, minute[, second]]])\n\n# nepalidate object with current date and time\nnp_datetime = nepalidate.now()\nnp_datetime = nepalidate.today()\n\n# parse nepali datetime\nnp_datetime = nepalidatetime.strptime('2078-01-12 13:12', format='%Y-%m-%d %H:%M')\n```\n\n**Getting nepalidatetime object from python datetime**\n\n```python\n# from date object\nnp_datetime = nepalidatetime.from_date(date_obj)\n\n# from datetime object\nnp_datetime = nepalidatetime.from_datetime(datetime_obj)\n```\n\n**Getting nepalidatetime object from nepalidate**\n\n```python\nnp_datetime = nepalidatetime.from_nepalidate(nepali_date)\n```\n\n**Attributes and Methods**\n\n```python\nnp_date.year                             # 2078 (year)\nnp_date.month                            # 1 (month)\nnp_date.day                              # 18 (day)\nnp_date.hour                             # 23 (hour)\nnp_date.minute                           # 59 (minute)\nnp_date.second                           # 59 (day)\n\nnp_date.to_date()                        # datetime.date object\nnp_date.to_datetime()                    # datetime.datetime object\nnp_date.to_nepalidate()                  # nepalidatetime object\nnp_date.to_time()                        # nepalitime object (datetime.time compatible)\n\nnp_date.strftime(\"%Y-%m-%d %H:%M\")       # 2078-01-18 23:59\nnp_date.strftime_ne(\"%Y-%m-%d %H:%M\")    # २०७८-०१-१८ २३:५९\n\nnp_date.weekday()                        # Sunday =\u003e 0, Monday =\u003e 1, ..., Saturday =\u003e 6\n```\n\n**Timedelta support**\n\n```python\n# timedelta addition and subtraction\nnp_datetime - datetime.timedelta(days=3)       # returns nepalidatetime\n\n# comparison between two dates\nnp_datetime1 - np_datetime2                    # returns timedelta object\nnp_datetime1 \u003c np_datetime2                    # returns bool (True/False)\nnp_datetime1 \u003e= datetime.datetime.now()        # returns bool (True/False)\n...\n```\n\n### nepalihumanize\n\nReturns readable form of nepali date.\n\n```python\nfrom nepali.datetime import nepalihumanize\n\n\nnepalihumanize(datetime, [threshold, format])\n```\n\nThe `threshold` is and optional field and is in seconds and the format is for the `strftime` format. If the datetime object crosses the threshold it print the date with the format. The `format` is also an optional and is `%B %d, %Y` in default.\n\nExample\n\n```python\nfrom nepali.datetime import nepalihumanize, nepalidatetime\n\nnp_datetime = nepalidatetime(2079, 10, 5)\noutput = nepalihumanize(np_datetime)\n# output: ३ महिना अघि\n\noutput = nepalihumanize(np_datetime, threshold=1400)\n# 1400 = 2 * 30 * 24; two months threshold\n# output: माघ ०५, २०७९\n```\n\n### timezone\n\n**NepaliTimeZone**\nYou can use `NepaliTimeZone` directly to your datetime object.\n\n```python\nfrom nepali.timezone import NepaliTimeZone\n\ndatetime.datetime(2018, 8, 12, 16, 23, tzinfo=NepaliTimeZone())\n```\n\n**now**\nReturns current datetime object with timezone\n\n```python\nfrom nepali import timezone\n\ntimezone.now()\n```\n\n`datetime.now()` vs `timezone.now()`:\n`datetime.now()` doesn't contain timezone, but `timezone.now()` will contain timezone of the system.\n\n**utc_now**\nReturns current UTC datetime object (with timezone UTC)\n\n```python\nfrom nepali import timezone\n\ntimezone.utc_now()\n```\n\n### parse\n\nParses date with commonly used date formats. Auto detects date format. If you are sure about the format, please use `strptime`.\n\n```python\nfrom nepali.datetime.parser import parse\n\nnp_datetime = parse(datetime_str)\n```\n\nExample\n\n```python\nnp_datetime = parse(\"2079-02-15\")                     # 2079-02-15 00:00:00\nnp_datetime = parse(\"२०७८-०१-१८\")                      # 2078-01-15 00:00:00\nnp_datetime = parse(\"2079/02/15\")                     # 2079-02-15 00:00:00\nnp_datetime = parse(\"2079-02-15 15:23\")               # 2079-02-15 15:23:00\nnp_datetime = parse(\"2079-02-15 5:23 AM\")             # 2079-02-15 05:23:00\nnp_datetime = parse(\"2079-02-15 5:23 AM\")             # 2079-02-15 05:23:00\nnp_datetime = parse(\"Jestha 15, 2079\")                # 2079-02-15 00:00:00\n\n```\n\n### strftime() and strptime() Format Codes\n\n| Directive | Meaning                                                   | Example                        |\n| --------- | --------------------------------------------------------- | ------------------------------ |\n| `%a`      | Weekday as locale’s abbreviated name.                     | Sun, Mon, …, Sat (आइत, सोम, …) |\n| `%A`      | Weekday as locale’s full name.                            | Sunday, Monday, …, Saturday    |\n| `%d`      | Day of the month as a zero-padded decimal number.         | 01, 02, …, 31                  |\n| `%-d`     | Day of the month as a decimal number.                     | 1, 2, …, 31                    |\n| `%B`      | Month as locale’s full name.                              | Baishakh, Jestha, …, Chaitra   |\n| `%m`      | Month as a zero-padded decimal number.                    | 01, 02, …, 12                  |\n| `%-m`     | Month as a decimal number.                                | 1, 2, …, 12                    |\n| `%y`      | Year without century as a zero-padded decimal number.     | 00, 01, …, 99                  |\n| `%Y`      | Year with century as a decimal number.                    | 2001, 2078, 2079, …, 2099      |\n| `%H`      | Hour (24-hour clock) as a zero-padded decimal number.     | 00, 01, …, 23                  |\n| `%-H`     | Hour (24-hour clock) as a decimal number.                 | 0, 1, 2, …, 23                 |\n| `%I`      | Hour (12-hour clock) as a zero-padded decimal number.     | 01, 02, …, 12                  |\n| `%-I`     | Hour (12-hour clock) as a decimal number.                 | 1, 2, …, 12                    |\n| `%p`      | Locale’s equivalent of either AM or PM.                   | AM, PM (en_US)                 |\n| `%M`      | Minute as a zero-padded decimal number.                   | 00, 01, …, 59                  |\n| `%-M`     | Minute as a decimal number.                               | 0, 1, 2, …, 59                 |\n| `%S`      | Second as a zero-padded decimal number.                   | 00, 01, …, 59                  |\n| `%-S`     | Second as a decimal number.                               | 0, 1, 2, …, 59                 |\n| `%f`      | Microsecond as a decimal number, zero-padded to 6 digits. | 000000, 000001, …, 999999      |\n| `%%`      | A literal `'%'` character.                                | %                              |\n\n---\n\n## Numbers\n\n```python\nfrom nepali import number\n```\n\n**convert**\nConverts english number to nepali.\n\n```python\nnp_number = number.convert(\"1234567890\")  # १२३४५६७८९०\n```\n\n**revert**\nConverts english number to nepali.\n\n```python\nen_number = number.revert(\"१२३४५६७८९०\")  # 1234567890\n```\n\n**add_comma**\nAdds comma in nepali numbers.\n\n```python\nnumber_text = number.add_comma(\"1234567890\")  # 1,23,45,67,890\n```\n\n### nepalinumber\n`nepalinumber` is a new data type, which can be used to represent Nepali (Devanagari) numbers. It allows us to perform arithmetic operations, just like with int and float. Additionally, it can be used to parse numbers and output them in Devanagari format.\n\n```python\nfrom nepali.number import nepalinumber\n```\n\n**Parsing**\n```python\na = nepalinumber(\"१८.२७\")\nprint(a)  # 18.27\n\nb = nepalinumber(15)\nprint(b)  # 15\n```\n\n**Nepali (Devanagari) output**\n```python\na = nepalinumber(\"18.27\")\nprint(a.str_ne())  # १८.२७\n```\n\n**Arithmetic operations**\n```python\na = nepalinumber(\"1\")\nb = nepalinumber(\"२\")\nc = a + b * 3\nprint(c)  # 7\n```\n---\n\n## Phone Number\n\n```python\nfrom nepali import phone_number\n```\n\n**is_valid**\nChecks is the given number is a valid nepali phone number.\n\n```python\nphone_number.is_valid(\"9851377890\")      # True\nphone_number.is_valid(\"+977-142314819\")  # True\n\nphone_number.is_valid(\"8251377890\")      # False\n```\n\n**parse**\nParse phone number and returns details of the number.\n\n```python\nphone_number.parse(\"9851377890\")\n# {'type': 'Mobile', 'number': '9851377890', 'operator': \u003cOperator: Nepal Telecom\u003e}\n\nphone_number.parse(\"+977-142314819\")\n# {'type': 'Landline', 'number': '0142314819', 'area_code': '01'}\n```\n\n---\n\n## Locations\n\nProvides details of Nepal's Province, District, and Municipality.\n\n```python\nfrom nepali.locations import provinces, districts, municipalities\n```\n\n```python\nfrom nepali.locations.utils import get_province, get_district, get_municipality\n\n# Province\nget_province(name=\"Bagmati\")\n# Bagmati Province\n\n# District\nget_district(name=\"Kathmandu\")\n# Kathmandu\n\n# Municipality\nget_municipality(name=\"Kathmandu\")\n# Kathmandu Metropolitan City\n\n# Municipality\nget_municipality(name_nepali=\"विराटनगर\")\n# Biratnagar Metropolitan City\n```\n\n---\n\n## For Django\n\nWe have created a new Django package called [django-nepali](https://github.com/opensource-nepal/django-nepali) to support `nepali` package. For more information, please visit [django-nepali](https://github.com/opensource-nepal/django-nepali).\n\n## Contribution\n\nWe appreciate feedback and contribution to this package. To get started please see our [contribution guide](./CONTRIBUTING.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopensource-nepal%2Fpy-nepali","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopensource-nepal%2Fpy-nepali","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopensource-nepal%2Fpy-nepali/lists"}