Skip to content

Get Free Crude Oil Prices API In Python

Using this free API, you can get rates for any commodity you want. It’s safe and can give you the result in different programming languages, like Python and JSON.

Crude oil is and has always been one of the most essential commodities worldwide. It is a fossil fuel that is processed into usable products like gasoline, diesel, and other petrochemicals. Crude oil is a nonrenewable resource, meaning it cannot be regenerated naturally at the rate at which people consume it, making it a finite resource.

To know the prices of this commodity, it’s really useful to use an API, which is an interface that connects two websites, computers, or applications, among others, and allows them to communicate with each other. When you send a request to an API, you get an instant answer. Often, an API gives you the information in a programming language. So, if you’re trying to obtain free crude oil prices API in Python, you should keep this in mind: 

Get Free Crude Oil Prices API In Python

Why Python?

Python is an interpreted high-level general-purpose programming language. Is commonly used in the construction of websites and software, as well as task automation, data analysis, and data visualization. Its design philosophy promotes code readability with extensive indentation. Its language features and object-oriented approach are intended to help programmers write clear, logical code for small and large-scale projects alike.

How Can You Get This Information?

To get an API you need to use a software that allows you to make API calls. For this, we highly recommend Commodities-API, which is a free public API that provides commodity pricing for a wide range of commodities such as coffee, rice, sugar, and wheat. Commodities-API supports over 170 currencies and provides data with a 2 decimal point precision. 

To utilize it, go to this page, sign in, and receive an API key, after which you may pick the currency and commodity of interest. The program will then provide you with the data you want, and you may modify the API any way you see fit. 

Get Free Crude Oil Prices API In Python

The Python information will look like this:

import requests

    base_currency = ‘USD’

    symbol = ‘BRENTOIL’ 

    endpoint = ‘latest’

    access_key = ‘API_KEY’

    resp = requests.get(

        ‘https://commodities-api.com/api/’+endpoint+’?access_key=’+access_key+’&base=’+base_currency+’&symbols=’+symbol)

    if resp.status_code != 200:

        # This means something went wrong.

        raise ApiError(‘GET /’+endpoint+’/ {}’.format(resp.status_code))

    print(resp.json())

Commodities-API provides midpoint data for all commodities and currency rates. The midpoint rate is determined by taking the average median rate of Bid and Ask for a certain time period. The same API endpoints are used in Commodities-API to convert currency and commodity prices, and they may be used to convert any amount from one currency to another, any commodity to any commodity, and any currency to any currency.

Another Option

If Commodities-API doesn’t match your expectations, you can also use Barchart, a global financial technology leader that provides market data and services to the financial, media, and commodities industries. To obtain the information, go to https://www.barchart.com/.


Also published on Medium.

Published inAppsTechnology
%d bloggers like this: