Skip to main content
Money Parser
============


Description
-----------

Money Parser is a price and currency parsing utility.
It provides methods to extract price and currency information from the raw string.
There is a lot of different price and currency formats that present values with separators, spacing etc.
This library may help you to parse such data.


Limitation
----------

- currency with 3 numbers after decimal point (e.g. KWD, see `ISO 4217`_)


Introduction
------------

Extracting price from raw ``str``::

>>> from money_parser import price_str
>>> price_str('₹1,50,087.99 \n')
'150087.99'
>>> price_dec('+12.007')
Decimal('12007')

Installation
------------

::

$ pip install money-parser

The library requires Python >= 3.4


Documentation
------------------

.. py:function:: price_str(raw_price, [default=<not_defined>], [dec_point='.'])

Search and clean price value.

Convert raw price string presented in any localization
as a valid number string with an optional decimal point.

If raw price does not contain valid price value or contains
more than one price value, then return default value.
If default value not set, then raise ValueError.

:param str raw_price: string that contains price value.
:param default: value that will be returned if raw price not valid.
:param dec_point: symbol that separate integer and fractional parts.
:return: cleaned price string or default value.
:raise ValueError: error if raw price not valid and default value not set.

::

>>> price_str('+12.007')
'12007'
>>> price_str('- 520,05')
'-520.05'
>>> price_str('1,000,777.5')
'1000777.5'
>>> price_str('1.777.000,99')
'1777000.99'
>>> price_str('99,77,11,000.1')
'997711000.1'
>>> price_str('USD 5,242 \t\n')
'5242'
>>> price_str('90 210.42', dec_point='|')
'90210|42'
>>> price_str(None, default='0')
'0'
>>> price_str(42.333, default=None) is None
True
>>> price_str(None)
Traceback (most recent call last):
...
ValueError: Wrong raw price type "<class 'NoneType'>" (expected type "str")
>>> price_str('')
Traceback (most recent call last):
...
ValueError: Raw price value "" does not contain valid price digits
>>> price_str('1..2')
Traceback (most recent call last):
...
ValueError: Raw price value "1..2" contains more than one price value


.. py:function:: price_dec(raw_price, [default=<not_defined>])

Price decimal value from raw string.

Extract price value from input raw string and
present as Decimal number. Uses a price_str function for price parsing.

If raw price does not contain valid price value or contains
more than one price value, then return default value.
If default value not set, then raise ValueError.

:param str raw_price: string that contains price value.
:param default: value that will be returned if raw price not valid.
:return: Decimal price value.
:raise ValueError: error if raw price not valid and default value not set.

::

>>> price_dec('+12.007')
Decimal('12007')
>>> price_dec(': -10.99$')
Decimal('-10.99')
>>> price_dec('', default=Decimal('0'))
Decimal('0')
>>> price_dec('1..10', default=0)
0
>>> price_dec('410.5 - 555', default=None) is None
True
>>> price_dec(42.3)
Traceback (most recent call last):
...
ValueError: Wrong raw price type "<class 'float'>" (expected type "str")
>>> price_dec('free')
Traceback (most recent call last):
...
ValueError: Raw price value "free" does not contain valid price digits
>>> price_dec('2+2')
Traceback (most recent call last):
...
ValueError: Raw price value "2+2" contains more than one price value


Run Tests
------

Project has tests::

$ make test

Also available tests with coverage::

$ make cov


Source code
-----------

The project is hosted on GitHub_


Authors and License
-------------------

The ``money-parser`` package is written by Serhii Kostel.

It's *Apache 2* licensed and freely available.


.. _`ISO 4217`: https://en.wikipedia.org/wiki/ISO_4217
.. _GitHub: https://github.com/kserhii/money-parser

CHANGES
=======

0.0.1 (2017-12-17)
------------------

* The first release.

Metadata

Release files for money-parser 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for money-parser 0.0.1
File Size Uploaded Provenance
money-parser-0.0.1.tar.gz 9.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for money-parser 0.0.1
File Interpreter ABI Platform
money_parser-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.9 kB

Release files / money-parser-0.0.1.tar.gz

Download URL money-parser-0.0.1.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
91fb362ba851d0e789586b6a7aec39df0ee1dcb594e50e2bc60d76b90fc1f764
BLAKE2b-256 checksum
How to use checksums
6bfdf69add6f634dc586d92a2671280d7258f86c0e12f9b03d1f1a04be6c3d85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / money_parser-0.0.1-py3-none-any.whl

Download URL money_parser-0.0.1-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
93b4f312f214c54d6474052816c3ecaa8dd67a403e18d18c9001c8f4e4b8f67a
BLAKE2b-256 checksum
How to use checksums
d8c8abf8b7bf6d216c8ed23a8427b7f7db221027254d4ca3e906ac4c6b6d2195
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for money-parser 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page