Skip to content
Python price handling for humans
Python
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
prices
.gitignore
.travis.yml
README.rst
setup.py

README.rst

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')"
Something went wrong with that request. Please try again.