{"id":52016743,"url":"https://github.com/rondomondo/python-utils-rondomondo","last_synced_at":"2026-07-31T22:27:10.358Z","repository":{"id":358961510,"uuid":"1243869436","full_name":"rondomondo/python-utils-rondomondo","owner":"rondomondo","description":"A small, dependency-free Python 3.12 library of practical utilities for two domains that come up in almost every project: dates and money.  The money module is built on top of Python's decimal.Decimal and covers the full lifecycle of a monetary value - converting raw input with to_money, rounding with either half-up or banker's convention, truncati","archived":false,"fork":false,"pushed_at":"2026-05-19T21:39:01.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-24T16:25:26.879Z","etag":null,"topics":["accounting","currency","dates","datetime","decimal","finance","formatting","fstrings","money","python","python3","stdlib","type-hints","utilities"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rondomondo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-19T18:40:23.000Z","updated_at":"2026-05-19T21:39:05.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/rondomondo/python-utils-rondomondo","commit_stats":null,"previous_names":["rondomondo/python-utils-rondomondo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rondomondo/python-utils-rondomondo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rondomondo%2Fpython-utils-rondomondo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rondomondo%2Fpython-utils-rondomondo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rondomondo%2Fpython-utils-rondomondo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rondomondo%2Fpython-utils-rondomondo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rondomondo","download_url":"https://codeload.github.com/rondomondo/python-utils-rondomondo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rondomondo%2Fpython-utils-rondomondo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":36136272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-07-20T02:08:10.276Z","status":"online","status_checked_at":"2026-07-31T02:00:06.731Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["accounting","currency","dates","datetime","decimal","finance","formatting","fstrings","money","python","python3","stdlib","type-hints","utilities"],"created_at":"2026-07-31T22:27:09.796Z","updated_at":"2026-07-31T22:27:10.352Z","avatar_url":"https://github.com/rondomondo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# python-utils-rondomondo\n\nReusable Python utilities for dates and money.\n\n## Install\n\n```bash\npip install python-utils-rondomondo\n```\n\nOr with `uv`:\n\n```bash\nuv add python-utils-rondomondo\n```\n\n## Usage\n\n```python\nfrom python_utils.dates import now_utc, parse_duration, date_windows\nfrom python_utils.money import to_money, fmt_accounting, format_currency, allocate\n```\n\n### Dates\n\n| Function | Description |\n|---|---|\n| `now_utc(microsecond=False)` | Current UTC datetime, always timezone-aware |\n| `to_iso(dt, timespec=\"seconds\")` | Format datetime as ISO 8601 string (space separator) |\n| `from_iso(s)` | Parse ISO 8601 string to datetime |\n| `parse_duration(s)` | Parse human duration like `\"7days\"`, `\"3hrs\"`, `\"90secs\"` to `timedelta` |\n| `midnight_before(dt)` | Midnight at the start of the day before `dt` |\n| `date_windows(start, end, window)` | Split a range into non-overlapping `timedelta` windows |\n| `is_leap(year)` | True if the given year is a leap year |\n| `same_day_next_year(dt)` | Advance by one calendar year, clamping Feb 29 to Feb 28 |\n\n```python\nfrom python_utils.dates import now_utc, parse_duration, date_windows, to_iso\nfrom datetime import timedelta\n\nnow = now_utc()\nend = now + parse_duration(\"7days\")\nwindows = date_windows(now, end, timedelta(days=2))\nprint(to_iso(now))  # '2026-05-19 14:30:00+00:00'\n```\n\n### Money\n\n| Function | Description |\n|---|---|\n| `to_money(value)` | Convert `str`, `int`, or `Decimal` to a cent-quantised `Decimal` (half-up) |\n| `to_decimal(value)` | Convert `int`, `float`, `str`, or `Decimal` to `Decimal` without rounding |\n| `round_half_up(amount, places=2)` | Round using half-up convention |\n| `round_bankers(amount, places=2)` | Round using banker's rounding (half to even) |\n| `truncate(amount, places=2)` | Truncate toward zero |\n| `format_currency(amount, symbol=\"$\", thousands=True)` | Format `Decimal` as a currency string |\n| `parse_currency(s)` | Parse a currency string like `\"$1,234.56\"` or `\"-£99.00\"` to `Decimal` |\n| `fmt_accounting(value)` | Accounting convention: negatives as `(120.00)`, positives as `500.00 ` |\n| `allocate(amount, ratios)` | Distribute amount across ratios with no penny lost or gained |\n\n```python\nfrom decimal import Decimal\nfrom python_utils.money import to_money, format_currency, fmt_accounting, allocate\n\nprice = to_money(\"19.99\")\ntax   = to_money(price * Decimal(\"0.1\"))  # 2.00\ntotal = price + tax                       # 21.99\n\nprint(format_currency(total))             # '$21.99'\nprint(fmt_accounting(Decimal(\"-120.00\"))) # '(120.00)'\nprint(fmt_accounting(Decimal(\"500.00\"))) # '500.00 '\n\nshares = allocate(Decimal(\"100.00\"), [1, 2, 3])  # [33.33, 33.33, 33.34] (sums exactly)\n```\n\n## Examples\n\n### F-string formatting reference\n\n[`src/python_utils/examples/fstrings.py`](src/python_utils/examples/fstrings.py) is a runnable reference script covering the full range of Python f-string format specs, using an invoice as the running example:\n\n- Number formatting: decimal places, thousands separators, alignment, currency symbols\n- Sign formatting: explicit `+`, space padding, accounting parentheses\n- Integer bases: hex, octal, binary, scientific notation, percent\n- String alignment, padding, fill characters, truncation\n- Expressions, conditionals, and method calls inside f-strings\n- Conversion flags: `!s`, `!r`, `!a`\n- A complete invoice table tying all patterns together\n\n```bash\npython src/python_utils/examples/fstrings.py\n```\n\n## Requirements\n\nPython 3.12+\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frondomondo%2Fpython-utils-rondomondo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frondomondo%2Fpython-utils-rondomondo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frondomondo%2Fpython-utils-rondomondo/lists"}