{"id":13501506,"url":"https://github.com/scrapinghub/price-parser","last_synced_at":"2025-05-14T18:06:48.968Z","repository":{"id":51135940,"uuid":"180854023","full_name":"scrapinghub/price-parser","owner":"scrapinghub","description":"Extract price amount and currency symbol from a raw text string","archived":false,"fork":false,"pushed_at":"2025-02-13T22:24:41.000Z","size":152,"stargazers_count":324,"open_issues_count":26,"forks_count":51,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-15T00:41:30.509Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scrapinghub.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-04-11T18:27:30.000Z","updated_at":"2025-04-05T10:00:20.000Z","dependencies_parsed_at":"2023-01-23T13:45:22.232Z","dependency_job_id":"ad512300-2304-4546-b1d0-3acaa4e2e0e1","html_url":"https://github.com/scrapinghub/price-parser","commit_stats":{"total_commits":83,"total_committers":13,"mean_commits":6.384615384615385,"dds":0.5180722891566265,"last_synced_commit":"18c5ed8c98a569f805ac4444a2dae20bdef27760"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrapinghub%2Fprice-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrapinghub%2Fprice-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrapinghub%2Fprice-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrapinghub%2Fprice-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scrapinghub","download_url":"https://codeload.github.com/scrapinghub/price-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254198514,"owners_count":22030965,"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":["hacktoberfest"],"created_at":"2024-07-31T22:01:39.830Z","updated_at":"2025-05-14T18:06:43.951Z","avatar_url":"https://github.com/scrapinghub.png","language":"Python","funding_links":[],"categories":["Python","Specialized Tools","Text Data"],"sub_categories":["Text Processing"],"readme":"============\nprice-parser\n============\n\n.. image:: https://img.shields.io/pypi/v/price-parser.svg\n   :target: https://pypi.python.org/pypi/price-parser\n   :alt: PyPI Version\n\n.. image:: https://img.shields.io/pypi/pyversions/price-parser.svg\n   :target: https://pypi.python.org/pypi/price-parser\n   :alt: Supported Python Versions\n\n.. image:: https://github.com/scrapinghub/price-parser/actions/workflows/main.yml/badge.svg?branch=master\n   :target: https://github.com/scrapinghub/price-parser/actions?workflow=Tests\n   :alt: Build Status\n\n.. image:: https://codecov.io/github/scrapinghub/price-parser/coverage.svg?branch=master\n   :target: https://codecov.io/gh/scrapinghub/price-parser\n   :alt: Coverage report\n\n\n``price-parser`` is a small library for extracting price and currency from\nraw text strings.\n\nFeatures:\n\n* robust price amount and currency symbol extraction\n* zero-effort handling of thousand and decimal separators\n\nThe main use case is parsing prices extracted from web pages.\nFor example, you can write a CSS/XPath selector which targets an element\nwith a price, and then use this library for cleaning it up,\ninstead of writing custom site-specific regex or Python code.\n\nLicense is BSD 3-clause.\n\nInstallation\n============\n\n::\n\n    pip install price-parser\n\nprice-parser requires Python 3.6+.\n\nUsage\n=====\n\nBasic usage\n-----------\n\n\u003e\u003e\u003e from price_parser import Price\n\u003e\u003e\u003e price = Price.fromstring(\"22,90 €\")\n\u003e\u003e\u003e price\nPrice(amount=Decimal('22.90'), currency='€')\n\u003e\u003e\u003e price.amount       # numeric price amount\nDecimal('22.90')\n\u003e\u003e\u003e price.currency     # currency symbol, as appears in the string\n'€'\n\u003e\u003e\u003e price.amount_text  # price amount, as appears in the string\n'22,90'\n\u003e\u003e\u003e price.amount_float # price amount as float, not Decimal\n22.9\n\nIf you prefer, ``Price.fromstring`` has an alias ``price_parser.parse_price``,\nthey do the same:\n\n\u003e\u003e\u003e from price_parser import parse_price\n\u003e\u003e\u003e parse_price(\"22,90 €\")\nPrice(amount=Decimal('22.90'), currency='€')\n\nThe library has extensive tests (900+ real-world examples of price strings).\nSome of the supported cases are described below.\n\nSupported cases\n---------------\n\nUnclean price strings with various currencies are supported;\nthousand separators and decimal separators are handled:\n\n\u003e\u003e\u003e Price.fromstring(\"Price: $119.00\")\nPrice(amount=Decimal('119.00'), currency='$')\n\n\u003e\u003e\u003e Price.fromstring(\"15 130 Р\")\nPrice(amount=Decimal('15130'), currency='Р')\n\n\u003e\u003e\u003e Price.fromstring(\"151,200 تومان\")\nPrice(amount=Decimal('151200'), currency='تومان')\n\n\u003e\u003e\u003e Price.fromstring(\"Rp 1.550.000\")\nPrice(amount=Decimal('1550000'), currency='Rp')\n\n\u003e\u003e\u003e Price.fromstring(\"Běžná cena 75 990,00 Kč\")\nPrice(amount=Decimal('75990.00'), currency='Kč')\n\n\nEuro sign is used as a decimal separator in a wild:\n\n\u003e\u003e\u003e Price.fromstring(\"1,235€ 99\")\nPrice(amount=Decimal('1235.99'), currency='€')\n\n\u003e\u003e\u003e Price.fromstring(\"99 € 95 €\")\nPrice(amount=Decimal('99'), currency='€')\n\n\u003e\u003e\u003e Price.fromstring(\"35€ 999\")\nPrice(amount=Decimal('35'), currency='€')\n\n\nSome special cases are handled:\n\n\u003e\u003e\u003e Price.fromstring(\"Free\")\nPrice(amount=Decimal('0'), currency=None)\n\n\nWhen price or currency can't be extracted, corresponding\nattribute values are set to None:\n\n\u003e\u003e\u003e Price.fromstring(\"\")\nPrice(amount=None, currency=None)\n\n\u003e\u003e\u003e Price.fromstring(\"Foo\")\nPrice(amount=None, currency=None)\n\n\u003e\u003e\u003e Price.fromstring(\"50% OFF\")\nPrice(amount=None, currency=None)\n\n\u003e\u003e\u003e Price.fromstring(\"50\")\nPrice(amount=Decimal('50'), currency=None)\n\n\u003e\u003e\u003e Price.fromstring(\"R$\")\nPrice(amount=None, currency='R$')\n\n\nCurrency hints\n--------------\n\n``currency_hint`` argument allows to pass a text string which may (or may not)\ncontain currency information. This feature is most useful for automated price\nextraction.\n\n\u003e\u003e\u003e Price.fromstring(\"34.99\", currency_hint=\"руб. (шт)\")\nPrice(amount=Decimal('34.99'), currency='руб.')\n\nNote that currency mentioned in the main price string may be\n**preferred** over currency specified in ``currency_hint`` argument;\nit depends on currency symbols found there. If you know the correct currency,\nyou can set it directly:\n\n\u003e\u003e\u003e price = Price.fromstring(\"1 000\")\n\u003e\u003e\u003e price.currency = 'EUR'\n\u003e\u003e\u003e price\nPrice(amount=Decimal('1000'), currency='EUR')\n\n\nDecimal separator\n-----------------\n\nIf you know which symbol is used as a decimal separator in the input string,\npass that symbol in the ``decimal_separator`` argument to prevent price-parser\nfrom guessing the wrong decimal separator symbol.\n\n\u003e\u003e\u003e Price.fromstring(\"Price: $140.600\", decimal_separator=\".\")\nPrice(amount=Decimal('140.600'), currency='$')\n\n\u003e\u003e\u003e Price.fromstring(\"Price: $140.600\", decimal_separator=\",\")\nPrice(amount=Decimal('140600'), currency='$')\n\n\nContributing\n============\n\n* Source code: https://github.com/scrapinghub/price-parser\n* Issue tracker: https://github.com/scrapinghub/price-parser/issues\n\nUse tox_ to run tests with different Python versions::\n\n    tox\n\nThe command above also runs type checks; we use mypy.\n\n.. _tox: https://tox.readthedocs.io\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscrapinghub%2Fprice-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscrapinghub%2Fprice-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscrapinghub%2Fprice-parser/lists"}