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.1.tar.gz (16.8 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.1-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: parsimoney-0.1.1.tar.gz
  • Upload date:
  • Size: 16.8 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.1.tar.gz
Algorithm Hash digest
SHA256 3fd5057f85a99609267d81a252b168dca053df7956d0671329a98f6efe1cdba7
MD5 b5bfad332246d3c148425e59c4c4f597
BLAKE2b-256 afe2fda335ae044db237eb414d275ab9a48c8e7971a06b866ffb67307e768f40

See more details on using hashes here.

File details

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

File metadata

  • Download URL: parsimoney-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9de5dbaa04a980f210262ff2f860b88de0df66fa7ef032f6ab9e8bd56a03e0ed
MD5 959c657b9ed564a14ff69bec3ad0fd31
BLAKE2b-256 25e6c9b438e817abb7a17987f1599effd4b23f86e80a0eb99e399d0c12c0d153

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