Last modified: Nov 15, 2023 By Alexander Williams

Python: Get Movie and Series Ratings

Example 1: IMDbPY Library for IMDb Ratings


from imdb import IMDb

# Create an instance of IMDb
ia = IMDb()

# Search for a movie or series by title
result = ia.search_movie('Inception')

# Get the first result (assuming it's the correct one)
movie = ia.get_movie(result[0].movieID)

# Access the IMDb rating
imdb_rating = movie.data['rating']
print(f"IMDb Rating: {imdb_rating}")

Example 2: OMDB API for Movie and Series Ratings


import requests

# Specify the API key (get one from http://www.omdbapi.com/)
api_key = 'your_api_key'

# Search for a movie or series by title
title = 'Breaking Bad'
url = f'http://www.omdbapi.com/?apikey={api_key}&t={title}&type=series'

# Make the API request
response = requests.get(url)
data = response.json()

# Access the IMDb rating
omdb_rating = data.get('imdbRating')
print(f"OMDb Rating: {omdb_rating}")

Example 3: TMDb API for Movie and Series Ratings


import requests

# Specify the API key (get one from https://www.themoviedb.org/settings/api)
api_key = 'your_api_key'

# Search for a movie or series by title
title = 'The Dark Knight'
url = f'https://api.themoviedb.org/3/search/movie?api_key={api_key}&query={title}'

# Make the API request
response = requests.get(url)
data = response.json()

# Access the TMDb rating
tmdb_rating = data.get('results')[0].get('vote_average')
print(f"TMDb Rating: {tmdb_rating}")