Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4df4bced8a
Fetching contributors…

Cannot retrieve contributors at this time

34 lines (27 sloc) 0.988 kb

Prices: Python price handling for humans

>>> from prices import price, pricerange, lineartax
>>> p = price('1.99')
>>> p += price(50)
>>> p += lineartax('1.23', '23% VAT')
>>> p.quantize('0.01').gross
Decimal('63.95')
>>> pr = pricerange(price(50), price(100))
>>> p in pr
True

While protecting you from all sorts of mistakes:

>>> from prices import price
>>> price(10, currency='USD') < price(15, currency='GBP')
...
ValueError: Cannot compare prices in 'USD' and 'GBP'
>>> price(5, currency='BTC') + price(7, currency='INR')
...
ValueError: Cannot add price in 'BTC' to 'INR'

And being helpful:

>>> from prices import price, lineartax, inspect_price
>>> p = price('1.99')
>>> p += price(50)
>>> p += lineartax('1.23', '23% VAT')
>>> inspect_price(p)
"price('1.99', currency=None) + price('50', currency=None) + lineartax('1.23', name='23% VAT')"
Jump to Line
Something went wrong with that request. Please try again.