All Projects → kserhii → money-parser

kserhii / money-parser

Licence: Apache-2.0 license
Price and currency parsing utility

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to money-parser

Jackson Datatype Money
Extension module to properly support datatypes of javax.money
Stars: ✭ 165 (+534.62%)
Mutual labels:  money, currency
Guide-to-Swift-Numbers-Sample-Code
Xcode Playground Sample Code for the Flight School Guide to Swift Numbers
Stars: ✭ 92 (+253.85%)
Mutual labels:  money, currency
Cash Cli
💰💰 Convert currency rates directly from your terminal!
Stars: ✭ 168 (+546.15%)
Mutual labels:  money, currency
Ngx Currency
📦 Currency mask module for Angular
Stars: ✭ 161 (+519.23%)
Mutual labels:  money, currency
django-prices-openexchangerates
openexchangerates.org support for django-prices
Stars: ✭ 33 (+26.92%)
Mutual labels:  money, currency
Currency.js
A javascript library for handling currencies
Stars: ✭ 2,214 (+8415.38%)
Mutual labels:  money, currency
Prices
Python price handling for humans.
Stars: ✭ 248 (+853.85%)
Mutual labels:  money, currency
Frankfurter
💱 Currency data API
Stars: ✭ 123 (+373.08%)
Mutual labels:  money, currency
nova-money-field
Money Field for Laravel Nova
Stars: ✭ 71 (+173.08%)
Mutual labels:  money, currency
CurrencyEditText
A simple EditText input designed to input decimal and currency values.
Stars: ✭ 18 (-30.77%)
Mutual labels:  money, currency
Easymoney
Library for operating with monetary values in JavaScript and Typescript 💵
Stars: ✭ 145 (+457.69%)
Mutual labels:  money, currency
binarium
Binarium cryptocurrency is the first one protected from ASICs
Stars: ✭ 14 (-46.15%)
Mutual labels:  money, currency
Django Prices
Django fields for the prices module
Stars: ✭ 135 (+419.23%)
Mutual labels:  money, currency
pesa
A JS money lib whose precision goes up to 11 (and beyond).
Stars: ✭ 38 (+46.15%)
Mutual labels:  money, currency
Exchanger
🏢 Currency exchange rates framework for PHP
Stars: ✭ 133 (+411.54%)
Mutual labels:  money, currency
Jsr354 Ri
JSR 354 - Moneta: Reference Implementation
Stars: ✭ 223 (+757.69%)
Mutual labels:  money, currency
Money Open Exchange Rates
A gem that calculates the exchange rate using published rates from open-exchange-rates. Compatible with the money gem.
Stars: ✭ 87 (+234.62%)
Mutual labels:  money, currency
Javamoney Lib
JavaMoney financial libraries, extending and complementing JSR 354
Stars: ✭ 104 (+300%)
Mutual labels:  money, currency
Megacoin
Welcome to Megacoin MΣC - Around the World!
Stars: ✭ 16 (-38.46%)
Mutual labels:  money, currency
bankster
Money Creation Made Easy
Stars: ✭ 30 (+15.38%)
Mutual labels:  money, currency

Money Parser

https://api.travis-ci.org/kserhii/money-parser.svg?branch=master

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

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 str 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

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

The library uses Travis for Continuous Integration.

Authors and License

The money-parser package is written by Serhii Kostel.

It's Apache 2 licensed and freely available.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].