Blog available for sell
This blog is available for sale. Please 'contact us' if interested.
Advertise with us
py_instagram_dl - The Python Package to Download All pictures of an Instagram User

I created a small script to download all pictures of an Instagram user without using APIs as APIs poses few limitations like rate limit.

After few rounds of tweaking, optimisation and beautifying code, I though of creating a python package out of it. If you want to know how to create a distributable python package, this article will be extremely helpful as steps are discussed in great detail.

You can find the py_instagram_dl  package listed on pypi.

link is -  https://pypi.python.org/pypi/py-instagram-dl.


How to download all pictures of an Instagram user:

Create a virtual environment. Optional but strongly recommended. You may follow this simple and step by step pocket guide on Python Virtual Environment.

Install dependencies. 

pip install beautifulsoup4 bs4 lxml requests urllib3


Now install this package.

pip install py_instagram_dl


Use the installed package in your code.

import py_instagram_dl as pyigdl
import sys

# run script by providing username as command line argument
# usage : python script_name.py username

try:
    pyigdl.download(sys.argv[1], wait_between_requests=1)
except Exception as e:
    print(e)


Parameter Options:

Download method have one mandatory and two optional parameters as of now.

Mandatory Parameter:


Parameter 1:
Valid username of Instagram user.


Optional Parameter:

Verbose:
Default value - True (boolean).
Decides whether information should be printed on screen. Recommended to have it set to True so that in case of large number of downloads you can make sure script is working and is not just freezed.

Wait_between_requests:
Default value - 0 (integer).
This is the time in seconds for which scripts waits to send new hit to download the picture to Instagram. It is recommended to pass a positive value for this parameter. If you are getting rate limit exceptions after downloading few pictures, pass 1 in this parameter, i.e. wait for 1 second between each request.


Exceptions:
InvalidUsernameException:
When a non existent username is provided.

RateLimitException:
When rate limit is reached. Use parameter wait_between_requests to avoid this.  


Source Code:  Source code is available on Github.

3 comments on 'Py_Instagram_Dl - The Python Package To Download All Pictures Of An Instagram User'
Login to comment

Julián Varela May 22, 2019, 2:42 p.m.
Hi! I'm new with Python and I've installed your package in a new project with its own virtual environment.I copied your code in a file (insta.py), but I don't know how to run the program. I've tried from the command line running insta.py but it just gives me an error, I don't really get how it works.Sorry for the silly question, but if you could explain me how to make it work I'd really appreciate it.Thanks for the good work!
Admin May 24, 2019, 12:15 p.m.
What is the error?
Sean Jan. 26, 2020, 10:22 p.m.
I installed all of the required dependencies and ran the example program with python3 (on a Raspberry Pi Zero W) but I got the message "An Unknown Exception occurred. Please contact developer." with no further details. So, here I am, contacting the developer. I'm sure there are other options to download Instagram pictures but I would really appreciate if someone else looked into this issue!

Related Articles:
How to develop a distributable Django app to block the crawling IP addresses
How to create reusable django app which can block crawling IPs from accessing your app. Creating distributable python package and upload on pypi....
Scraping data of 2019 Indian General Election using Python Request and BeautifulSoup and analyzing it
scraping 2019 election data india, Scraping data of 2019 Indian General Election using Python BeautifulSoup and analyzing it, using beautifulsoup to collection election data, using request...
Python Script 14: Scraping news headlines using python beautifulsoup
Scraping news headlines using python beautifulsoup, web scraping using python, python script to scrape news, web scraping using beautifulsoup, news headlines scraping using python, python programm to get news headlines from web...
Python Script 10: Collecting one million website links
Collecting one million website links by scraping using requests and BeautifulSoup in Python. Python script to collect one million website urls, Using beautifulsoup to scrape data, Web scraping using python, web scraping using beautifulsoup, link collection using python beautifulsoup...
DigitalOcean Referral Badge

© 2024-2025 Python Circle   Contact   Sponsor   Archive   Sitemap