π¬ 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"])
π€οΈ 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']}")
βοΈ 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)