Python price handling for humans.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
prices Add MoneyRange Jan 22, 2018
tests Add MoneyRange Jan 22, 2018
.coveragerc First draft of the new API Sep 28, 2017
.gitignore 0.4.2 Aug 20, 2013
.travis.yml Run mypy tests Jan 19, 2018
LICENSE Add LICENSE and Sep 28, 2017 Add LICENSE and Sep 28, 2017 Fix invalid tax example in readme May 9, 2018 Bump version to 1.0.0 Mar 2, 2018

Prices: Python price handling for humans

Build Status


from prices import Money
a = Money(10, 'USD')
a += Money(20, 'USD')
# Decimal('30')
a = a.quantize()
# Decimal('30.00')
a = Money('5.00', 'JPY')
# Decimal('5')

Taxed money:

from prices import Money, TaxedMoney
p = TaxedMoney(net=Money(20, 'EUR'), gross=Money(30, 'EUR'))
# Money('20', 'EUR')
# Money('30', 'EUR')
# Money('10', 'EUR')
p = p.quantize()
# Money('20.00', 'EUR')

Taxed ranges:

from prices import Money, TaxedMoney, TaxedMoneyRange
price1 = TaxedMoney(Money(1, 'USD'), Money(1, 'USD'))
price2 = TaxedMoney(Money(10, 'USD'), Money(10, 'USD'))
pr = TaxedMoneyRange(price1, price2)
# TaxedMoney(net=Money('1', 'USD'), gross=Money('1', 'USD'))
# TaxedMoney(net=Money('10', 'USD'), gross=Money('10', 'USD'))
price3 = TaxedMoney(net=Money(5, 'USD'), gross=Money(5, 'USD'))
price3 in pr
# True
pr = pr.quantize()
# Money('1.00', 'USD')


from decimal import Decimal
from prices import Money, TaxedMoney, TaxedMoneyRange, flat_tax
p = TaxedMoney(Money('1.99', 'GBP'), Money('1.99', 'GBP'))
p = flat_tax(p, Decimal('0.23'))
p = p.quantize()
# Money('2.45', 'GBP')

While protecting you from all sorts of mistakes:

from prices import Money
Money(10, 'USD') < Money(15, 'GBP')
# ValueError: Cannot compare amounts in 'USD' and 'GBP'
from prices import Money, TaxedMoney
price1 = TaxedMoney(Money(5, 'BTC'), Money(5, 'BTC'))
price2 = TaxedMoney(Money(7, 'INR'), Money(7, 'INR'))
price1 + price2
# ValueError: Cannot add amount in 'BTC' to 'INR'