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.4.0.tar.gz (18.2 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.4.0-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: parsimoney-0.4.0.tar.gz
  • Upload date:
  • Size: 18.2 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

Hashes for parsimoney-0.4.0.tar.gz
Algorithm Hash digest
SHA256 06b8031d150a8fd51eee5ff7350f0c50e212777ecf7b4c76ef3a6921129b5e4f
MD5 f3d63697e14458622bdd0b34ba84b686
BLAKE2b-256 c97b79384487ae3c7ed5d0721f5b8fd3d81b9ebe304a45454bfcc9977b2c9eea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: parsimoney-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 20.3 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

Hashes for parsimoney-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7777e49b676bca47aa46a36cf204a768ddc2b309104c5f65a8c2893092f0fea8
MD5 f780e866851ad5bb8182799a762a5e11
BLAKE2b-256 65807f9860cbf4b04933eed1ae636901cb8a87b9df44fe6fe6430d55a7c8e383

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