Skip to main content

Pythonic Money class. Correct. Type-safe. Matches expectations.

Project description

mundane

Pythonic Money class. Correct. Type-safe. Matches expectations.

Installation

pip install mundane

Required Python version: 3.12.

Usage

>>> from mundane import EUR, PLN, Money
>>> PLN(50) < PLN(100)
True
>>> PLN(50) < EUR(50)
TypeError: '<' not supported between money in 'PLN' and 'EUR'
>>> PLN(50) / 2
PLN('25')
>>> def do_something_with_money(money: Money):
...     print(money)
...
>>> do_something_with_money(PLN(25))
PLN 25
>>> do_something_with_money(EUR(50))
EUR 50

See tests/test_money.py for more examples.

Supported operations (a and b are money instances with matching currency):

  • a == b, a != b, a < b, a <= b, a > b, a >= b
  • +a, -a, abs(a)
  • a + b, a - b, 2 * a, a * 2, a / 2, a / b
  • round(a), round(a, 2), math.trunc(a), math.floor(a), math.ceil(a)
  • str(a), repr(a), hash(a)

Define your own currency

from mundane import TypedMoney

class BTC(TypedMoney):
    pass

print(BTC('0.0000000000000000000000000001'))
# BTC 0.0000000000000000000000000001

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mundane-0.1.1.tar.gz (12.4 kB view hashes)

Uploaded Source

Built Distribution

mundane-0.1.1-py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page