
Currency is one of the significant critical components in international trade and finances. It has become crucial for individuals to have avenues for exchanging and converting currencies. Here in this brief tutorial, you will learn how to create a currency conversion API web app using Python Flask and integrating an API.
If you are looking for the best currency APIs for your website or application, the CurrencyLayer API is the best option for Real-time exchange rates and conversion services.
With just one universal exchange rate API, you can access 168 world currencies and precious metals.
- Reliable Forex Rates
- Accurate Exchange Rates for 168 World Currencies with data updates ranging from every 60 minutes down to stunning 60 seconds.
- Easy-to-integrate API
- Delivered in portable JSON format for maximum usability, ease of integration, and compatibility with any of your applications.
- Advanced Features
- Gain access to historical rates, have our API convert single amounts for you, get a currency’s change parameters, switch Source Currency, etc.

Table of Contents
Can I Empower Apps With Forex Data?
CurrencyLayer API Forex data powers currency converters, mobile apps, and office systems worldwide. You can easily integrate the service into any application you have. Here are examples of how you can get the data.
Do You Need More On API Endpoints?
The CurrencyLayer API offers up to 5 customizable endpoints, all of which provide different kinds of data. Below you will find a summary of all available endpoints.

Moreover, you can specify
For both live and historical rates, you may limit your API request to a set of specific currencies by attaching the currencies parameter followed by any available 3-letter currency codes of your choice.

Here is a response example that you can get:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
{ "success": true, "terms": "https://currencylayer.com/terms", "privacy": "https://currencylayer.com/privacy", "timestamp": 1430068515, "source": "USD", "quotes": { "USDAUD": 1.278384, "USDCHF": 0.953975, "USDEUR": 0.919677, "USDGBP": 0.658443, "USDPLN": 3.713873 } } |
How To Create A Python Flask App?
We build a Python Flask web app that utilizes this CurrencyLayer API. By this, you can learn how to integrate and interact with the endpoints.
Start your PowerShell or Bash and type these commands to create a new folder and initialize a new Python Flask application.
1 2 3 4 5 6 7 8 |
0. mkdir PythonFlaskDemo 1. cd PythonFlaskDemo 2. touch app.py 3. py -m venv env 4. env\Scripts\activate 5. pip install flask 6. pip install requests 7. set FLASK_APP=app.py |
Here I’m using VS Code to code, and we have already opened it with the “code .” command. Now copy this source code to your app.py and use HTML web pages for data representation (you can find them from this GitHub repository [1])
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
from flask import Flask, request, redirect, url_for import requests app = Flask(__name__) @app.route('/') def hello_world(): # put application's code here return 'Hello World!' @app.route('/result/<string:usd_aud>/<string:usd_eur>/<string:usd_gbp>') def result_realtime(usd_aud, usd_eur, usd_gbp): return "<h3>USDAUD: {}; <br>USDEUR: {}; <br>USDGBP: {}</h3>".format(usd_aud, usd_eur, usd_gbp) @app.route('/rtrates', methods=['GET', 'POST']) def rtrates(): if request.method == 'GET': return '''<h1>Please fill out the parameters</h1> <form method="POST" action="/rtrates"> <input type="text" name="acc_key" value="c92b0e664f8dd7743333fed2f42fd6c9"> <input type="text" name="currencies" value="AUD,EUR,GBP"> <input type="submit" value="Request"> </form>''' else: acc_key = request.form['acc_key'] currencies = request.form['currencies'] req = requests.get('https://api.currencylayer.com/live?access_key=' + acc_key + '¤cies=' + currencies) response = req.json() usd_aud = response['quotes']['USDAUD'] usd_eur = response['quotes']['USDEUR'] usd_gbp = response['quotes']['USDGBP'] return redirect(url_for('result_realtime', usd_aud=usd_aud, usd_eur=usd_eur, usd_gbp=usd_gbp)) @app.route('/result/<string:from_c>/<string:to_c>/<string:amount>/<string:quote>/<string:result>') def result_conversion(from_c, to_c, amount, quote, result): return "<h3>From: {}; <br>To: {}; <br>Amount: {}; <br> Result: {}; <br> Quote: {};</h3>" \ .format(from_c, to_c, amount, result, quote) @app.route('/conversion', methods=['GET', 'POST']) def conversion(): if request.method == 'GET': return '''<h1>Please fill out the parameters</h1> <form method="POST" action="/conversion"> <input type="text" name="acc_key" value="c92b0e664f8dd7743333fed2f42fd6c9"> <input type="text" name="from" value="from"> <input type="text" name="to" value="to"> <input type="text" name="amount" value="amount"> <input type="submit" value="Request"> </form>''' else: acc_key = request.form['acc_key'] from_c = request.form['from'] to_c = request.form['to'] amount = request.form['amount'] req = requests.get( 'https://api.currencylayer.com/convert?access_key=' + acc_key + '&from=' + from_c + "&to=" + to_c + "&amount=" + amount) response = req.json() quote = response['info']['quote'] result = response['result'] return redirect( url_for('result_conversion', from_c=from_c, to_c=to_c, amount=amount, quote=quote, result=result)) if __name__ == '__main__': app.run() |
As you can see, we have two simple endpoint calling functions and two functions to represent the received data to the user. It is straightforward. It gets the submitted data, builds up a URL string, and sends it as a request.
How To Run Our CurrencyLayer API-based Flask Web Application?
Depending on the configuration of your system, you can run your Flask web application with these commands.

Demo in Action!



Get your free subscription API key right now! Head over to the CurrencyLayer!
[1] https://github.com/MuminjonGuru/CurrencyLayerWithFLask/blob/main/app.py