Provides Currency and Money classes for use in your Python code.
Project description
The need to represent instances of money frequently arises in software development, particularly any financial/economics software. To address that need, the py-moneyed package provides the classes of Money and Currency, at a level more useful than just using Python’s Decimal class, or ($DEITY forbid) the float primitive. The package is meant to be stand-alone and easy to either use directly, or subclass further. py-moneyed is BSD-licensed.
Some of the py-moneyed code was first derived from python-money available via this URL: http://code.google.com/p/python-money/ Because that Google Code version has been inactive since May 2008, I forked it and modified it for my needs in 2010. Compared to python-money, major changes here in py-moneyed include separating it from Django usage, tightening types handling in operators, a complete suite of unit tests, PEP8 adherence, providing a setup.py, and local currency formatting/display.
Usage
On to the code! The Money class is instantiated with:
An amount which can be of type string, float, or Decimal.
A currency, which usually is specified by the three-capital-letters ISO currency code, e.g. USD, EUR, CNY, and so on.
For example,
from moneyed.classes import Money
sale_price_today = Money(amount='99.99', currency='USD')
The Money class also provides operators with type checking, matching currency checking, and sensible dimensional behavior, e.g. you cannot multiply two Money instances, nor can you add a Money instance to a non-Money number; dividing a Money instance by another results in a Decimal value, etc.
The Currency class is provided with a complete dictionary of ISO 4217 currencies data, each key (e.g. ‘USD’) mapping to a Currency instance with ISO numeric code, canonical name in English, and countries using the currency. Thanks to the python-money developers for their (possibly tedious) data-entry of the ISO codes!
Testing
Unit-tests have been provided, and can be run with tox (recommended) or just py.test.
If you don’t have tox installed on your system, it’s a modern Python tool to automate running tests and deployment; install it to your global Python environment with:
sudo pip install tox
Then you can activate a virtualenv (any will do - by design tox will not run from your globally-installed python), cd to the py-moneyed source directory then run the tests at the shell:
cd where/py-moneyed-source/is tox
If you do not have all versions of Python that are used in testing, you can use pyenv. After installing pyenv, install the additional plugin pyenv-implict.
The py-moneyed package has been tested with Python 2.6, 2.7, 3.2, 3.3 and PyPy 2.1.
Future
Future versions of py-moneyed may provide currency conversions or other capabilities, dependent on feedback and usage.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file py-moneyed-0.5.0.tar.gz
.
File metadata
- Download URL: py-moneyed-0.5.0.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06cea60bffbdb8116688d305e8d645a2c32beef88d310d9b32382fd43edf88e6 |
|
MD5 | 6d6eebb6b8936054d0fdde6646c871aa |
|
BLAKE2b-256 | 11bb46287952823ccf6ed90618eb17ef6f37ffa1b1a70e6a8093436b9ffea176 |
File details
Details for the file py_moneyed-0.5.0-py2.7.egg
.
File metadata
- Download URL: py_moneyed-0.5.0-py2.7.egg
- Upload date:
- Size: 31.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f44797ed0147fb9eb51c65d4f715c0f02c9c772db8401186b84bdf9fb02a4b05 |
|
MD5 | 749c7e67efc325fff39e47ed2cf37aad |
|
BLAKE2b-256 | 641a28b7565ae93bd0b573c687a3b2b5e15fab3646dee5db42e513c24a4dbf35 |