DEV Community

Sabin Sim
Sabin Sim

Posted on

My Project 4: Movie Search App (with Python + Streamlit)

🎬 Building a Movie Search App with Python + Streamlit (Using OMDb API)

For this project, I wanted to practice working with external APIs that require an API key. The OMDb API is perfect for this β€” free, fast, and provides detailed movie information.

This project includes two versions:

  • Console Version (movie_app.py)
  • Streamlit Web Version (movie_app_streamlit.py)

By building this app, I learned how to work with authenticated APIs, handle search results, manage missing data, and build a better UI using Streamlit.


🧱 1. Project Overview

The Movie Search App allows you to:

  • Enter a movie title
  • Fetch detailed movie information
  • View poster, genre, plot, and rating
  • Use either console or Streamlit web interface

πŸ“‚ Project Structure


movie_app/
β”‚
β”œβ”€β”€ movie_app.py                 # Console version
β”œβ”€β”€ movie_app_streamlit.py       # Streamlit version
└── README.md                    # (optional)

🌐 2. API Used: OMDb API

OMDb requires a free API key. Get one here:

πŸ”— https://www.omdbapi.com/apikey.aspx


πŸ–₯️ 3. Console Version (movie_app.py)

Key Features:

  • Fetch movie data using requests
  • Handles invalid titles gracefully
  • Displays essential movie details

πŸ“Œ Code

import requests

API_KEY = "YOUR_API_KEY"  # Put your OMDb API key here

title = input("Movie title: ")

url = f"https://www.omdbapi.com/?t={title}&apikey={API_KEY}"
response = requests.get(url)

if response.status_code != 200:
    print("Error fetching data.")
    exit()

data = response.json()

if data["Response"] == "False":
    print("Movie not found.")
    exit()

print("=== Movie Info ===")
print("Title:", data["Title"])
print("Year:", data["Year"])
print("Genre:", data["Genre"])
print("Plot:", data["Plot"])
print("Rating:", data["imdbRating"])
Enter fullscreen mode Exit fullscreen mode

🌀️ 4. Streamlit Version (movie_app_streamlit.py)

Added Features:

  • Poster image display
  • Well formatted output UI
  • Error / not found handling

πŸ“Œ Code

import streamlit as st
import requests

st.title("🎬 Sabin's Movie Search App")

API_KEY = "YOUR_API_KEY"

title = st.text_input("Enter movie title:", "Inception")

if st.button("Search"):
    url = f"https://www.omdbapi.com/?t={title}&apikey={API_KEY}"
    response = requests.get(url)

    if response.status_code != 200:
        st.error("Error fetching data.")
    else:
        data = response.json()

        if data["Response"] == "False":
            st.warning("Movie not found.")
        else:
            st.subheader(f"{data['Title']} ({data['Year']})")

            if data["Poster"] != "N/A":
                st.image(data["Poster"], width=300)
            else:
                st.info("No poster available.")

            st.write(f"Genre: {data['Genre']}")
            st.write(f"Rating: ⭐ {data['imdbRating']}")
            st.write(f"Plot: {data['Plot']}")
Enter fullscreen mode Exit fullscreen mode

βš™οΈ 5. How to Run

βœ” Console Version


python3 movie_app.py

βœ” Streamlit Version


pip install streamlit
streamlit run movie_app_streamlit.py

πŸ“š 6. What I Learned

  • Working with authenticated APIs
  • Error handling for missing data
  • Displaying images in Streamlit
  • CLI vs Web app differences

πŸ”§ 7. Future Improvements

  • Search by keyword instead of exact title
  • Show similar or recommended movies
  • Save favorite movies
  • Add Rotten Tomatoes / Metacritic ratings
  • Dark mode UI

Top comments (0)