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
Release history Release notifications | RSS feed
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 details)
Built Distribution
File details
Details for the file mundane-0.1.1.tar.gz
.
File metadata
- Download URL: mundane-0.1.1.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ef07832dbd50027f253210fd9c979fee6bd16c8c0cf3844307812e4bb20ec4f |
|
MD5 | 0372358c285bf3300c79295b4fcd9858 |
|
BLAKE2b-256 | a0279c31c070d22e80d4e18fd3cec1f414036a6d4ca77f78167bdd25bb6d8b0c |
File details
Details for the file mundane-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: mundane-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c95067f710ef0dceb8fbf12161b90214a5ba1abccfa4b72f840056616890f867 |
|
MD5 | 6a7efa00d034dea1527bbaed9fcaf5e0 |
|
BLAKE2b-256 | effc21beba9aeba438864804d8ae8cf9a1a2beb852dac41ed1feb8ef707cf3e7 |