Cover image for How to make an Instagram Bot with Python

How to make an Instagram Bot with Python

ayushi7rawat profile image Ayushi Rawat Updated on ・3 min read

Do you use Instagram?
Do you want to know how to build an Instagram Bot?

This tutorial will teach you how to automate Instagram activities with the help of an Instagram bot.

Alt Text

Let's get started!

Prerequisites for making one (Bot)

- Python
- Instapy module in Python
- An Instagram account, which you will use to run the bot script.

That's it. Now let's dive straight into the code.

Time To Code!

Alt Text

Now let's Understand the code.

Installation of instapy

pip install Instapy 

Important: Depending on your system, make sure to use pip3 and python3 instead.

If you would like to install a specific version of Instapy you may do so with:

pip install instapy==0.1.1

Set the login credentials

You can put in your account details now by passing the username and password parameters to the InstaPy() function in your bot script, like so:


If want InstaPy to run in the background pass the --headless- browser option when running from the CLI
Or add the headless_browser=True parameter to the InstaPy(headless_browser=True) constructor.


The bot will fetch posts with hashtag python3 and javascript.
Set the amount to the number of posts you wish to like.

session.like_by_tags(['python3','javascript'], amount=300)


By default enabled=False, follows every 2nd user from the images

session.set_do_follow(True, percentage=50)


Enable comments (by default enabled=False) and set commenting probability to 100% so ~ every image will be commented on

session.set_do_follow(True, percentage=100)

Configure a simple list of optional comments, one will be selected at random when commenting:

session.set_comments(['Comment1', 'Comment2', 'Comment3'])

Excluding friends

will prevent commenting on and unfollowing your good friends (the images will still be liked)

session.set_dont_include(['friend1', 'friend2', 'friend3'])

Interactions based on the number of followers and/or following a user has

This is used to check the number of followers and/or following a user has and if these numbers either exceed the number set OR does not pass the number set OR if their ratio does not reach desired potency ratio then no further interaction happens


Quota Supervisor

Take full control of the actions with the most sophisticated approaches

                                 sleep_after=['likes', 'follows'])

Once done, we will end the session by session.end().

You are ready to run the bot!

Once you have your bot script configured you can execute the script with the following commands.

python instagrambot.py

You can find my code at GitHub.

Also, have look at my other blogs:

You can also connect with me on twitter

Good luck with making your own.
If you have any Queries or Suggestions, please reach out to me in the Comments Section below.

Posted on by:

ayushi7rawat profile

Ayushi Rawat


Software Engineer at TCS | Technical Blogger | YouTuber | Passionate about learning new stuffs | Like to read | Music calms my soul


markdown guide

Tnx for sharing this amazing tutorial Ayushi
Just let me know if you have any information about the Instagram Rate-Limit to follow users.
Happy Coding ;)


Thank you Banji
I will let you know.


HAHAHA, So let me know :)))))) LOL


Great for study purposes. But, please be careful about using the bot for growing Instagram accounts.


Yes, I am aware about that, thank you.


Make sure your account will not be banned due to instagram interactions limit.


Yes, I am aware about that. Thank you


Nice i'm going to have to try making a bot of some sort with Python at some point. Good guide.


Thank you Andrew.
Keep learning.


Is this module open sourced? Since it requires entire login details but obscures if the usage extends the normal reason.


This is such a cool post! More power to you Ayushi! Gotta try this out now :p


Yes, thank you Hamza.
Keep learning!