{"id":6776,"library":"price-parser","title":"Price Parser","description":"Price-parser is a lightweight Python library designed for robustly extracting price amounts and currency symbols from raw text strings. It intelligently handles various international formats for decimal and thousand separators, making it particularly useful for cleaning price data obtained from web scraping. The library returns a `Price` object containing the numeric amount (as a `Decimal`) and the detected currency. The current version is 0.5.1, released on March 19, 2026, and it maintains an active development and release cadence.","status":"active","version":"0.5.1","language":"en","source_language":"en","source_url":"https://github.com/scrapinghub/price-parser","tags":["price","currency","parsing","extraction","web scraping","data cleaning"],"install":[{"cmd":"pip install price-parser","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"Price","correct":"from price_parser import Price"},{"note":"An alias for Price.fromstring()","symbol":"parse_price","correct":"from price_parser import parse_price"}],"quickstart":{"code":"from price_parser import Price\n\n# Basic usage\nprice = Price.fromstring(\"22,90 €\")\nprint(f\"Amount: {price.amount}, Currency: {price.currency}\")\n\n# Handling different formats\nprice2 = Price.fromstring(\"Price: $119.00\")\nprint(f\"Amount: {price2.amount}, Currency: {price2.currency}\")\n\n# Using currency hints\nprice3 = Price.fromstring(\"34.99\", currency_hint=\"руб. (шт)\")\nprint(f\"Amount: {price3.amount}, Currency: {price3.currency}\")\n\n# Explicitly setting decimal separator\nprice4 = Price.fromstring(\"1.234,56 SEK\", decimal_separator=\",\")\nprint(f\"Amount: {price4.amount}, Currency: {price4.currency}\")\n\n# Accessing float value (use with caution for financial calculations)\nprice5 = Price.fromstring(\"€123.45\")\nprint(f\"Float Amount: {price5.amount_float}\")","lang":"python","description":"Demonstrates basic price and currency extraction using `Price.fromstring()`, handling various formats, applying currency hints, and explicitly setting the decimal separator. It also shows how to access both Decimal and float representations of the amount."},"warnings":[{"fix":"Always use `price.amount` (Decimal) for calculations to avoid floating-point inaccuracies. Convert to float (`price.amount_float`) only when necessary for external systems that require floats.","message":"The `Price.amount` attribute returns a `Decimal` object for precision. While `Price.amount_float` is available, using floats for financial calculations can lead to precision errors. Prefer `Decimal` for accuracy.","severity":"gotcha","affected_versions":"All"},{"fix":"For improved reliability, provide the `decimal_separator` argument to `Price.fromstring()` if you know the exact separator used in the input string (e.g., `Price.fromstring(\"1.234,56\", decimal_separator=\",\")`).","message":"In ambiguous cases, especially with mixed international numeral formats (e.g., '1.234,56' vs '1,234.56'), the library might guess the decimal separator incorrectly. This is more common when no explicit currency symbol guides the parsing.","severity":"gotcha","affected_versions":"All"},{"fix":"Always check for `None` values on `price.amount` and `price.currency` after parsing to ensure successful extraction before further processing. Example: `if price.amount is not None: ...`","message":"If the library cannot confidently detect an amount or currency from the input string, the respective `amount` or `currency` attributes of the returned `Price` object will be `None`.","severity":"gotcha","affected_versions":"All"},{"fix":"Verify the import path `from price_parser import Price` and the project's GitHub repository `https://github.com/scrapinghub/price-parser` matches your intended library. If you need Pydantic compatibility, consider `price-parser-reworkd` (a different library).","message":"There are multiple Python packages (and even libraries in other languages) named 'price-parser' or similar. Ensure you are installing and using the correct 'scrapinghub/price-parser' library to avoid unexpected behavior or API differences.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}