A strict money parser that reads what humans write and preserves what they meant
Project description
parsimoney
A strict money parser. Reads what humans write, preserves what they meant.
from parsimoney import parse_money
parse_money("$45.00") # Money(amount=45.0, currency="$", iso=None)
parse_money("45 dollars") # Money(amount=45.0, currency="dollars", iso=None, currency_after=True)
parse_money("EUR 1,234.56") # Money(amount=1234.56, currency="EUR", iso="EUR")
parse_money("\u20ac100") # Money(amount=100.0, currency="\u20ac", iso="EUR")
parse_money("1000 yen") # Money(amount=1000.0, currency="yen", iso="JPY")
Strict: the entire input must be accounted for. No silent data loss.
parse_money("$45.00 worth of stuff") # raises ValueError
ISO Resolution
Unambiguous currencies resolve automatically. Ambiguous ones like $
and "dollars" (USD? CAD? AUD?) resolve via application-provided defaults
or locale:
parse_money("$100", defaults={"$": "CAD"})
# Money(amount=100.0, currency="$", iso="CAD")
parse_money("100 dollars", defaults={"dollars": "AUD"})
# Money(amount=100.0, currency="dollars", iso="AUD", currency_after=True)
Without an explicit default, ambiguous currencies check the system
locale. If the locale doesn't resolve it either, iso is None -
parsimoney never guesses.
CLI
$ python -m parsimoney '$45.00' '100 euros' '1,234 USD'
'$45.00' -> $45
'100 euros' -> 100 euros
'1,234 USD' -> 1234 USD
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 parsimoney-0.4.1.tar.gz.
File metadata
- Download URL: parsimoney-0.4.1.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.8.0-117-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fb9604587840c07da489f2ede28f71a65382bdf86bf6972c08c8e6b23a4240c
|
|
| MD5 |
257d16f3af678ead23ed96da8ab613c6
|
|
| BLAKE2b-256 |
f2601a2f51db705349b7bd97bfe435167f8ba825cc5ecd466c6ae4a504139098
|
File details
Details for the file parsimoney-0.4.1-py3-none-any.whl.
File metadata
- Download URL: parsimoney-0.4.1-py3-none-any.whl
- Upload date:
- Size: 20.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.8.0-117-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b74b205c12ad33d6e0b2bf0e2dbefe98a4d7007789ecb979cb322bee9dc8059c
|
|
| MD5 |
296a64df869a08eeb6f103f6758cfee4
|
|
| BLAKE2b-256 |
618a5d2720b7189162178b1f3078841048338d49f37c965c3ecf339ef8766b79
|