twitter-text-python (ttp) module – PythonReadDiscussCoursesPracticeImprove Article ImproveSave Article SaveLike Article Liketwitter-text-python is a Tweet parser and formatter for Python. Amongst many things, the tasks that can be performed by this module are :reply : The username of the handle to which the tweet is being replied to.users : All the usernames mentioned in the tweet.tags : All the hashtags mentioned in the tweet.urls : All the URLs mentioned in the tweet.html : Adds hyperlinks to the fields mentioned above.Example 1 :# import the twitter-text-python modulefrom ttp import ttp # the text to be parsedtweet_text = ("@twitter Sample tweet containing different components." + "# gfg # tweeple Visit : https://twitter.com @TwitterIndia") # instantiating the Parserp = ttp.Parser() # parsing the textresult = p.parse(tweet_text) # printing the username of the# account being replied toprint("The username being replied to is : " + result.reply) # printing all the usernames# mentioned in the tweetprint("\nAll the usernames mentioned are : " + str(result.users)) # printing all the hashtags# mentioned in the tweetprint("\nAll the hashtags mentioned are : " + str(result.tags)) # printing all the URLs# mentioned in the tweetprint("\nAll the URLs mentioned are : " + str(result.urls)) # adding hyperlinks to usernames,# hashtags and URLsprint(result.html)Output :The username being replied to is : twitterAll the usernames mentioned are : [‘twitter’, ‘TwitterIndia’]All the hashtags mentioned are : [‘gfg’, ‘tweeple’]All the URLs mentioned are : [‘https://twitter.com’]@twitter Sample tweet containing different components.#gfg #tweeple Visit : https://twitter.com @TwitterIndiaExample 2 : We can also find the position of string (POS) by doing include_spans = True.# import the twitter-text-python modulefrom ttp import ttp # the text to be parsedtweet_text = ("@twitter Sample tweet containing different components." + "# gfg # tweeple Visit : https://twitter.com @TwitterIndia") # instantiating the Parser# with spansp = ttp.Parser(include_spans = True) # parsing the textresult = p.parse(tweet_text) # printing all the usernames# mentioned in the tweet with POSprint("All the usernames mentioned are : " + str(result.users)) # printing all the hashtags# mentioned in the tweet with POSprint("\nAll the hashtags mentioned are : " + str(result.tags)) # printing all the URLs# mentioned in the tweet with POSprint("\nAll the URLs mentioned are : " + str(result.urls))Output :All the usernames mentioned are : [(‘twitter’, (0, 8)), (‘TwitterIndia’, (130, 143))]All the hashtags mentioned are : [(‘gfg’, (96, 100)), (‘tweeple’, (101, 109))]All the URLs mentioned are : [(‘https://twitter.com’, (76, 95))]Last Updated : 08 Sep, 2021Like Article Save Article Please Login to comment...Similar ReadsTwitter Sentiment Analysis using PythonHow to Build a Twitter Bot to Post Latest Stock Update using PythonTwitter Automation using Selenium PythonHow to make a Twitter Bot in Python?Login Twitter using Python SeleniumTwitter Sentiment Analysis on Russia-Ukraine War Using PythonTwitter Sentiment Analysis WebApp Using FlaskOAuth Authentication with Flask - Connect to Google, Twitter, and FacebookPython Text To Speech | pyttsx moduleWorking With Text In Python .docx ModuleRelated TutorialsOpenAI Python API - Complete GuidePandas AI: The Generative AI Python LibraryPython for Kids - Fun Tutorial to Learn Python ProgrammingData Analysis TutorialFlask Tutorial LikePreviousConvert emoji into text in PythonNext fmean() function in Python statisticsArticle Contributed By :YYash_RYash_R FollowVote for difficultyCurrent difficulty : EasyEasy Normal Medium Hard ExpertImproved By :abhishek0719kadiyanArticle Tags :python-modulesPython-projectspython-utilityPythonPractice Tags :pythonReport Issue