Tweepy supports both basic and oauth authentication. Authentication is handled by tweepy.AuthHandler classes with two implementations provided:
Basic authentication uses the user’s Twitter username and password for authenticating with the API. You must query the user for these two pieces of infomation before we can authenticate.
Now first we must create an instance of the BasicAuthHandler and pass into it the username and password:
auth = tweepy.BasicAuthHandler(username, password)
Next we need to create our API instance which will be used for executing requests to the Twitter API:
api = tweepy.API(auth)
We are now ready to make API calls that are authenticated! Here is a quick example posting a new tweet to the authenticated user’s account:
api.update_status(‘hello from tweepy!’)