Currency Exchange Project (Intro blog coming soon!) is a small project created by a group of junior programmers aiming to build a Python application that integrates APIs, frameworks, and potentially other technologies. The goal here is to gain a better understanding of workflows commonly used in the ‘developer world’.

This project serves as a great learning opportunity for our future, including GitHub repositories and blog posts.

Before diving into our code, let’s first explain some key terminology. ʕっ•ᴥ•ʔっ

What is an API?

An API (Application Programming Interface) is a way for different software or services to communicate. It works like a waiter in a restaurant, taking requests, delivering them to the system, and returning a response. 

For example, when using Google Maps, the app sends a request to Google’s API, which retrieves the necessary data and sends it back for display.

APIs exist in many forms, some follow established standards like HTTP, while others extend or build upon these, such as REST. Creating an API can involve anything from defining custom protocols and data structures to developing simple interfaces for utility libraries. In web applications, APIs commonly serve as the connection points between various underlying services.

In basic terms is API broadly refers to the code used to interact with a library or service.  Typically, users only need to know how to use it, not how it operates internally

How do we import it? 

First, let’s check what version of python we have, we do this by (in bash)

‘py –version’

We can see the output being ‘python 3.13.1’, basically meaning python3. Now knowing that we can do the next step

Since we are using python we have to ensure that we have installed some API tools within our systems. The command we do this is the following (this would depend on your device):

‘Py -m pip install requests’

You know it would work through a lot of output of ‘downloading’ stuff. If it doesn’t, you already have it, or your command is a little different due to a different system/ terminal. Google is your best friend there. 

Now we need to create a virtual environment for our project. We do this by typing:

‘py -m venv venv’

The reason we do this is to ensure that each project has its own virtual environment, keeping it separate from other projects. Without a virtual environment, all dependencies would be installed globally, which can lead to conflicts if different projects require different versions of the same package. This can cause interference and potentially break everything.

With  Linux users, installing packages globally can be risky because the operating system relies on Python internally. Modifying system-wide Python packages could disrupt essential system functions.

As a best practice, always create a virtual environment for every project, whether it’s a personal or group project. This keeps dependencies organised, prevents conflicts, and ensures a stable development environment.

Next let’s import the library at the top of the page. We do this by typing:

‘Import requests’

For our project, we would be importing JSON, making it easy to parse and extract the required currency rates. We do this by:

‘Import json’

Importing API

Now, we need to store the API in a variable so that we can call it easily instead of pasting that long link everywhere it’s needed. Since the project heavily relies on this API, it would be used everywhere!

  • currency_value_API – Stores the URL of an API that provides real-time currency exchange rates (in JSON format. In this case, it fetches exchange rates for EUR (Euro) against other currencies.)

Printing API

Now, let’s print the contents. First, I will fetch the data from the API, then convert it into JSON format, and finally print it to the console. Easy, innit!

 This is what i have come up with:

‘all_currencies_response = requests.get(currency_value_API)’

  • This sends a request to the API to get the latest currency exchange rates.
  • The response is stored in all_currencies_response.

‘currency_data = all_currencies_response.json()’

  • The API sends data in text format, so .json() converts it into a Python dictionary.
  • This makes it easier to use and process in the program.

‘print(json.dumps(currency_data, indent=4))’

  • The data is formatted nicely using json.dumps(), adding indentation (spaces) for better readability.
  • print() then displays the currency exchange rates clearly.

This is the result:

We can see that using the json has formatted the code quite nicely and in a readable manner. And it wasn’t so hard to do it. 

Next we might learn how to print/ search for specific currencies and have a better understanding of the first pull request of the project . Now let’s code ‘em all! ʕ -ᴥ•ʔ♡

Credits 

Resources

+

Leave a comment