Last time I used something with Yahoo! Finance was almost four years ago, showing in Conky using just a Bash script.

yahoo-finance is a Python library for accessing finanical data via Yahoo! Finance API for stock markets or currency, etc. Here is an example for Yahoo’s own stock, from README:


>>> from yahoo_finance import Share
>>> yahoo = Share('YHOO')
>>> print yahoo.get_open()
36.60
>>> print yahoo.get_price()
36.84
>>> print yahoo.get_trade_datetime()
2014-02-05 20:50:00 UTC+0000
>>> yahoo.refresh()
>>> print yahoo.get_price()
36.87
>>> print yahoo.get_trade_datetime()
2014-02-05 21:00:00 UTC+0000

Historial data is retrievable in list of dict by dates:


>>> from pprint import pprint
>>> pprint(yahoo.get_historical('2014-04-25', '2014-04-29'))
[{u'Adj_Close': u'35.83',
u'Close': u'35.83',
u'Date': u'2014-04-29',
u'High': u'35.89',
u'Low': u'34.12',
u'Open': u'34.37',
u'Symbol': u'YHOO',
u'Volume': u'28720000'},
{u'Adj_Close': u'33.99',
u'Close': u'33.99',
u'Date': u'2014-04-28',
u'High': u'35.00',
u'Low': u'33.65',
u'Open': u'34.67',
u'Symbol': u'YHOO',
u'Volume': u'30422000'},
{u'Adj_Close': u'34.48',
u'Close': u'34.48',
u'Date': u'2014-04-25',
u'High': u'35.10',
u'Low': u'34.29',
u'Open': u'35.03',
u'Symbol': u'YHOO',
u'Volume': u'19391100'}]

There is also company information available for use:


>>> pprint(yahoo.get_info())
{u'FullTimeEmployees': u'12200',
u'Industry': u'Internet Information Providers',
u'Sector': u'Technology',
u'end': u'2014-05-03',
u'start': u'1996-04-12',
u'symbol': u'YHOO'}

It has almost 30 functions to retrieve sorts of data of shares, such as get_dividend_share() or get_market_cap(). Another section of this library is accessing currency data, for example, Euro to Polish Zloty currency exchance, from README:


>>> from yahoo_finance import Currency
>>> eur_pln = Currency('EURPLN')
>>> print eur_pln.get_bid()
4.2007
>>> print eur_pln.get_ask()
4.2091
>>> print eur_pln.get_rate()
4.2049
>>> print eur_pln.get_trade_datetime()
2014-03-05 11:23:00 UTC+0000
>>> eur_pln.refresh()
>>> print eur_pln.get_rate()
4.2052
>>> print eur_pln.get_trade_datetime()
2014-03-05 11:27:00 UTC+0000

yahoo-finance is written by Lukasz Banasiak under the MIT License, currently version 1.0.1, for Python 2 only. It depends on pytz for timezone handling.