Instaloader

Language: Python

Web

Instaloader was created by Thilo Planz to provide a simple and efficient tool for downloading content from Instagram without using the official API. It handles login, private profiles, hashtags, and profiles with ease, and can save metadata like captions, likes, and comments.

Instaloader is a Python library to download Instagram photos, videos, stories, IGTV, and profiles. It allows you to scrape Instagram content programmatically for personal or research purposes.

Installation

pip: pip install instaloader
conda: conda install -c conda-forge instaloader

Usage

Instaloader can download posts, stories, profiles, or hashtags using Python scripts or command-line interface. It supports login for private profiles, filtering by date, and storing metadata in JSON files.

Download a profile

import instaloader
L = instaloader.Instaloader()
L.download_profile('instagram_username', profile_pic=True)

Downloads all posts and profile picture of the specified Instagram user.

Download stories

import instaloader
L = instaloader.Instaloader()
L.download_stories(userids=['instagram_user_id'])

Downloads active stories for the specified user IDs.

Login and download private profile

import instaloader
L = instaloader.Instaloader()
L.login('your_username', 'your_password')
L.download_profile('private_user', profile_pic=True)

Logs in with your credentials to download posts from a private account you follow.

Download posts by hashtag

import instaloader
L = instaloader.Instaloader()
for post in instaloader.Hashtag.from_name(L.context, 'python').get_posts():
    L.download_post(post, target='#python')

Downloads all posts tagged with #python into a folder named '#python'.

Save metadata

import instaloader
L = instaloader.Instaloader(download_comments=False, save_metadata=True)
L.download_profile('instagram_username')

Saves JSON metadata for each post, including captions, likes, and comments.

Filter posts by date

import instaloader
import datetime
L = instaloader.Instaloader()
PROFILE = instaloader.Profile.from_username(L.context, 'instagram_username')
for post in PROFILE.get_posts():
    if post.date > datetime.datetime(2025,1,1):
        L.download_post(post, target=PROFILE.username)

Downloads posts from the profile after January 1, 2025.

Error Handling

instaloader.exceptions.LoginRequiredException: Login using L.login('username', 'password') to access private content.
instaloader.exceptions.ProfileNotExistsException: Verify that the Instagram username exists and is spelled correctly.
instaloader.exceptions.ConnectionException: Check network connectivity and Instagram server availability.

Best Practices

Respect Instagram’s terms of service and avoid excessive scraping.

Use login for private content responsibly and only for accounts you have access to.

Handle exceptions for network issues or blocked content.

Save metadata and use structured directories for organization.

Rate-limit requests to avoid temporary bans or throttling.