Price Parser
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.
Warnings
- gotcha 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.
- gotcha 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.
- gotcha 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`.
- gotcha 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.
Install
-
pip install price-parser
Imports
- Price
from price_parser import Price
- parse_price
from price_parser import parse_price
Quickstart
from price_parser import Price
# Basic usage
price = Price.fromstring("22,90 €")
print(f"Amount: {price.amount}, Currency: {price.currency}")
# Handling different formats
price2 = Price.fromstring("Price: $119.00")
print(f"Amount: {price2.amount}, Currency: {price2.currency}")
# Using currency hints
price3 = Price.fromstring("34.99", currency_hint="руб. (шт)")
print(f"Amount: {price3.amount}, Currency: {price3.currency}")
# Explicitly setting decimal separator
price4 = Price.fromstring("1.234,56 SEK", decimal_separator=",")
print(f"Amount: {price4.amount}, Currency: {price4.currency}")
# Accessing float value (use with caution for financial calculations)
price5 = Price.fromstring("€123.45")
print(f"Float Amount: {price5.amount_float}")