Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install py-moneyed

How to install py-moneyed

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install py-moneyed
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.4
0.4.1Never BuiltWhy not?
0.4 Available View build log
0.3 Failed View build log
Windows (64-bit)
0.4
0.4.1Never BuiltWhy not?
0.4 Available View build log
0.3 Failed View build log
Mac OS X (10.5+)
0.4
0.4.1Never BuiltWhy not?
0.4 Available View build log
0.3 Failed View build log
Linux (32-bit)
0.4
0.4.1Never BuiltWhy not?
0.4 Available View build log
0.3 Failed View build log
Linux (64-bit)
0.4.1 Available View build log
0.4 Available View build log
0.3 Failed View build log
 
Author
License
BSD
Dependencies
Imports
Lastest release
version 0.4.1 on Jan 9th, 2014

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

The py-moneyed package has been tested with Python 2.6; it should work with Python 2.x but I haven't tried other versions yet. Should you use py-moneyed with other Python versions, please let me know if you are successful or not.

Future

Future versions of py-moneyed may provide currency conversions or other capabilities, dependent on feedback and usage.

Subscribe to package updates

Last updated Jan 9th, 2014

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.