Bulk Delete All Instagram Posts Using Python (instagrapi Script)

Need to clean up your Instagram account quickly? Manually removing posts one by one can be extremely time-consuming. In this tutorial, you’ll learn how to use the instagrapi Python library to create a script that deletes all your Instagram posts in bulk. Whether you want to remove only Reels, feed posts, or everything before a certain date, this method gives you full control.
Once your account is clean, you can even automate new uploads every 5 minutes to multiple platforms.

Bulk Delete All Instagram Posts Using Python (instagrapi Script)

Manually removing hundreds of Instagram posts is tedious. In this guide, you’ll learn how to use the popular instagrapi library to create a Python script that deletes all your Instagram media in bulk — including Reels. You can also target only Reels, only feed posts, or anything before a specific date.

Requirements

  • Python 3.10+ (3.11/3.12 recommended)
  • pip install instagrapi
  • If 2FA is enabled, the first login may prompt for a code (then stored in session.json).

Script (clean_instagram.py)

import time, random
from datetime import datetime
from instagrapi import Client
from instagrapi.exceptions import PleaseWaitFewMinutes, LoginRequired

USERNAME = "username"
PASSWORD = "password"

DELETE_REELS = True
DELETE_POSTS = True
DELETE_OLD_ONLY = False
DELETE_BEFORE = datetime(2023, 1, 1)

DELAY_EACH = (1.5, 2.5)
PAUSE_EVERY = 100
PAUSE_SECS = 60

def wait_range(a, b):
    time.sleep(random.uniform(a, b))

def login_with_session(cl: Client, session_path="session.json"):
    try:
        cl.load_settings(session_path)
    except Exception:
        pass
    try:
        cl.login(USERNAME, PASSWORD)
    except LoginRequired:
        cl.relogin()
    cl.dump_settings(session_path)

def should_delete(m):
    if DELETE_OLD_ONLY and m.taken_at >= DELETE_BEFORE:
        return False
    ptype = getattr(m, "product_type", None)  # "feed", "clips"
    if ptype == "clips" and not DELETE_REELS:
        return False
    if (ptype in (None, "feed")) and not DELETE_POSTS:
        return False
    return True

def main():
    cl = Client()
    cl.delay_range = DELAY_EACH
    login_with_session(cl)

    user_id = cl.user_id
    print("Fetching media (v1, large amount)...")
    medias = cl.user_medias_v1(user_id, amount=100000)
    print(f"Found {len(medias)} items.")

    deleted = 0
    for m in medias:
        if not should_delete(m):
            continue
        try:
            cl.media_delete(m.pk)
            deleted += 1
            print(f"[{deleted}] Deleted: {m.product_type or 'feed'} | {m.pk} | {m.taken_at}")
        except PleaseWaitFewMinutes as e:
            print("Rate limit. Waiting 5 minutes...", e)
            time.sleep(300)
        except Exception as e:
            print(f"Error: {m.pk} -> {e}")

        time.sleep(__import__("random").uniform(*DELAY_EACH))

        if deleted and deleted % PAUSE_EVERY == 0:
            print(f"Paused {PAUSE_EVERY} deletions, waiting {PAUSE_SECS}s...")
            time.sleep(PAUSE_SECS)

    print(f"Done. Total deleted: {deleted}")

if __name__ == "__main__":
    main()

Usage

  1. pip install -U instagrapi
  2. Run python clean_instagram.py.
  3. Enter the first-time 2FA code if prompted; a session will be stored.

Tips

  • Only Reels: DELETE_POSTS=False, DELETE_REELS=True
  • Only feed posts: DELETE_REELS=False, DELETE_POSTS=True
  • Date cutoff: set DELETE_OLD_ONLY=True and update DELETE_BEFORE.

Leave a Comment