This project is a Flask-based API for managing and retrieving movie data stored in a Neo4j graph database. The API supports CRUD operations for movies and their relationships, such as actors, directors, and genres.
Before running this application, ensure you have the following installed:
-
Python 3.7+
- Download: https://www.python.org/downloads/
-
Neo4j Community or Enterprise Edition
- Download: https://neo4j.com/download-center/
-
Flask
-
Neo4j Python Driver (
neo4j) -
Postman
- Postman is a tool for testing and interacting with APIs.
- Download: https://www.postman.com/downloads/
-
Clone the repository to your local machine:
git clone https://github.com/Swathi-Reddy1408/Neo4jDataAnalysis-FlaskAPI.git cd Neo4jDataAnalysis-FlaskAPI-main -
Install the required Python libraries:
pip install flask neo4j
-
Ensure your Neo4j database is running and update the following in the code:
- Replace
<password>with your Neo4j database password. - Ensure the URI matches your Neo4j instance (default:
bolt://localhost:7687).
- Replace
-
Run the Flask application:
python PROG_ASSIGN2_23915_700743277.py
-
Access the API at:
http://127.0.0.1:5000/
GET /imdb
- Retrieves all movies in the database.
- Response: JSON array of movies.
GET /imdb/<string:fname>
- Retrieves a movie by its title, including its directors, actors, and genres.
- Response: JSON object with movie details and related nodes.
POST /imdb
- Creates a new movie node and its relationships.
- Request Body Example:
{ "id": "1", "title": "Inception", "description": "A mind-bending thriller", "rating": 9.0, "revenue": 800000000, "runtime": 148, "votes": 2000000, "year": 2010, "actors": ["Leonardo DiCaprio", "Joseph Gordon-Levitt"], "directors": ["Christopher Nolan"], "genres": ["Sci-Fi", "Thriller"] } - Response: Confirmation message.
PATCH /imdb/<string:fname>
- Updates the title, description, and rating of a movie.
- Request Body Example:
{ "title": "Inception Updated", "description": "An updated description", "rating": 9.5 } - Response: Movie node with title 'Inception' has been updated successfully.
DELETE /imdb/<string:fname>
- Deletes a movie and all its relationships.
- Response: Movie 'Inception' and all its relationships deleted from database.
neo4j: For connecting and executing queries on the Neo4j graph database.flask: For building the web application and handling API routes.json: For managing JSON data.
-
Neo4j Connection:
- Established using the Neo4j driver.
- All operations interact with the graph database.
-
Routes:
- Routes are defined using Flask decorators.
- Each route corresponds to a specific CRUD operation.
-
CRUD Operations:
- Add, retrieve, update, and delete movie nodes and their relationships.
-
Relational Queries:
- Cypher queries are used for interacting with the Neo4j database.
- Relationships like
ACTED_IN,DIRECTED, andIN(for genres) are handled.
- Add better error handling and validations.
- Implement user authentication.
- Paginate the results for large datasets.
- Optimize Cypher queries for better performance.