Reusable Python utilities for dates, money, and more
Project description
python-utils-rondomondo
Reusable Python utilities for dates and money.
Install
pip install python-utils-rondomondo
Or with uv:
uv add python-utils-rondomondo
Usage
from python_utils.dates import now_utc, parse_duration, date_windows
from python_utils.money import to_money, format_currency, allocate, fmt_accounting
Dates
| Function | Description |
|---|---|
now_utc(microsecond=False) |
Current UTC datetime, always timezone-aware |
to_iso(dt, timespec="seconds") |
Format datetime as ISO 8601 string (space separator) |
from_iso(s) |
Parse ISO 8601 string to datetime |
parse_duration(s) |
Parse human duration like "7days", "3hrs", "90secs" to timedelta |
midnight_before(dt) |
Midnight at the start of the day before dt |
date_windows(start, end, window) |
Split a range into non-overlapping timedelta windows |
is_leap(year) |
True if the given year is a leap year |
same_day_next_year(dt) |
Advance by one calendar year, clamping Feb 29 to Feb 28 |
from python_utils.dates import now_utc, parse_duration, date_windows, to_iso
from datetime import timedelta
now = now_utc()
end = now + parse_duration("7days")
windows = date_windows(now, end, timedelta(days=2))
print(to_iso(now)) # '2026-05-19 14:30:00+00:00'
Money
| Function | Description |
|---|---|
to_money(value) |
Convert str, int, or Decimal to a cent-quantised Decimal (half-up) |
to_decimal(value) |
Convert int, float, str, or Decimal to Decimal without rounding |
round_half_up(amount, places=2) |
Round using half-up convention |
round_bankers(amount, places=2) |
Round using banker's rounding (half to even) |
truncate(amount, places=2) |
Truncate toward zero |
format_currency(amount, symbol="$", thousands=True) |
Format Decimal as a currency string |
parse_currency(s) |
Parse a currency string like "$1,234.56" or "-£99.00" to Decimal |
fmt_accounting(value) |
Accounting convention: negatives as (120.00), positives as 500.00 |
allocate(amount, ratios) |
Distribute amount across ratios with no penny lost or gained |
from decimal import Decimal
from python_utils.money import to_money, format_currency, fmt_accounting, allocate
price = to_money("19.99")
tax = to_money(price * Decimal("0.1")) # 2.00
total = price + tax # 21.99
print(format_currency(total)) # '$21.99'
print(fmt_accounting(Decimal("-120.00"))) # '(120.00)'
print(fmt_accounting(Decimal("500.00"))) # '500.00 '
shares = allocate(Decimal("100.00"), [1, 2, 3]) # [33.33, 33.33, 33.34] (sums exactly)
Requirements
Python 3.12+
License
MIT
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
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
File details
Details for the file python_utils_rondomondo-0.1.3.tar.gz.
File metadata
- Download URL: python_utils_rondomondo-0.1.3.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c596b6d1a820e0b775bb22bed27a87b98c9642a96757fc145576d1115b04b0d8
|
|
| MD5 |
2c7edd72419d4401509a552c46f76671
|
|
| BLAKE2b-256 |
cb20bc2ed86b79ecc8f9d19e8c3ff7117d4d22b7e0dd5ad879e7a1a615bc76a4
|
File details
Details for the file python_utils_rondomondo-0.1.3-py3-none-any.whl.
File metadata
- Download URL: python_utils_rondomondo-0.1.3-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
698f182172671a218150ce5e2cc0f98c57752228df6b5e303eafa7a81750167b
|
|
| MD5 |
13009b1f932db7118ebebd4a1c2c45ff
|
|
| BLAKE2b-256 |
5588709020e67cb76b1bb045d338933778d88af69fe7b1bfa2a7cdfa4d21d6d5
|