Retrieve the Exchange Rate Between USD and EUR in Python

When monetizing products or making strategic decisions for your organization’s international business dealings, it is integral to understand the exchange rates between your default currency and others. The following API will allow you to automatically retrieve the exchange rate data between a source and destination currency, with minimal input.

Image for post
Image for post

Our first step will be to install our SDK:

pip install cloudmersive-currency-api-client

Then, we can call our function:

from __future__ import print_function
import time
import cloudmersive_currency_api_client
from cloudmersive_currency_api_client.rest import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_currency_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = cloudmersive_currency_api_client.CurrencyExchangeApi(cloudmersive_currency_api_client.ApiClient(configuration))
source = 'source_example' # str | Source currency three-digit code (ISO 4217), e.g. USD, EUR, etc.
destination = 'destination_example' # str | Destination currency three-digit code (ISO 4217), e.g. USD, EUR, etc.
try:
# Gets the exchange rate from the source currency into the destination currency
api_response = api_instance.currency_exchange_get_exchange_rate(source, destination)
pprint(api_response)
except ApiException as e:
print("Exception when calling CurrencyExchangeApi->currency_exchange_get_exchange_rate: %s\n" % e)

Now, you can easily search and track exchange rates between specific currencies instantly. Retrieve your free API Key from Cloudmersive, giving you access to 800 monthly calls across our API library.

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store