{ "info": { "author": "Carlos Palol", "author_email": "carlos.palol@awarepixel.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Topic :: Software Development :: Libraries" ], "description": "\n============\nPython Money\n============\n\nMoney class with optional CLDR-backed locale-aware formatting and an extensible currency exchange solution.\n\n.. RADAR: version\n\n**This is version 1.3.0**.\n\n:Development: https://github.com/carlospalol/money\n:Latest release: https://pypi.python.org/pypi/money/\n\nThis package is compatible with Python 2.7, 3.4, 3.5 (tested in 2.7.11, 3.4.4, 3.5.1), but there are important `Differences between Python versions`_. All code examples use Python 3.x.\n\n**Contents**\n\n.. contents::\n :local:\n :backlinks: none\n\n\nInstallation\n============\n\nInstall the latest release with:\n\n::\n\n pip install money\n\nFor locale-aware formatting, also install the latest version of `Babel `_ (2.2 or higher required):\n\n::\n\n pip install babel\n\n\nUsage\n=====\n\n.. code:: python\n\n >>> from money import Money\n >>> m = Money(amount='2.22', currency='EUR')\n >>> m\n EUR 2.22\n\n*amount* can be any valid value in ``decimal.Decimal(value)`` and *currency* should be a three-letter currency code. Money objects are immutable by convention and hashable. Once created, you can use read-only properties ``amount`` (decimal.Decimal) and ``currency`` (str) to access its internal components:\n\n.. code:: python\n\n >>> m = Money(2, 'USD')\n >>> m.amount\n Decimal('2')\n >>> m.currency\n 'USD'\n\nMoney emulates a numeric type and you can apply most arithmetic and comparison operators between money objects, as well as addition, subtraction, and division with integers (int) and decimal numbers (decimal.Decimal):\n\n.. code:: python\n\n >>> m = Money('2.22', 'EUR')\n >>> m / 2\n EUR 1.11\n >>> m + Money('7.77', 'EUR')\n EUR 9.99\n\nMore formally, with *AAA* and *BBB* being different currencies:\n\n+-----------+---------------+-----------+-----------+-----------------+\n| | Operator | Money AAA | Money BBB | int, Decimal |\n+===========+===============+===========+===========+=================+\n| **Money | ``+``, ``-`` | Money | N/A | Money |\n+ AAA** +---------------+-----------+-----------+-----------------+\n| | ``*`` | N/A | N/A | Money |\n+ +---------------+-----------+-----------+-----------------+\n| | ``/``, ``//`` | Decimal | N/A | Money |\n+ +---------------+-----------+-----------+-----------------+\n| | ``>``, ``>=`` | Compares | N/A | N/A |\n| | ``<``, ``<=`` | amount. | | |\n+ +---------------+ +-----------+-----------------+\n| | ``==`` | | False | False |\n| | | | | |\n+-----------+---------------+-----------+-----------+-----------------+\n\nArithmetic operations with floats are not directly supported. If you need to operate with floats, you must first convert the float to a Decimal, or the Money object to a float (i.e. float(m)). Please be aware of the `issues and limitations of floating point arithmetics `_.\n\n\nCurrency presets\n----------------\n\nIf you use fixed currencies in your code, you may find convenient to create currency-preset Money subclasses:\n\n.. code:: python\n\n class EUR(Money):\n def __init__(self, amount='0'):\n super().__init__(amount=amount, currency='EUR')\n \n price = EUR('9.99')\n\n\nFormatting\n==========\n\nMoney objects are printed by default with en_US formatting and the currency code.\n\n.. code:: python\n\n >>> m = Money('1234.567', 'EUR')\n >>> str(m)\n 'EUR 1,234.57'\n\nUse ``format(locale=LC_NUMERIC, pattern=None, currency_digits=True, format_type='standard')`` for locale-aware formatting with currency expansion. ``format()`` relies on ``babel.numbers.format_currency()``, and **requires Babel** 2.2 or higher to be installed.\n\n.. code:: python\n\n >>> m = Money('1234.567', 'USD')\n >>> m.format('en_US')\n '$1,234.57'\n >>> m.format('es_ES')\n '1.234,57\\xa0$'\n\nThe character ``\\xa0`` is an unicode non-breaking space. If no locale is passed, Babel will use your system's locale. You can also provide a specific pattern to format():\n\n.. code:: python\n\n >>> m = Money('-1234.567', 'USD')\n >>> # Regular US format:\n >>> m.format('en_US', '\u00a4#,##0.00') \n '-$1,234.57'\n >>> # Custom negative format:\n >>> m.format('en_US', '\u00a4#,##0.00;<\u00a4#,##0.00>')\n '<$1,234.57>'\n >>> # Spanish format, full currency name:\n >>> m.format('es_ES', '#,##0.00 \u00a4\u00a4\u00a4')\n '-1.234,57 d\u00f3lares estadounidenses'\n >>> # Same as above, but rounding (overriding currency natural format):\n >>> m.format('es_ES', '#0 \u00a4\u00a4\u00a4', currency_digits=False)\n '-1235 d\u00f3lares estadounidenses'\n\nFor more details on formatting see `Babel docs on currency formatting `_. To learn more about the formatting pattern syntax check out `Unicode TR35 `_.\n\nCurrency exchange\n=================\n\nCurrency exchange works by \"installing\" a **backend** class that implements the abstract base class (`abc `_) ``money.exchange.BackendBase``. Its API is exposed through ``money.xrates``, along with setup functions ``xrates.install(pythonpath)``, ``xrates.uninstall()``, and ``xrates.backend_name``.\n\nA simple proof-of-concept backend ``money.exchange.SimpleBackend`` is included:\n\n.. code:: python\n\n from decimal import Decimal\n from money import Money, xrates\n\n xrates.install('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.to('AAA') == Money('1.25', 'AAA')\n\n\n\nXMoney\n======\n\nYou can use ``money.XMoney`` (a subclass of Money), for automatic currency conversion while adding, subtracting, and dividing money objects (+, +=, -, -=, /, //). This is useful when aggregating lots of money objects with heterogeneous currencies. The currency of the leftmost object has priority.\n\n.. code:: python\n\n from money import XMoney\n \n # Register backend and rates as above...\n \n a = XMoney(1, 'AAA')\n b = XMoney(1, 'BBB')\n \n assert sum([a, b]) == XMoney('1.25', 'AAA')\n\n\nExceptions\n==========\n\nFound in ``money.exceptions``.\n\n``MoneyException(Exception)``\n Base class for all exceptions.\n\n``CurrencyMismatch(MoneyException, ValueError)``\n Thrown when mixing different currencies, e.g. ``Money(2, 'EUR') + Money(2, 'USD')``. Money objects must be converted first to the same currency, or XMoney could be used for automatic conversion.\n\n``InvalidOperandType(MoneyException, TypeError)``\n Thrown when attempting invalid operations, e.g. multiplication between money objects.\n\n``ExchangeError(MoneyException)``\n Base class for exchange exceptions.\n\n``ExchangeBackendNotInstalled(ExchangeError)``\n Thrown if a conversion is attempted, but there is no backend available.\n\n``ExchangeRateNotFound(ExchangeError)``\n The installed backend failed to provide a suitable exchange rate between the origin and target currencies.\n\n\nHierarchy\n---------\n\n* ``MoneyException``\n * ``CurrencyMismatch``\n * ``InvalidOperandType``\n * ``ExchangeError``\n * ``ExchangeBackendNotInstalled``\n * ``ExchangeRateNotFound``\n\n\n\n.. _python-differences:\n\nDifferences between Python versions\n===================================\n\n.. list-table::\n :header-rows: 1\n :stub-columns: 1\n \n * - Expression\n - Python 2.x\n - Python 3.x\n \n * - ``round(Money('2.5', 'EUR'))``\n - Returns ``3.0``, a **float** rounded amount **away from zero**.\n - Returns ``EUR 2``, a **Money object** with rounded amount to the **nearest even**.\n \n * - ``Money('0', 'EUR').amount < '0'``\n - Returns ``True``. This is the weird but expected behaviour in Python 2.x when comparing Decimal objects with non-numerical objects (Note the '0' is a string). `See note in docs `_.\n - TypeError: unorderable types: decimal.Decimal() > str()\n\n\n\nDesign decisions\n================\n\nThere are several design decisions in *money* that differ from currently available money class implementations:\n\nLocalization\n------------\n\nDo not keep any kind of locale conventions database inside this package. Locale conventions are extensive and change over time; keeping track of them is a project of its own. There is already such a project and database (the Unicode Common Locale Data Repository), and an excellent python API for it: `Babel `_.\n\nCurrency\n--------\n\nThere is no need for a currency class. A currency is fully identified by its ISO 4217 code, and localization or exchange rates data are expected to be centralized as databases/services because of their changing nature.\n\nAlso:\n\n+ **Modulo operator (%)**: do not override to mean \"percentage\".\n+ **Numeric type**: you **can** mix numbers and money in binary operations, and objects evaluate to False if their amount is zero.\n+ **Global default currency**: subclassing is a safer solution.\n\n\nContributions\n=============\n\nContributions are welcome. You can use the `regular github mechanisms `_.\n\nTo be forward-compatible, and given the small size of the package, Python 2.7 is supported in a different source \"branch\" at ``src-py2``.\n\nTo test your changes you will need `tox `_ and python 2.7, 3.4, and 3.5. Simply cd to the package root (by setup.py) and run ``tox``.\n\n\nLicense\n=======\n\nmoney is released under the **MIT license**, which can be found in the file ``LICENSE``.\n\n\n\n\n", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/carlospalol/money", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "money", "package_url": "https://pypi.org/project/money/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/money/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/carlospalol/money" }, "release_url": "https://pypi.org/project/money/1.3.0/", "requires_dist": null, "requires_python": null, "summary": "Python Money Class", "version": "1.3.0" }, "last_serial": 2068236, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "574d8cad90a8ae85041e3051ce5ae6dc", "sha256": "243e2ac425e762c80e579e97ff3e6f35bee170d10e4b3027e498a3e9991361e4" }, "downloads": -1, "filename": "money-1.0.tar.gz", "has_sig": false, "md5_digest": "574d8cad90a8ae85041e3051ce5ae6dc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9776, "upload_time": "2013-11-25T14:45:43", "url": "https://files.pythonhosted.org/packages/ff/14/3c1d7b6d61cdcff9258e14824d98025c3df0517ef74cf1f9464f91720ad2/money-1.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "d89daa8524d2bc9cb7baf3d2ab112a63", "sha256": "70d33d5284c3794454d5727a277328bfae87ad542bdf5f2a05b0468d4b80e4a4" }, "downloads": -1, "filename": "money-1.0.1.tar.gz", "has_sig": false, "md5_digest": "d89daa8524d2bc9cb7baf3d2ab112a63", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6448, "upload_time": "2013-11-25T14:51:39", "url": "https://files.pythonhosted.org/packages/1c/a1/699b5b02222a7a03b18bac038d3aab702db548417d6598bb346289e6116f/money-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "cb1701ecbffb9ddf33d996b851da72d1", "sha256": "f789d6a44d78e735b8552787c5b5f6dbca4069b1f431010354fb1fcd2e1ea2e4" }, "downloads": -1, "filename": "money-1.0.2.tar.gz", "has_sig": false, "md5_digest": "cb1701ecbffb9ddf33d996b851da72d1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6445, "upload_time": "2013-11-25T14:56:05", "url": "https://files.pythonhosted.org/packages/80/c3/7c7109a89e7a9387bb94c1f80a50b9091bca7f05e29f43871b78585960dc/money-1.0.2.tar.gz" } ], "1.0b1": [ { "comment_text": "", "digests": { "md5": "822bb81fdbec068037c56dade3afdc77", "sha256": "fc6038a2172ea96fd2d52f591459022c57055a6b4a42a749bd878826ed389126" }, "downloads": -1, "filename": "money-1.0b1.tar.gz", "has_sig": false, "md5_digest": "822bb81fdbec068037c56dade3afdc77", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9622, "upload_time": "2013-11-16T05:58:08", "url": "https://files.pythonhosted.org/packages/07/e2/8a1c16d2446510f066004af69594e0b8b05625b6f43d7bb921d7b2cffdee/money-1.0b1.tar.gz" } ], "1.0b2": [ { "comment_text": "", "digests": { "md5": "9e6a96e60a5b6c61e80b6dc2090a688e", "sha256": "ec9daa4386a3a8bd981099e71969ff7602698fe1e7e967cd7495ddd13ea58883" }, "downloads": -1, "filename": "money-1.0b2.tar.gz", "has_sig": false, "md5_digest": "9e6a96e60a5b6c61e80b6dc2090a688e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9782, "upload_time": "2013-11-18T01:11:17", "url": "https://files.pythonhosted.org/packages/fa/36/f00035b59d1e034ce8ee1cb2a834548663d9412c15004d44bb7cd37a49ea/money-1.0b2.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "0a82860ecbd9e2ba5ad25b4b4a0c7419", "sha256": "7cf438b622a515c9b54a85fbd105549a5268db1a8b522a67f4a7efc188b10688" }, "downloads": -1, "filename": "money-1.1.0.tar.gz", "has_sig": false, "md5_digest": "0a82860ecbd9e2ba5ad25b4b4a0c7419", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16289, "upload_time": "2014-04-01T16:36:53", "url": "https://files.pythonhosted.org/packages/f0/68/6c067b4ee2a802554870da4d0442191ed1d3a21c82648e0ee2ab0f244aff/money-1.1.0.tar.gz" } ], "1.1.1": [ { "comment_text": "", "digests": { "md5": "6cc944f8a0e84f5639f365e882322139", "sha256": "07a200a308bead1db9cc1d248152c57675858cf48a6efb884a9b383ecfbbfbfe" }, "downloads": -1, "filename": "money-1.1.1.tar.gz", "has_sig": false, "md5_digest": "6cc944f8a0e84f5639f365e882322139", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16471, "upload_time": "2014-06-15T22:48:28", "url": "https://files.pythonhosted.org/packages/2b/61/b62cee408d71e8de569c6bd7d6fc382e35bb528794bf7d0d43956abe89c6/money-1.1.1.tar.gz" } ], "1.2.0": [ { "comment_text": "", "digests": { "md5": "4d095d66d0dcbd1b260fb3bb7593a29d", "sha256": "3ece814f3bda710a09e1cc21849931b94e1279bcaa592ceddcf5dee4b3cfe87e" }, "downloads": -1, "filename": "money-1.2.0.tar.gz", "has_sig": false, "md5_digest": "4d095d66d0dcbd1b260fb3bb7593a29d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16496, "upload_time": "2014-04-30T16:06:37", "url": "https://files.pythonhosted.org/packages/61/69/4cbd5706b480b8de0bb64584d36a31a2ccc5edeeb6f198a28687b683fe82/money-1.2.0.tar.gz" } ], "1.2.1": [ { "comment_text": "", "digests": { "md5": "c435b9b0f6dcab6e2fcae2e6acb7bb9d", "sha256": "aca3040747cc2f1b3402e16d476861217c7dbcb96e62ebac4905aa8b22df9032" }, "downloads": -1, "filename": "money-1.2.1.tar.gz", "has_sig": false, "md5_digest": "c435b9b0f6dcab6e2fcae2e6acb7bb9d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16554, "upload_time": "2014-06-15T19:07:58", "url": "https://files.pythonhosted.org/packages/0c/e3/bb161867ff2b1f89f45aa6994753d1d38237753fde735f747a3d15c1cb2e/money-1.2.1.tar.gz" } ], "1.2.2": [ { "comment_text": "", "digests": { "md5": "c8c44fa7c469a91a5bf33e5b4f4ac197", "sha256": "c8619a9a40a317cb8a9c7af9951d56452b75d1a41834994502171c1935dbe99d" }, "downloads": -1, "filename": "money-1.2.2.tar.gz", "has_sig": false, "md5_digest": "c8c44fa7c469a91a5bf33e5b4f4ac197", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16653, "upload_time": "2015-06-09T15:53:21", "url": "https://files.pythonhosted.org/packages/71/d4/c6994f3b91e9278036bdef7866d0c54c3c8c6fa25ab75d599b3ba966069f/money-1.2.2.tar.gz" } ], "1.2.3": [ { "comment_text": "", "digests": { "md5": "5284cdfe1caad9907e1efa011a41c350", "sha256": "c813e30c41154893918d5bc15998b734cba724796968c3e79f071ba6ec6fc9b9" }, "downloads": -1, "filename": "money-1.2.3.tar.gz", "has_sig": false, "md5_digest": "5284cdfe1caad9907e1efa011a41c350", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16870, "upload_time": "2016-04-17T13:48:46", "url": "https://files.pythonhosted.org/packages/9c/12/5e4621a5319cbfa4dcbaed2f30c193d012bf9b02901fe9d08152eca35b0e/money-1.2.3.tar.gz" } ], "1.3.0": [ { "comment_text": "", "digests": { "md5": "d7330de2580356124f463737079dc400", "sha256": "ac049caf19df9502f7a481d5959fc51b038baaa68c5dcef2070ffbb785729f7d" }, "downloads": -1, "filename": "money-1.3.0.tar.gz", "has_sig": false, "md5_digest": "d7330de2580356124f463737079dc400", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18369, "upload_time": "2016-04-17T13:42:31", "url": "https://files.pythonhosted.org/packages/52/9f/642ef475b58588ce28ea93ed370075dcf1ee801bbc764e1adb4c1f2f2235/money-1.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d7330de2580356124f463737079dc400", "sha256": "ac049caf19df9502f7a481d5959fc51b038baaa68c5dcef2070ffbb785729f7d" }, "downloads": -1, "filename": "money-1.3.0.tar.gz", "has_sig": false, "md5_digest": "d7330de2580356124f463737079dc400", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18369, "upload_time": "2016-04-17T13:42:31", "url": "https://files.pythonhosted.org/packages/52/9f/642ef475b58588ce28ea93ed370075dcf1ee801bbc764e1adb4c1f2f2235/money-1.3.0.tar.gz" } ] }