import urllib import json def GooGL(url): params = urllib.urlencode({'security_token': None, 'url': url}) f = urllib.urlopen('http://goo.gl/api/shorten', params) return json.loads(f.read())['short_url'] print GooGL('http://www.google.com')