real-money


Namereal-money JSON
Version 0.1.0 PyPI version JSON
download
home_page
SummaryMoney module for python
upload_time2023-08-28 11:24:14
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT
keywords money currency
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # real-money

[![Latest PyPI version](https://badge.fury.io/py/real-money.svg)](https://badge.fury.io/py/real-money)

Money class for Python 3.7 and higher. Forked from [py-money][]. It has been
forked as the original library seems unmantained, and some of the currencies
have changed since the last update.

Unlike other Python money classes, this class enforces that all monetary
amounts are represented with the correct number of decimal places for the
currency. For example, 3.678 USD is invalid, as is 5.5 JPY.

## Installation

Install the latest release with:

```sh
pip install real-money
```

If you want to have localised formatting, you should install with
[`Babel`][babel]:

```sh
pip install real-money[babel]
```

## Usage

A `Money` object can be created with an amount (specified as a string) and a
currency from the `Currency` class:

```python
from money import Currency, Money
m = Money("9.95", Currency.GBP)
m
# GBP 9.95
```

If you try to use more decimals than declared for the currency in the
[ISO 4217][] standard, it will throw an error:

```python
m = Money("4.624", Currency.EUR)
# InvalidAmountError: Invalid amount for currency
m = Money("1200.5", Currency.JPY)
# InvalidAmountError: Invalid amount for currency
```

`Money` objects can also be created from and converted to sub units:

```python
m = Money.from_sub_units(499, Currency.USD)
m
# USD 4.99
m.sub_units
# 499
```

`Money` is inmutable and supports most mathematical and logical operators:

```python
m = Money("10.00", Currency.USD)
m / 2
# USD 5.00
m + Money("3.00", Currency.USD)
# USD 13.00
m > Money("5.55", Currency.USD)
# True
m < Money("5.55", Currency.USD)
# False
```

`Money` will automatically round to the correct number of decimal places for
the currency:

```python
m = Money("9.95", Currency.EUR)
m * 0.15
# EUR 1.49
m = Money("10", Currency.JPY)
m / 3
# JPY 3
```

Money can be formatted for different locales (if you have `Babel`):

```python
Money("3.24", Currency.USD).format("en_US")
# $3.24
Money("9.95", Currency.EUR).format("es_ES")
# 9,95 €
Money("7.36", Currency.EUR).format("en_UK")
# £7.36
Money("94", Currency.JPY).format("ja_JP")
# ¥94
```

`Money` does not support conversion between currencies. Mathematical and
logical operations between two money objects are only allowed if both objects
are of the same currency. Otherwise, an error will be thrown:

```python
Money("1.25", Currency.USD) + Money("2", Currency.EUR)
# CurrencyMismatchError: Currencies must match
```

For more examples, check out the test file!

## Acknowledgements
`real-money` is a fork of [py-money][].

Much of the code is borrowed from [carlospalol/money][]. Much of the logic for
handling foreign currencies is taken from [sebastianbergmann/money][]. Money
formatting is powered by [Babel][babel].

[py-money]: https://github.com/vimeo/py-money
[babel]: https://babel.pocoo.org/en/latest/
[ISO 4217]: https://en.wikipedia.org/wiki/ISO_4217
[carlospalol/money]: https://github.com/carlospalol/money
[sebastianbergmann/money]: https://github.com/sebastianbergmann/money

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "real-money",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "money currency",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/60/8f/5bc2fec56710a5200a35f14b92146829578427c2cd43a6afad4d44265e4c/real-money-0.1.0.tar.gz",
    "platform": null,
    "description": "# real-money\n\n[![Latest PyPI version](https://badge.fury.io/py/real-money.svg)](https://badge.fury.io/py/real-money)\n\nMoney class for Python 3.7 and higher. Forked from [py-money][]. It has been\nforked as the original library seems unmantained, and some of the currencies\nhave changed since the last update.\n\nUnlike other Python money classes, this class enforces that all monetary\namounts are represented with the correct number of decimal places for the\ncurrency. For example, 3.678 USD is invalid, as is 5.5 JPY.\n\n## Installation\n\nInstall the latest release with:\n\n```sh\npip install real-money\n```\n\nIf you want to have localised formatting, you should install with\n[`Babel`][babel]:\n\n```sh\npip install real-money[babel]\n```\n\n## Usage\n\nA `Money` object can be created with an amount (specified as a string) and a\ncurrency from the `Currency` class:\n\n```python\nfrom money import Currency, Money\nm = Money(\"9.95\", Currency.GBP)\nm\n# GBP 9.95\n```\n\nIf you try to use more decimals than declared for the currency in the\n[ISO 4217][] standard, it will throw an error:\n\n```python\nm = Money(\"4.624\", Currency.EUR)\n# InvalidAmountError: Invalid amount for currency\nm = Money(\"1200.5\", Currency.JPY)\n# InvalidAmountError: Invalid amount for currency\n```\n\n`Money` objects can also be created from and converted to sub units:\n\n```python\nm = Money.from_sub_units(499, Currency.USD)\nm\n# USD 4.99\nm.sub_units\n# 499\n```\n\n`Money` is inmutable and supports most mathematical and logical operators:\n\n```python\nm = Money(\"10.00\", Currency.USD)\nm / 2\n# USD 5.00\nm + Money(\"3.00\", Currency.USD)\n# USD 13.00\nm > Money(\"5.55\", Currency.USD)\n# True\nm < Money(\"5.55\", Currency.USD)\n# False\n```\n\n`Money` will automatically round to the correct number of decimal places for\nthe currency:\n\n```python\nm = Money(\"9.95\", Currency.EUR)\nm * 0.15\n# EUR 1.49\nm = Money(\"10\", Currency.JPY)\nm / 3\n# JPY 3\n```\n\nMoney can be formatted for different locales (if you have `Babel`):\n\n```python\nMoney(\"3.24\", Currency.USD).format(\"en_US\")\n# $3.24\nMoney(\"9.95\", Currency.EUR).format(\"es_ES\")\n# 9,95 \u20ac\nMoney(\"7.36\", Currency.EUR).format(\"en_UK\")\n# \u00a37.36\nMoney(\"94\", Currency.JPY).format(\"ja_JP\")\n# \uffe594\n```\n\n`Money` does not support conversion between currencies. Mathematical and\nlogical operations between two money objects are only allowed if both objects\nare of the same currency. Otherwise, an error will be thrown:\n\n```python\nMoney(\"1.25\", Currency.USD) + Money(\"2\", Currency.EUR)\n# CurrencyMismatchError: Currencies must match\n```\n\nFor more examples, check out the test file!\n\n## Acknowledgements\n`real-money` is a fork of [py-money][].\n\nMuch of the code is borrowed from [carlospalol/money][]. Much of the logic for\nhandling foreign currencies is taken from [sebastianbergmann/money][]. Money\nformatting is powered by [Babel][babel].\n\n[py-money]: https://github.com/vimeo/py-money\n[babel]: https://babel.pocoo.org/en/latest/\n[ISO 4217]: https://en.wikipedia.org/wiki/ISO_4217\n[carlospalol/money]: https://github.com/carlospalol/money\n[sebastianbergmann/money]: https://github.com/sebastianbergmann/money\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Money module for python",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/Sighery/real-money"
    },
    "split_keywords": [
        "money",
        "currency"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "24774597a746bac26dee5b05d91928499494c8486485688f6ab7e5895509df3b",
                "md5": "c87399ecf2d2472126d01ae6c20faaec",
                "sha256": "688bc131c24e10e19e378e8099a17bbbf6b44817a63ebc914568cf0aa6930d2d"
            },
            "downloads": -1,
            "filename": "real_money-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c87399ecf2d2472126d01ae6c20faaec",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 10168,
            "upload_time": "2023-08-28T11:24:13",
            "upload_time_iso_8601": "2023-08-28T11:24:13.588748Z",
            "url": "https://files.pythonhosted.org/packages/24/77/4597a746bac26dee5b05d91928499494c8486485688f6ab7e5895509df3b/real_money-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "608f5bc2fec56710a5200a35f14b92146829578427c2cd43a6afad4d44265e4c",
                "md5": "f2814fa1355134d2c052395edbab32ed",
                "sha256": "55af3eb41e1766455c22321a5e73c3a5e3b9cbd158f2084460fa12fb4d75aa4d"
            },
            "downloads": -1,
            "filename": "real-money-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "f2814fa1355134d2c052395edbab32ed",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 14576,
            "upload_time": "2023-08-28T11:24:14",
            "upload_time_iso_8601": "2023-08-28T11:24:14.972944Z",
            "url": "https://files.pythonhosted.org/packages/60/8f/5bc2fec56710a5200a35f14b92146829578427c2cd43a6afad4d44265e4c/real-money-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-28 11:24:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Sighery",
    "github_project": "real-money",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "real-money"
}
        
Elapsed time: 0.28612s