Skip to content
Twitter text processing library (auto linking and extraction of usernames, lists and hashtags).
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE update repository URLs Feb 18, 2019

CircleCI PyPI version


twitter-text-python is a Tweet parser and formatter for Python. Extract users, hashtags, URLs and format as HTML for display.

PyPI release:


$ pip install twitter-text-python


twitter-text-python has been tested with Python 2.6, 2.7, 3.3, 3.4, 3.5, and 3.7.


>>> from ttp import ttp
>>> p = ttp.Parser()
>>> result = p.parse("@burnettedmond, you now support #IvoWertzel's tweet parser!")
>>> result.reply
>>> result.users
>>> result.tags
>>> result.urls
>>> result.html
u'<a href="">@burnettedmond</a>, you now support <a href="">#IvoWertzel</a>\'s tweet parser! <a href=""></a>'

If you need different HTML output just subclass and override the format_* methods.

You can also ask for the span tags to be returned for each entity:

>>> p = ttp.Parser(include_spans=True)
>>> result = p.parse("@burnettedmond, you now support #IvoWertzel's tweet parser!")
>>> result.urls
[('', (57, 87))]

To use the shortlink follower (depends on the Requests library):

>>> from ttp import utils
>>> # assume that result.urls == ['', u'']
>>> print utils.follow_shortlinks(result.urls)  # pass in list of shortlink URLs
{'': [u'', u'', u''], u'': [u'', u'']}
 >>> # note that bad shortlink URLs have a key to an empty list (lost/forgotten shortlink URLs don't generate any error)


  • 2019/02/17 1.1.1 Minor release to fix Python 3 support for, test with 3.7
  • 2015/04/11 1.1.0 Add basic support for Python 3
  • 2014/07/30 1.0.3 Update parsed URLs for Twitter API 1.1 compatibility
  • 2013/06/01 1.0.1 new working version, adding comma parse fix (thanks, used autopep8 to clean the src, added a shortlink expander
  • 2013/02/11 released to PyPI


Run the unit tests:

$ python ttp/
Ran 100 tests in 0.009s

Or test on multiple Python versions with tox:

$ pip install tox
$ tox


See the relevant wiki page for notes on contributing to twitter-text-python.


The current version was forked by Edmond Burnett in July 2014:

The library was forked by Ian Ozsvald in January 2013 and released to PyPI, some bugs were fixed, a few minor changes to functionality added (no longer supported):

The original ttp comes from Ivo Wetzel (no longer supported):

Originally based on

You can’t perform that action at this time.