Python code examples
The following code examples demonstrate the Python interaction with the API.
All examples also expect your
API key.
Example 1
Get the exchange rate between two currencies
import requests
response = requests.get(
'http://jsonrates.com/get/?'+
'from=USD'+
'&to=EUR'
)
json = response.json()
rate = float(json['rate'])
Example 2
Convert an amount from one into another currency
import requests
response = requests.get(
'http://jsonrates.com/convert/?'+
'from=USD'+
'&to=EUR'+
'&amount=2.99'
)
json = response.json()
amount = float(json['amount'])
Example 3
Get historical exchange rates between two currencies for three days
import requests
response = requests.get(
'http://jsonrates.com/historical/?'+
'from=USD'+
'&to=EUR'+
'&dateStart=2014-06-25'+
'&dateEnd=2014-06-27'
)
json = response.json()
for date, values in json['rates'].iteritems():
histrate = float(values['rate'])