Skip to content

Latest commit

 

History

History
77 lines (53 loc) · 2.03 KB

README.md

File metadata and controls

77 lines (53 loc) · 2.03 KB

moneymoney

Money package for Python

PyPI GitHub release (latest by date) PyPI - Python Version PyPi downloads

Installation

pip install moneymoney

Usage

Base usages

from moneymoney.currency_codes import CurrencyCodes
from moneymoney.defaults import ONE_EUR
from moneymoney.money import Money
from moneymoney.presets import EUR

# using a string as currency code
quantity = Money(amount=1000, currency_code="EUR")

# using currency codes from this package
quantity_two = Money(amount=1000, currency_code=CurrencyCodes.EUR)

# using defaults
my_price = ONE_EUR

# using presets
my_euro = EUR(amount=1.0)

Some possible operations

You can add, subtract, multiply and divide money!

from moneymoney.money import Money

# add
money_a = Money(currency_code="EUR", amount=3.0)
money_b = Money(currency_code="EUR", amount=2.0)
money_c = money_a + money_b  # equal to Money(currency_code="EUR", amount=5.0)

# subtract
money_a = Money(currency_code="EUR", amount=3.0)
money_b = Money(currency_code="EUR", amount=2.0)
money_c = money_a - money_b  # equal to Money(currency_code="EUR", amount=1.0)

# multiply
money_a = Money(currency_code="EUR", amount=3.0)
money_b = money_a * 3  # equal to Money(currency_code="EUR", amount=9.0)

# divide
money_a = Money(currency_code="EUR", amount=3.0)
money_b = money_a / 3  # equal to Money(currency_code="EUR", amount=1.0)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Sponsors

Become a sponsor here

License

GPLv3