{ "info": { "author": "Rui Pereira", "author_email": "r4g3baby@gmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython" ], "description": "# money-lib\n\n![PyPI - Version](https://img.shields.io/pypi/v/money-lib.svg)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/money-lib.svg)\n![PyPI - License](https://img.shields.io/pypi/l/money-lib.svg)\n\nPython 3 money lib with decimal precision and currency exchange support.\n\n## Installation\n\nInstall the latest release with:\n```\npip install money-lib\n```\n\n## Usage\n\nA Currency object can be created with a *currency_code* (must be a string and valid ISO 4217 format: `^[A-Z]{3}$`).\n\n```python\n>>> from money import Currency\n>>> currency = Currency('USD')\n>>> currency\nCurrency('USD')\n```\n\nA Money object can be created with an *amount* (can be any valid value in `decimal.Decimal(value)`) and a *currency* (can be a string or a `Currency(code)` object).\n\n```python\n>>> from money import Money\n>>> money = Money('7.37', 'USD')\n>>> money\nMoney(Decimal('7.37'), 'USD')\n```\n\nMoney objects are immutable by convention and hashable. Once created, you can use read-only properties *amount* (decimal.Decimal) and *currency* (Currency) to access its internal components.\nThe *amount* property returns the amount rounded to the correct number of decimal places for the currency.\n\n```python\n>>> money = Money('6.831', 'USD')\n>>> money.amount\nDecimal('6.83')\n>>> money.currency\nCurrency('USD')\n```\n\nMoney can apply most arithmetic and comparison operators between money objects, integers (int) and decimal numbers (decimal.Decimal).\n\n```python\n>>> money = Money('5', 'USD')\n>>> money / 2\nMoney(Decimal('2.5'), 'USD')\n>>> money + Money('10', 'USD')\nMoney(Decimal('15'), 'USD')\n```\n\nAll comparison and arithmetic operators support automatic currency conversion as long as you have a [currency exchange backend](#currency-exchange) setup.\nThe currency of the leftmost object has priority.\n\n```python\n# Assuming the rate from USD to EUR is 2\n>>> money = Money('7.50', 'USD')\n>>> money + Money('5', 'EUR')\nMoney(Decimal('10.00'), 'USD')\n```\n\nMoney supports formatting for different locales.\n```python\n>>> money = Money('13.65', 'USD')\n>>> money.format()\n'$13.65'\n>>> money.format('pt_PT')\n'13,65 US$'\n```\n\n## Currency exchange\n\nCurrency exchange works by setting a backend class that implements the abstract base class `money.exchange.BaseBackend`.\nIts API is exposed through `money.xrates`, along with `xrates.backend` and `xrates.backend_name`.\n\nA simple proof-of-concept backend `money.exchange.SimpleBackend` is included.\n\n```python\n>>> from decimal import Decimal\n>>> from money import Money, xrates\n\n>>> xrates.backend = 'money.exchange.SimpleBackend'\n>>> xrates.base = 'USD'\n>>> xrates.setrate('AAA', Decimal('2'))\n>>> xrates.setrate('BBB', Decimal('8'))\n\n>>> a = Money('1', 'AAA')\n>>> b = Money('1', 'BBB')\n\n>>> assert a.to('BBB') == Money('4', 'BBB')\n>>> assert b.to('AAA') == Money('0.25', 'AAA')\n>>> assert a + b == Money('1.25', 'AAA')\n```\n\n## Django integration\n\nModel fields usage:\n\n```python\n>>> from django.db import models\n>>> from money import fields, Money\n\n>>> class Product(models.Model):\n... price = fields.MoneyField(max_digits=19, decimal_places=4, default=Money('10', 'USD'))\n```\n\nModel queries usage:\n\n```python\n# MoneyField creates another field (MoneyField name + '_currency') to store the currency\n>>> Product.objects.create(price=Money('10', 'USD'))\n>>> Product.objects.create(price='10', price_currency='USD')\n\n# Get all products where price is greater than 4 and the currency equals 'USD'\n>>> product = Product.objects.filter(price__gt=4, price_currency='USD').first()\n>>> product.price\nMoney(Decimal('10.0000'), 'USD')\n```\n\n## Credits\n\nCurrency exchange support based on https://github.com/carlospalol/money.\n\nDjango model multiple database columns by [miracle2k](https://blog.elsdoerfer.name/2008/01/08/fuzzydates-or-one-django-model-field-multiple-database-columns/).\n\nCurrency data and formatting is powered by [Babel](http://babel.pocoo.org).\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://gitlab.com/R4G3_BABY/money-lib", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "money-lib", "package_url": "https://pypi.org/project/money-lib/", "platform": "", "project_url": "https://pypi.org/project/money-lib/", "project_urls": { "Homepage": "https://gitlab.com/R4G3_BABY/money-lib" }, "release_url": "https://pypi.org/project/money-lib/2.1.0/", "requires_dist": [ "Babel (>=2.5.0)", "Django (>=2.0) ; extra == 'django'" ], "requires_python": ">=3", "summary": "Python 3 money lib with decimal precision and currency exchange support.", "version": "2.1.0" }, "last_serial": 5174054, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "c800b45b7a44b4d76c46a3fa6b54551c", "sha256": "db680b9ee801e7fc90080b8982284a0749ff4fa2ddadbe6163e227a6b45bb4da" }, "downloads": -1, "filename": "money_lib-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "c800b45b7a44b4d76c46a3fa6b54551c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3", "size": 9578, "upload_time": "2018-08-10T03:32:47", "url": "https://files.pythonhosted.org/packages/d8/de/c0171b70eeb03922c4ba4f3e12e8ebc34d594731adf71d0d3a09592395c3/money_lib-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b522500b79af9664acb852e52c296239", "sha256": "0a43e567fe228fa9866a94a6a952401929d024433bf876543bffcf6cba259412" }, "downloads": -1, "filename": "money-lib-1.0.0.tar.gz", "has_sig": false, "md5_digest": "b522500b79af9664acb852e52c296239", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 9979, "upload_time": "2018-08-10T03:32:48", "url": "https://files.pythonhosted.org/packages/a5/c2/50f8fb2fc0aa01e72d0a04be855fe783cc17083011277a190964bd9ae851/money-lib-1.0.0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "df4e3ba183695435de2ac2f1652fe0e0", "sha256": "f81356bae6f2bf476734e2abce8aa33f31d0aa653b1a3fafea423f7d900ec6dd" }, "downloads": -1, "filename": "money_lib-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "df4e3ba183695435de2ac2f1652fe0e0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3", "size": 6161, "upload_time": "2018-08-10T22:16:12", "url": "https://files.pythonhosted.org/packages/75/12/e6dfbda46ae6c30cc9889419be034d9408e8fe6a9445e2b7ed2038edf52b/money_lib-1.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2ed563cfcac65f2f867f8ad2f9960246", "sha256": "ba1c918094e1a03ccc68a96dbf5ab8079ecca8bfd2ed152eec968999a81d6271" }, "downloads": -1, "filename": "money-lib-1.1.0.tar.gz", "has_sig": false, "md5_digest": "2ed563cfcac65f2f867f8ad2f9960246", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 5062, "upload_time": "2018-08-10T22:16:14", "url": "https://files.pythonhosted.org/packages/a4/34/d0343644bbcf45c6df7ea5c541c9ce92d8181ac32c3dfd0a9b2f6e548abf/money-lib-1.1.0.tar.gz" } ], "2.0.0": [ { "comment_text": "", "digests": { "md5": "aabd66fab0abc5e40b370e3711702071", "sha256": "3a1168cef0df2fe2d084525d2bccd1b2f9714afc0833c5daf48e7b53889282fe" }, "downloads": -1, "filename": "money_lib-2.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "aabd66fab0abc5e40b370e3711702071", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3", "size": 6881, "upload_time": "2019-04-10T22:51:31", "url": "https://files.pythonhosted.org/packages/4e/59/92d98802c7fc46abeca14fafc59b7e493d9d600dfca4ba3272c46cdc3e66/money_lib-2.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5363f5b4940ba57d50ebd96a3a8385a0", "sha256": "7562108e41cdc94cb4c333d3cd3d23ff0694f26514bb70015398adcd5edfdcad" }, "downloads": -1, "filename": "money-lib-2.0.0.tar.gz", "has_sig": false, "md5_digest": "5363f5b4940ba57d50ebd96a3a8385a0", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 4943, "upload_time": "2019-04-10T22:51:32", "url": "https://files.pythonhosted.org/packages/f9/7c/21207428ff585f56642e59808b20af37479a8080bc231dc83c06c3ec31f1/money-lib-2.0.0.tar.gz" } ], "2.1.0": [ { "comment_text": "", "digests": { "md5": "2c3d98c204052225702ebcc9a74eb2ca", "sha256": "40e8d745e8ad5cb3bbd2fcc0d84a57c721cc0ee192bd8cb6baa9c0c2f09a25a2" }, "downloads": -1, "filename": "money_lib-2.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "2c3d98c204052225702ebcc9a74eb2ca", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3", "size": 9276, "upload_time": "2019-04-22T18:49:13", "url": "https://files.pythonhosted.org/packages/3f/32/518ad4aa0dd0167696f087bccb1add777d309f69d3310103572afcd6c96a/money_lib-2.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8daf1839e62887986a48a807a6e9f428", "sha256": "59b2878fab7895efb3486a44976cef06e95fed3668343c847a5648e93b5bb48b" }, "downloads": -1, "filename": "money-lib-2.1.0.tar.gz", "has_sig": false, "md5_digest": "8daf1839e62887986a48a807a6e9f428", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 7318, "upload_time": "2019-04-22T18:49:14", "url": "https://files.pythonhosted.org/packages/ee/cc/198d8b8403db4afaed13eaa4c214cf0b7a313dc3f6951359c89b599ae83f/money-lib-2.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2c3d98c204052225702ebcc9a74eb2ca", "sha256": "40e8d745e8ad5cb3bbd2fcc0d84a57c721cc0ee192bd8cb6baa9c0c2f09a25a2" }, "downloads": -1, "filename": "money_lib-2.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "2c3d98c204052225702ebcc9a74eb2ca", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3", "size": 9276, "upload_time": "2019-04-22T18:49:13", "url": "https://files.pythonhosted.org/packages/3f/32/518ad4aa0dd0167696f087bccb1add777d309f69d3310103572afcd6c96a/money_lib-2.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8daf1839e62887986a48a807a6e9f428", "sha256": "59b2878fab7895efb3486a44976cef06e95fed3668343c847a5648e93b5bb48b" }, "downloads": -1, "filename": "money-lib-2.1.0.tar.gz", "has_sig": false, "md5_digest": "8daf1839e62887986a48a807a6e9f428", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 7318, "upload_time": "2019-04-22T18:49:14", "url": "https://files.pythonhosted.org/packages/ee/cc/198d8b8403db4afaed13eaa4c214cf0b7a313dc3f6951359c89b599ae83f/money-lib-2.1.0.tar.gz" } ] }