Fetch Live Cricket Scores and ICC Rankings from Cricket API Using Python

Vasudevan Swornampillai
3 min readFeb 21, 2024

--

Image of stumps and ball

Cricket is not everything, not by any means, but it is a large part of who I am.

—MS Dhoni

Cricket is a popular sport followed by millions of fans around the world. Staying updated with live scores and player rankings is essential for cricket enthusiasts. This article presents a Python script that utilizes the Cricket API to fetch live cricket scores and ICC rankings.

Introduction to Cricket API

The Cricket API offers a variety of endpoints to access different types of cricket data.It also provides comprehensive coverage of cricket matches, scores, and statistics.

Workflow Diagram

The workflow diagram displayed below demonstrates how to Fetch Live Cricket Scores and ICC Rankings from Cricket API Using Python.

Workflow diagram to fetch cricket scores and ICC rankings from Cricket API

Fetching Live Scores

The Python script uses the requests library to make HTTP requests to the Cricket API endpoint for live scores. The retrieved JSON data is then parsed and formatted for easy display. The script outputs the latest news with their headline, intro & publication time.

#Fetch Live Scores

import requests
import json

print("1-News , 2- ICC Rankings")
val = input(">")
if val == "1":
url = "https://unofficial-cricbuzz.p.rapidapi.com/news/list"

headers = {
"X-RapidAPI-Key": "enter your api key here",
"X-RapidAPI-Host": "unofficial-cricbuzz.p.rapidapi.com"
}

response = requests.get(url, headers=headers)
API_data = response.json()


for i in range(len(API_data['newsList'])):

print(API_data['newsList'][i])

Fetching ICC Rankings

Another endpoint provided by the Cricket API allows the script to fetch ICC rankings for various formats of the game, including Tests, ODIs, and T20Is. The script retrieves the rankings for batsmen, bowlers, and all-rounders, showcasing the player positions, names, teams, and ratings.

# Fetch ICC Rankings

elif val == "2":

url = "https://unofficial-cricbuzz.p.rapidapi.com/stats/get-icc-rankings"

querystring = {"category":"batsmen","formatType":"test","isWomen":"0"}

headers = {
"X-RapidAPI-Key": "enter your api key here",
"X-RapidAPI-Host": "unofficial-cricbuzz.p.rapidapi.com"
}

response = requests.get(url, headers=headers, params=querystring)

data = response.json()

for player in data['rank']:
print("ID :",player['id'])
print("Rank :",player['rank'])
print("Name :",player['name'])
print("Country :",player['country'])
print("Ratings :",player['rating'])
print("---------------------------------------------------------------")

Final Result

For fetching ICC rankings feature,

Image of final result of fetching ICC rankings

For fetching Cricket News,

Image of final result of fetching latest cricket news from cricket API

Benefits of using the Script

This Python script offers several benefits for cricket fans:

  • Real-time updates: Provides live cricket scores as matches progress.
  • Comprehensive rankings: Displays ICC rankings for different formats and categories.
  • Easy integration: Can be integrated into other Python projects or scripts.
  • Customization: Allows users to tailor the script to their specific needs.

Getting Started

To use the script, ensure you have Python 3.6 or higher and the requests library installed. Copy and paste the script into a Jupyter notebook or Python IDE and run each cell to fetch live scores and ICC rankings.

Conclusion

This article demonstrated how to leverage the Cricket API using Python to fetch live cricket scores and ICC rankings. The provided script offers a convenient way to stay updated on the latest cricket matches and player rankings. By utilizing the Cricket API and Python, cricket enthusiasts can access a wealth of cricket data and enhance their overall experience of the sport.You can get the Python codes for these API integrations from my GitHub.

Cheers!

--

--