{ "info": { "author": "Michael Amrhein", "author_email": "michael@adrhinum.de", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Topic :: Software Development", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "The package `quantity` provides classes for unit-safe computations with\nquantities, including money.\n\nDefining a quantity class\n=========================\n\nA **basic** type of quantity is declared just by sub-classing the class\n`Quantity`:\n\n >>> class Length(Quantity):\n ... pass\n\nIn addition to the new quantity class the meta-class of class `Quantity`\ncreates a corresponding class for the units automatically. It can be\nreferenced via the quantity class:\n\n >>> Length.Unit\n \n\nIf the quantity has a unit which is used as a reference for defining other\nunits, the simplest way to define it is giving a name and a symbol for it as\nclass variables. The meta-class of class `Quantity` will then create a unit\nautomatically:\n\n >>> class Length(Quantity):\n ... refUnitName = 'Meter'\n ... refUnitSymbol = 'm'\n >>> Length.refUnit\n Length.Unit('m')\n\nNow, this unit can be given to create a quantity:\n\n >>> METER = Length.refUnit\n >>> print(Length(15, METER))\n 15 m\n\nOther units can be derived from the reference unit (or another unit), giving\na definition by multiplying a scaling factor with that unit:\n\n >>> MILLIMETER = Length.Unit('mm', 'Millimeter', Decimal('0.001') * METER)\n >>> MILLIMETER\n Length.Unit('mm')\n >>> KILOMETER = Length.Unit('km', 'Kilometer', 1000 * METER)\n >>> KILOMETER\n Length.Unit('km')\n >>> CENTIMETER = Length.Unit('cm', 'Centimeter', 10 * MILLIMETER)\n >>> CENTIMETER\n Length.Unit('cm')\n\nUsing one unit as a reference and defining all other units by giving\na scaling factor is only possible if the units have the same scale. Otherwise,\nunits have to be instantiated via the corresponding class `Unit` sub-class\nwithout giving a definition.\n\n >>> class Temperature(Quantity):\n ... pass\n >>> CELSIUS = Temperature.Unit('\u00b0C', 'Degree Celsius')\n >>> FAHRENHEIT = Temperature.Unit('\u00b0F', 'Degree Fahrenheit')\n\n**Derived** types of quantities are declared by giving a definition based on\nmore basic types of quantities:\n\n >>> class Volume(Quantity):\n ... defineAs = Length ** 3\n ... refUnitName = 'Cubic Meter'\n >>> class Duration(Quantity):\n ... refUnitName = 'Second'\n ... refUnitSymbol = 's'\n >>> class Velocity(Quantity):\n ... defineAs = Length / Duration\n ... refUnitName = 'Meter per Second'\n\nIf no symbol for the reference unit is given with the class declaration, a\nsymbol is generated from the definition, as long as all types of quantities\nin that definition have a reference unit.\n\n >>> print(Volume.refUnit.symbol)\n m\u00b3\n >>> print(Velocity.refUnit.symbol)\n m/s\n\nInstantiating quantities\n========================\n\nThe simplest way to create an instance of a class `Quantity` subclass is to\ncall the class giving an amount and a unit. If the unit is omitted, the\nquantity's reference unit is used (if one is defined).\n\n >>> Length(15, MILLIMETER)\n Length(Decimal(15), Length.Unit(u'mm'))\n\nAlternatively, the two-args infix operator '^' can be used to combine an\namount and a unit:\n\n >>> 17.5 ^ KILOMETER\n Length(Decimal('17.5'), Length.Unit(u'km'))\n\nAlso, it's possible to create a `Quantity` sub-class instance from a string\nrepresentation:\n\n >>> Length('17.5 km')\n Length(Decimal('17.5'), Length.Unit(u'km'))\n\nUnit-safe computations\n======================\n\nA quantity can be converted to a quantity using a different unit by calling\nthe method `Quantity.convert`:\n\n >>> l5cm = Length(Decimal(5), CENTIMETER)\n >>> l5cm.convert(MILLIMETER)\n Length(Decimal('50'), Length.Unit('mm'))\n >>> l5cm.convert(KILOMETER)\n Length(Decimal('0.00005'), Length.Unit('km'))\n\nQuantities can be compared to other quantities using all comparison operators\ndefined for numbers. Different units are taken into account automatically, as\nlong as they are compatible, i. e. a conversion is available:\n\n >>> Length(27) <= Length(91)\n True\n >>> Length(27, METER) <= Length(91, CENTIMETER)\n False\n\nQuantities can be added to or subtracted from other quantities \u2026:\n\n >>> Length(27) + Length(9)\n Length(Decimal(36))\n >>> Length(27) - Length(91)\n Length(Decimal(-64))\n >>> Length(27) + Length(12, CENTIMETER)\n Length(Decimal('27.12'))\n >>> Length(12, CENTIMETER) + Length(17, METER)\n Length(Decimal('1712'), Length.Unit('cm'))\n\n\u2026 as long as they are instances of the same quantity type:\n\n >>> Length(27) + Duration(9)\n quantity.quantity.IncompatibleUnitsError: Can't add a 'Length' and a\n 'Duration'\n\nQuantities can be multiplied or divided by scalars, preserving the unit:\n\n >>> 7.5 * Length(3, CENTIMETER)\n Length(Decimal('22.5'), Length.Unit(u'cm'))\n >>> Duration(66, MINUTE) / 11\n Duration(Decimal(6), Duration.Unit(u'min'))\n\nQuantities can be multiplied or divided by other quantities \u2026:\n\n >>> Length(15, METER) / Duration(3, SECOND)\n Velocity(Decimal(5))\n\n\u2026 as long as the resulting type of quantity is defined \u2026:\n\n >>> Duration(4, SECOND) * Length(7)\n UndefinedResultError: Undefined result: Duration * Length\n\n\u2026 or the result is a scalar:\n\n >>> Duration(2, MINUTE) / Duration(50, SECOND)\n Decimal('2.4')\n\nMoney\n=====\n\nMoney is a special type of quantity. Its unit type is known as currency.\n\nMoney differs from physical quantities mainly in two aspects:\n\n* Money amounts are discrete. For each currency there is a smallest fraction\n that can not be split further.\n\n* The relation between different currencies is not fixed, instead, it varies\n over time.\n\nThe sub-package `quantity.money` provides classes and functions to deal\nwith these specifics.\n\nA currency must explicitly be registered as a unit for further use. The\neasiest way to do this is to call the function `registerCurrency`. The\nfunction is backed by a database of currencies defined in ISO 4217. It takes\nthe 3-character ISO 4217 code as parameter.\n\n`Money` derives from `Quantity`, so all operations on quantities can also be\napplied to instances of `Money`. But because there is no fixed relation\nbetween currencies, there is no implicit conversion between money amounts of\ndifferent currencies. Resulting values are always quantized to the smallest\nfraction defined with the currency.\n\nA conversion factor between two currencies can be defined by using the\nclass `ExchangeRate`. It is given a unit currency (aka base currency), a unit\nmultiple, a term currency (aka price currency) and a term amount, i.e. the\namount in term currency equivalent to unit multiple in unit currency.\n\nMultiplying an amount in some currency with an exchange rate with the same\ncurrency as unit currency results in the equivalent amount in term currency.\nLikewise, dividing an amount in some currency with an exchange rate with the\nsame currency as term currency results in the equivalent amount in unit\ncurrency.\n\nAs `Money` derives from `Quantity`, it can be combined with other quantities\nin order to define a new quantity. This is, for example, useful for defining\nprices per quantum.\n\nFor more details see the documentation provided with the source distribution\nor `here `_.\n\nHistory\n=======\n\n=========== ==================================================================\nVersion Changes\n=========== ==================================================================\n0.9.0 Converters raise new exception 'UnitConversionError' instead of\n returning None.\n Changed priority of converters: they are tried in *reversed* order\n of registration.\n Added 'MoneyConverter' ('quantity.money.converter.py').\n\n0.8.1 Refactored class 'Term'.\n Some bug fixes.\n\n0.8.0 Exceptions raised by Quantity.__new__ changed to QuantityError.\n Added function 'generateUnits'.\n Added sub-package 'money'.\n\n0.7.3 Added function 'sum'.\n Added method 'Quantity.allocate'.\n\n0.7.2 Prevent __dict__ from being built for subclasses of Quantity or\n Unit.\n Made 'refUnitSymbol' and 'refUnitName' read-only properties.\n Added class property 'quantum' as option to define quantized\n quantities.\n Removed '__version__' from all sub-modules.\n\n0.7.1 Added 'install_requires' to setup.py.\n Corrected unit of 'Kelvin' in doc and README.\n Added method 'Quantity.quantize'.\n Enhanced method 'Quantity.__round__': round to quantity or unit.\n\n0.7.0 First public release.\n=========== ==================================================================", "description_content_type": null, "docs_url": "https://pythonhosted.org/quantity/", "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://pypi.python.org/pypi/quantity", "keywords": "quantity quantities unit units money currency exchange", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "quantity", "package_url": "https://pypi.org/project/quantity/", "platform": "all", "project_url": "https://pypi.org/project/quantity/", "project_urls": { "Homepage": "https://pypi.python.org/pypi/quantity" }, "release_url": "https://pypi.org/project/quantity/0.9/", "requires_dist": null, "requires_python": "", "summary": "Unit-safe computations with quantities (including money)", "version": "0.9" }, "last_serial": 1862354, "releases": { "0.7.0": [ { "comment_text": "", "digests": { "md5": "146b8c39d097a9c8ef2c1cb8a361fbda", "sha256": "5e5d82178405d54cae619d96ac9d60b2ac7ac823cb80dfaf00645ededd5436fe" }, "downloads": -1, "filename": "quantity-0.7.0.tar.gz", "has_sig": false, "md5_digest": "146b8c39d097a9c8ef2c1cb8a361fbda", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 324004, "upload_time": "2015-01-12T18:24:51", "url": "https://files.pythonhosted.org/packages/e9/b6/390e3d99b9feb86cbafe54721ff4c0ccc6860f23941093cf4e44d62f930a/quantity-0.7.0.tar.gz" } ], "0.7.3": [ { "comment_text": "", "digests": { "md5": "dcb0882a75b2e0322093b4afce36d2d4", "sha256": "da6ae5411d3879c1ae8fa53cb0d7e5e85cb794475e9cb6b373be2343f0a316a5" }, "downloads": -1, "filename": "quantity-0.7.3.tar.gz", "has_sig": false, "md5_digest": "dcb0882a75b2e0322093b4afce36d2d4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 428371, "upload_time": "2015-04-03T22:21:57", "url": "https://files.pythonhosted.org/packages/f0/a8/66847603142610ce1d5ba3cf48c197fed4cc9df64a512ca33c043b7ed907/quantity-0.7.3.tar.gz" } ], "0.8": [ { "comment_text": "", "digests": { "md5": "b488132a9046cb902c642c8f65858fce", "sha256": "4025d0d24170ce26c8a0e9f33f8ec16deb8ab359192deadb024bbebaaad7985d" }, "downloads": -1, "filename": "quantity-0.8.tar.gz", "has_sig": false, "md5_digest": "b488132a9046cb902c642c8f65858fce", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 468204, "upload_time": "2015-06-14T13:59:01", "url": "https://files.pythonhosted.org/packages/34/af/037be2367e757c7812e3de4e84d49083eced4dc62d719bc65e7955139cce/quantity-0.8.tar.gz" } ], "0.9": [ { "comment_text": "", "digests": { "md5": "e19eda2963d9b84d2181b4b072a31fc9", "sha256": "62eba09eaf5cc61448f9575b7d6a953c32e9634025a86060754cc588ae9b78c4" }, "downloads": -1, "filename": "quantity-0.9.tar.gz", "has_sig": false, "md5_digest": "e19eda2963d9b84d2181b4b072a31fc9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 288219, "upload_time": "2015-12-14T21:40:32", "url": "https://files.pythonhosted.org/packages/45/3b/39ed8cf2673c94ed92a50add8e8917e5cf692c76bc614505ab5c95cfecde/quantity-0.9.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e19eda2963d9b84d2181b4b072a31fc9", "sha256": "62eba09eaf5cc61448f9575b7d6a953c32e9634025a86060754cc588ae9b78c4" }, "downloads": -1, "filename": "quantity-0.9.tar.gz", "has_sig": false, "md5_digest": "e19eda2963d9b84d2181b4b072a31fc9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 288219, "upload_time": "2015-12-14T21:40:32", "url": "https://files.pythonhosted.org/packages/45/3b/39ed8cf2673c94ed92a50add8e8917e5cf692c76bc614505ab5c95cfecde/quantity-0.9.tar.gz" } ] }