Convert a Price from USD to EUR in Python

Allowing for instant price conversions within your website or programs will improve both user experience and system processing for international clients. This API will allow you to convert prices between different currencies like USD and EUR using constantly updating exchange rate data. To use this function, you will need to input the source currency code (i.e. USD), the destination (i.e. EUR), and the source price.

Image for post
Image for post

We will first need 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.
source_price = 1.2 # float | Input price, such as 19.99 in source currency
try:
# Converts a price from the source currency into the destination currency
api_response = api_instance.currency_exchange_convert_currency(source, destination, source_price)
pprint(api_response)
except ApiException as e:
print("Exception when calling CurrencyExchangeApi->currency_exchange_convert_currency: %s\n" % e)

With this, you can instantly convert prices for international currency with the most current exchange rate data. You can get your free API Key from the Cloudmersive website. This will give 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