I wouldn't bother trying to convert PHP code into python, but instead just search for a Python way of getting this answer. A little googling and it looks like this might be a duplicate:
Oauth client initialization in python for tumblr API using Python-oauth2