Statista does not allow for crawling systematically across our data. If you attempt to do so; we will disable your API key.

In the case where you want to show Statista content to your users based on a search query in a federated search system or intranet; this guide is for you.

This guide will use the Discovery Advanced API and requires an API Key.

Using Python, you’ll learn how to:

  1. Configure variables needed for HTTP client
  2. Execute an API query
  3. Render information returned back by the Statista API

1. Configure variables needed for HTTP client

You’ll connect to the API using a request header: x-api-key. In order to fetch content, you’ll need to decide which endpoint you want to request from; /statistics, /marketInsights, /studies or /infographics. See API Reference.

For this example we’ll fetch content from /statistics with two parameters.

import requests
import json
import pprint

base_url = "https://api.statista.ai/v1/statistics" # Alternate between endpoints as needed
headers = {"x-api-key": "<YOUR_API_KEY>"}
params = {"q": "basketball", "limit": "5"} # Using the URL parameters available on the API. See API Reference.

This is the basic setup you’ll need to get this example running on your machine - we don’t recommend using this code in production.

2. Execute an API query

Next, we can execute a request and get a response from the API.

response = requests.get(base_url, headers=headers, params=params) # Fetch data

print(response.status_code) # Check if request was successful

data = json.loads(response.text) # Load raw data as JSON
pprint.pp(data)

3. Render information returned back by the Statista API

While you can do this in a multitude of ways; we’ll show an example for putting the received data into a pandas data frame - and show you what that looks like:

import pandas as pd


df = pd.json_normalize(data['items'])
pprint.pp(df)

Which yields a structured table:

IndexIDTitleSubjectPremiumDescriptionLinkDateSourcesChargersGeolocationsIndustriesPlatformTeaser Image URLImage URLXLS FilePDF File
0910248South Korea: total WKBL basketball games attendance 2023Total number of spectators in the Women’s Korean Basketball LeagueTrueIn 2023 in South Korea, over 93 thousand people attended…Link2024-08-26T12:00:00ZMinistry of Culture, Sports and Tourism (MOT)Ministry of Culture, Sports and Tourism (MOT)Korea, SouthBasketballenImageDownloadDownloadDownload
1910245South Korea: total KBL attendance 2023Total number of spectators in the Korean Basketball LeagueTrueIn 2023, around 690 thousand people attended…Link2024-08-26T12:00:00ZMinistry of Culture, Sports and Tourism (MOT)Ministry of Culture, Sports and Tourism (MOT)Korea, SouthBasketballenImageDownloadDownloadDownload
2193467Total NBA league revenue 2024National Basketball Association total league revenueTrueDuring the 2023/24 season, the 30 franchise teams in the NBA generated…Link2024-10-24T12:00:00ZForbesForbesUnited StatesBasketballenImageDownloadDownloadDownload
3910300South Korea: KBL games number 2023Number of matches in the Korean Basketball LeagueTrueIn South Korea in 2023, there were a total of 54 games in the…Link2024-08-26T12:00:00ZMinistry of Culture, Sports and Tourism (MOT)Ministry of Culture, Sports and Tourism (MOT)Korea, SouthBasketballenImageDownloadDownloadDownload
4193503Average revenue of NBA teams 2024National Basketball Association average revenue by teamTrueDuring the 2023/24 season, the average revenue for NBA teams reached approximately…Link2024-10-24T12:00:00ZStatistaForbes, StatistaUnited StatesBasketballenImageDownloadDownloadDownload

(See API Reference for more info on what data is available)