Python implementation of Fowler's Money pattern inspired by go-money in GO
Project description
Kùdí 💰 (WIP)
“Kùdí” (also spelled “kudi”) is a Hausa word that means money 💰. Kudi is a python implementation of Fowler's Money pattern inspired by Rhymond/go-money
Installation
uv add kudi
Usage
from kudi import Money, CurrencyCode
m1 = Money(50, 'USD') # Fifty cents
m2 = Money('1.50', 'USD') # One dollar and fifty cents
m3 = Money(-100, 'usd')
m4 = Money(0, CurrencyCode.EUR)
# Arithmetic
print(m2 + m1)
print(m2 - m2)
print(m2 + m1 - m2)
print(m1 + m4) # will raise an exception, arithmetic on monies in different currencies is not allowed
print(m1 * 4)
print(-m2)
print(abs(m3)) # Absolute
print(m1.negative()) # Not to be confused with `-m1`, `.negative` will
# always result in a negative value
# Assertions
print(m3.is_negative)
print(m4.is_zero)
print(m1.is_positive)
# Allocations
# In order to split Money for parties without losing any pennies due
# to rounding differences, use `split`.
# After division leftover pennies will be distributed round-robin amongst
# the parties. This means that parties listed first will likely receive
# more pennies than ones that are listed later.
pound = Money(100, 'GBP')
allocations = pound.split(3)
print(allocations)
# To perform splits in ratios, use `allocate`.
# It splits money using the given ratios without losing pennies and as
# Split operations distributes leftover pennies amongst the parties
# with round-robin principle.
allocations = pound.allocate([33,33,33])
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
kudi-0.0.1.tar.gz
(9.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
kudi-0.0.1-py3-none-any.whl
(11.1 kB
view details)
File details
Details for the file kudi-0.0.1.tar.gz.
File metadata
- Download URL: kudi-0.0.1.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f836ff62f1219beee85c0c29e15c634af20a51f25daefa6eaed83b101b93aa61
|
|
| MD5 |
16564166965f7f687c9b1f355f285ad6
|
|
| BLAKE2b-256 |
9c40a42482a3bebaac8e0f60f442e69d1bf83a003d8cd10e6d7ce0134d03fcba
|
File details
Details for the file kudi-0.0.1-py3-none-any.whl.
File metadata
- Download URL: kudi-0.0.1-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7275b3032e66df1efd200ae05cefc705e532819a1b95caf7542228d49784019b
|
|
| MD5 |
28fd07d970109a814a317c0ea6b80853
|
|
| BLAKE2b-256 |
c002b2bfa510bb2721fbb97748f81bda3a9f688a90fa65ff36b717ae0adadf5d
|