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.2.0.tar.gz (17.3 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.2.0-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: parsimoney-0.2.0.tar.gz
  • Upload date:
  • Size: 17.3 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.2.0.tar.gz
Algorithm Hash digest
SHA256 644d6edac8210ca5daf9f9cc45d2f8bb7a3f1b497254bc92a4fd1cd84b6df636
MD5 b23ca4e3f1fea23352f3b5a65ecb0577
BLAKE2b-256 6490ba5a9360d87303893457f4b8321b78b6501f6f00754c3bec9f5974633f08

See more details on using hashes here.

File details

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

File metadata

  • Download URL: parsimoney-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.2 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fad4c448b2b28b42401bde6bf3362d4046cf4065aaf8ddec64f932e056c826ae
MD5 114de816ddd65d41edc0f60795d0d9c2
BLAKE2b-256 d822c8a99c70af45be9d0978ee7eddfe844f18b538851c7b96114a77afb76f0f

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