Photo by Joshua Reddekopp on Unsplash

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.

Step 1

Install instabot — this is a fantastic Python library for doing pretty much everything a human can do on Instagram.

pip install instabot

Step 2

Define your function

from instabot import Botdef post_to_ig(image, caption):
bot = Bot()
bot.login(username = 'your_username',
password = 'your_password')
bot.upload_photo(image, caption)

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.

Step 3

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.

That’s it!

Now how about scheduling the code using crontab, or triggering it from somewhere else?

Enjoy!

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

ArcBlock joins Future of Work Hackathon

What Happens When You Buy a Product Using Paypal/Bank Card Under the Hood?

Smalltalk Isn’t Dead: Here’s Why You Should Use It

Ruby Gems

My Journey As A Self-Taught Programmer

Explain about PEGA Testing?

Kotlin Hello World Program — First Kotlin Program

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Phil Hather

Phil Hather

More from Medium

Most commonly utilized libraries for data science :

Errors: Friend or Foe?? (Probably a Foe)

List and data structures in python

Python break, continue, pass statements with Examples