Write a Twitter Bot with Python Tweepy to Follow New Followers

Write a Twitter Bot with Python Tweepy to Follow New Followers

It’s hard being popular: everyone wants to follow you on Twitter but you don’t have time to follow them back. You could get an assistant or you could automate! In this tutorial, you will write a Twitter Bot with Python using the excellent Tweepy library to automatically follow new followers.

First, start a new application at http://dev.twitter.com

After that, create a file, keys.py, and add the following:

Enter your keys and tokens from Twitter. Then create another file, follow.py, and add the following:

Run this script from the command line:

Your shell should return a list of the user names you are following as you follow them.

As you will see, Tweepy does all of the heavy lifting in this script. We first import tweepy and our keys, then hook into the Twitter api. The for loop is the meat and potatoes of our bot. And it’s essentially 2 lines of code! Cursor is a tweepy object that handles pagination, which is how Twitter manages the endless stream of status updates. If you want to limit how many followers you iterate over, pass a value to the  .items()  function.

Next up? How to unfollow those  who don’t follow you back. Stay tuned!

About the Author

Write a Twitter Bot with Python Tweepy to Follow New Followers was posted by on . Jared is one half of the creative force behind Dototot. In addition to writing scripts and tutorials, he draws and animates both the digital and the analog.

Discuss this article in the Comments below, or and it with your friends. Learn more about our creative process by subscribing to the New Moon Newsletter .

Recommended for you
Join the discussion
  • Justin Greenough

    This doesn’t perform as advertised. No new followers are followed, only the names of those who are already following are displayed. What am I not seeing.

  • Justin Greenough

    The script induces following of all those who are already following. I understand. The text was a bit vague. I would like to follow random tweeters automatically. How could this be done?

Subscribe to our New Moon Newsletter

How do you make money doing what you love? Sign up for monthly emails exploring the necessary evils of business as we develop a creative media studio using free and open source software.

The email entered is invalid
×