Posting to Instagram with Python in 2021 — three simple steps
Posting to Instagram using Python is really simple, and opens so many doors for automation
The two best ways to organically grow your Instagram account are engaging with the community, and frequently posting. The latter can be hard to keep up with — but thankfully, we can automate this with Python.
Install instabot — this is a fantastic Python library for doing pretty much everything a human can do on Instagram.
pip install instabot
Define your function
from instabot import Botdef post_to_ig(image, caption):
bot = Bot()
bot.login(username = 'your_username',
password = 'your_password')
Replace the placeholders in the script above with your username and password — it goes without saying that you should exercise caution if you’re storing credentials in a script.
Call your function and run your script
post_to_ig('photo_filepath.jpeg','your caption #example')
Replace the placeholders above with the filepath to the photo you’d like to post, and your chosen caption. You can add in hashtags, \n for line breaks, and even emojis using the Python emoji library.
Now how about scheduling the code using crontab, or triggering it from somewhere else?