Wednesday, October 19, 2011

PyCurrency - a simple currency conversion solution for python

I needed a way to add currency conversions to some code, in the past I used a script that retrieved yahoo currency exchange data in csv format and stored the exchange rates. This time around I wanted something  simpler, and since I couldn't find anything, I wrote it myself.

I've just released an alpha version of PyCurrency. The code is embarrassingly horrible, the doctests pass and most importantly it works for me. The idea is to create a wrapper around Google's currency conversion features.

To get started install it using easy_install or pip:
easy_install pycurrency
Usage is pretty straight forward. Below is an example of how you would convert 1 US Dollar to Jamaican Dollars:

>>> from pycurrency import converter
>>> myconverter = converter.Converter(1,'USD','JMD')
>>> myconverter.result() 

Once instantiated, a converter object can be loaded with new currencies and amounts and the result recalculated. For more information visit:

The source is managed using mercurial and housed at


Yannig said...

Thanks for this, at the end of you could add:

def convert(amount,from_cur,to_cur):
return Converter(amount,from_cur,to_cur).result()

It would then be natural to do conversions on the fly from Ipython:

In [2]: from pycurrency.converter import convert

In [3]: convert(125,'EUR','GBP')
Out[3]: 109.50426400000001

David said...

I've implemented the convert method, so now you can do your 'on the fly' conversions.

Yannig said...

@David That's brilliant, thanks.

David Bain said...

Due to the shutdown of iGoogle, pycurrency version 1.x no longer works. I'm busy assessing an appropriate way to make a 2.0 version based on

Yannig said...

Thank you, I stil use it from time to time.

Sign up for my upcoming Plone 5 Book & Video tutorials

plone 5 for newbies book and videos