Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
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.
ISO 4217
_)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')
::
$ pip install money-parser
The library requires Python >= 3.4
.. 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
Project has tests::
$ make test
Also available tests with coverage::
$ make cov
The project is hosted on GitHub_
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
FAQs
Price and currency parsing utility
We found that money-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.