Skip to main content

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

parsimoney-0.1.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

parsimoney-0.1.0-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file parsimoney-0.1.0.tar.gz.

File metadata

  • Download URL: parsimoney-0.1.0.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.8.0-106-generic

File hashes

Hashes for parsimoney-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c90cd0e00e231d205d1d168a02981532e82efa17acbecbc4de97231c10cadd01
MD5 c869b68d03a95801d663667e4e464de8
BLAKE2b-256 80f26e188f05b62fc915304fd88b5354e273a396329cf37f352defb9eba66328

See more details on using hashes here.

File details

Details for the file parsimoney-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: parsimoney-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.8.0-106-generic

File hashes

Hashes for parsimoney-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ea5f7a3f2883cb9b8896e8b8545f6a09c81a19d85d9aafce503ca02a8238483
MD5 f9e0b895e14b64a43012d6a05a00cd6f
BLAKE2b-256 b463cce97e0bebf1d2b5b958eea14339791afddcb1e6adcbc86e7f039ecc20ea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page