My New Python Best Friends


Posted

in

,

I’d like to give a quick shout out to a few of my favorite new Python modules:

  • httplib: The httplib example page has some excellent usage examples for both GET and POST methods.
  • urllib: urllib.urlencode is your friend if you need to encode a url for inclusion in a POST request.
  • urlparse: I started to parse and split up urls by hand using regular expressions and string manipulation.  Then I found urlparse.  It will take a url like http://postneo.com/projects/wapblog and turn it into a useful tuple: (‘http’, ‘postneo.com’, ‘/projects/wapblog’).  This improved my quality of life considerably, and makes POST requests via httplib possible.

P.S. These libraries converge to make working with RESTful interfaces DUH-simple in Python.