In the beginning of my research I thought python-twitter is the twitter library for Python. But finally, it seems as if the Python Twitter Tools are more popular and support also twitter streaming.
It's a bit tricky, the streaming API and the REST api are not equal for direct messages. This small example script demonstrates how you can use the user stream to get direct messages:
import twitter # if this module does not
# contain OAuth or stream,
# check if sixohsix' twitter
# module is used!
auth = twitter.OAuth(
consumer_key='...',
consumer_secret='...',
token='...',
token_secret='...'
)
stream = twitter.stream.TwitterStream(auth=auth, domain='userstream.twitter.com')
for msg in stream.user():
if 'direct_message' in msg:
print msg['direct_message']['text']
This script will print all new messages - not the ones already received before starting the script.