Python Project – Instagram Photo Downloader

Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python

The Instagram Photo Downloader is a Python-based application designed to download photos from public Instagram profiles. It utilises the Instaloader library for fetching the images and tkinter for building a user-friendly graphical interface.

About Python Instagram Photo Downloader Project

The Instagram Photo Downloader automates the process of downloading photos from a specified public Instagram profile. By entering the Instagram username, the application fetches and saves the images to a designated folder on the user’s local machine.

Objectives for Instagram Photo Downloader

  • Develop a project to download photos from a public Instagram profile without logging in.
  • Provide a user-friendly interface for inputting the Instagram username and download path.
  • Save the downloaded pictures in a structured manner.

Project Setup

Required Libraries

  • instaloader: For downloading pictures from Instagram.
  • os: For directory operations.
  • instaloader: For downloading pictures from Instagram.
  • tkinter: For building the graphical user interface.

Prerequisites of Python Instagram Photo Downloader

  • Basic understanding of Python programming.
  • Familiarity with Tkinter for GUI development.
  • An Instagram account (optional).

Download the Python Instagram Photo Downloader Project

Please download the source code of the Python Instagram Photo Downloader Project: Python Instagram Photo Downloader Project Code.

Step-by-Step Code Implementation of Python Instagram Photo Downloader

1. Importing Libraries

  • instaloader: This library handles the interaction with Instagram to download photos.
  • os: It is used for operating system-dependent functionalities.
  • tkinter: It builds the graphical user interface.
  • messagebox and filedialog: It handles displaying messages and file dialogs.
import instaloader
import os
import tkinter as tk
from tkinter import messagebox, filedialog

2. Downloading Photos

  • download_photos function takes the Instagram username and the download path as inputs.
  • Initializing Instaloader creates an instance of the Instaloader class.
  • Then it checks if the specified path exists; if not, it creates it.
  • Using the Profile.from_username method we get the profile and iterate over posts to download them.
def download_photos(username, download_path):
   loader = instaloader.Instaloader()


   if not os.path.exists(download_path):
       os.makedirs(download_path)


   os.chdir(download_path)


   print(f"Downloading photos from @{username}...")
   try:
       loader.download_profile(username, profile_pic_only=False)
       print(f"Photos downloaded successfully to {download_path}")
       messagebox.showinfo("Success", f"Photos downloaded successfully to {download_path}")
   except Exception as e:
       print(f"An error occurred: {e}")
       messagebox.showerror("Error", f"An error occurred: {e}")

3. Tkinter Interface

  • This function creates the main window for the application using tkinter.
  • The tk.Label and tk.Entry creates input fields for the Instagram username and download path.
  • This function is responsible for creating buttons to browse the download directory and initiate the download process.
  • Arranging the labels, entries, and buttons using the grid method for a structured layout.
def build_gui():
   def start_download():
       username = username_entry.get()
       download_path = path_entry.get()
       if username and download_path:
           download_photos(username, download_path)
       else:
           messagebox.showwarning("Input Error", "Please enter both username and download path")


   def browse_folder():
       folder_selected = filedialog.askdirectory()
       path_entry.delete(0, tk.END)
       path_entry.insert(0, folder_selected)


   root = tk.Tk()
   root.title("DataFlair@Instagram Photo Downloader")


   tk.Label(root, text="Instagram Username:").grid(row=0, column=0, padx=10, pady=10)
   username_entry = tk.Entry(root, width=30)
   username_entry.grid(row=0, column=1, padx=10, pady=10)


   tk.Label(root, text="Download Path:").grid(row=1, column=0, padx=10, pady=10)
   path_entry = tk.Entry(root, width=30)
   path_entry.grid(row=1, column=1, padx=10, pady=10)
   browse_button = tk.Button(root, text="Browse", command=browse_folder)
   browse_button.grid(row=1, column=2, padx=10, pady=10)


   download_button = tk.Button(root, text="Download", command=start_download)
   download_button.grid(row=2, column=1, pady=20)


   root.mainloop()


if __name__ == "__main__":
   build_gui()

Python Instagram Photo Downloader Output

1. Application Interface

application interface

2. Setting Download Path

download path

3. Giving Username

giving username

4. Downloading Photos

downloading photos

5. Downloaded Folder

downloaded folder

Conclusion

The Instagram Photo Downloader project successfully demonstrates the use of the instaloader library to download photos from public Instagram profiles. By providing a simple and user-friendly interface, the application allows users to save their favorite Instagram photos locally. The project can be extended to include additional features such as downloading videos, handling private profiles, and integrating with cloud storage services.

If you are Happy with DataFlair, do not forget to make us happy with your positive feedback on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

1 Response

  1. This walkthrough is a useful example of working with public Instagram profile media without asking readers to log in. For people who only need a browser-based privacy layer rather than a Python script, InstaPV is another option: it lets users view public Instagram stories, posts, reels, profile pictures, and recent-followed signals without an Instagram login or password. It stays limited to public content, which is the important boundary I wish more viewer tools explained clearly.

Leave a Reply

Your email address will not be published. Required fields are marked *