Python Requests: HTTP for Humans (python-requests.org)
Requests is an ISC Licensed HTTP library, written in Python, for human beings.
Requests allow you to send HEAD, GET, POST, PUT, PATCH, and DELETE HTTP requests. You can add headers, form data, multipart files, and parameters with simple Python dictionaries, and access the response data in the same way. It’s powered by urllib2, but it does all the hard work and crazy hacks for you.
85 comments
[ 8.1 ms ] story [ 170 ms ] threadhttp://news.ycombinator.com/item?id=2882301
Apparently 113,798 people found a reason to download the 3.2.2 Windows installers (32 and 64 bit) from python.org through only the first 10 days of the month of October. http://www.python.org/webstats/usage_201110.html
(doesn't include mention of the 3.2 source tarball downloads, which are under 5,000, most likely since people get that from their distro anyway)
Also I couldn't tell if there is keep-alive support, is there?
Caching: I think that will be best be served by a hook/helper module, but we'll see.
Does that also mean that it will have better support for timeouts? I'm not interested in socket timeouts, more in a 'finish this in N seconds or just give up' thing.
For that reason I am using pycurl now for some stuff where I had previously used the requests library. Which has a really really horrible API :-/
Most existing Python modules for sending HTTP requests are extremely verbose and cumbersome. Python’s builtin urllib2 module provides most of the HTTP capabilities you should need, but the api is thoroughly broken. It requires an enormous amount of work (even method overrides) to perform the simplest of tasks."
E.g., urllib/urllib2 both support urlopen(url, [data]) if `data` is supplied the request is executed as a POST, if not it is executed as a GET.
Issuing a GET w/ a querystring requires mutating the `url` and omitting `data`. This surprised me at first, and probably a number of others
https://github.com/tarcieri/http
The support for keep-alive is particularly welcome, huge kudos to the author.
Question to users of other languages: do equivalents exist for PHP, Perl, C# or Java? Ruby folks rave about restclient, but is there anything else?
I do have a half-baked implementation on urllib2 that I hate. This is really cool.
https://github.com/tarcieri/http
httparty does a few of the same tricks, but I still find its API a bit obtrusive. At least it automatically parses JSON! (my library does this too, if an appropriate library is loaded)
In addition to a humane interface, it will soon be backed by a Ragel-generated HTTP parser:
https://github.com/tarcieri/http/tree/master/parser
Carl is working on a comprehensive event-driven HTTP (and Websockets) framework for Clojure. I'm just borrowing his parser and re-wrapping it in Ruby. I prefer to use Carl's as he's (at least for now) actively maintaining it, as opposed to using Zed's abandonware.
https://github.com/tarcieri/http/tree/master/parser
Probably others.
The new System.Net.Http.HttpClient in .NET 4.5 is closer to Requests and not entirely bad, if a little rigid.
And this one is a pet peeve, but I hate that verbose stateful OO idiom where you instantiate an object (with a factory) and then use setters to change properties, instead of setting it all in a single command. I don't know if other .NET HTTP libraries change that, though...
So's python's urllib2, the point of `request` is that as soon as you go even slightly beyond very basic GET and POST, it breaks down quickly in a horrible mess.
I'm still surprised every time I use it that they've not released a modern library for it in .Net.
Also check out the command line interface which allows you todo things like this:
ref: http://mojolicio.us/perldoc/Mojolicious/Guides/Cookbook#Comm...Also check out Mojo::UserAgent (https://metacpan.org/module/Mojo::UserAgent) for a nice(er) alternative. And don't forget that Perl now comes a nice lightweight alternative as standard: https://metacpan.org/module/HTTP::Tiny
This looks like all the other wrapper methods you spend 5 minutes doing, once, when you start a new codebase?
We may agree or disagree with the consensus of the masses, but the masses make the front page.
I'm glad when language quirks and libraries get linked, it's good for discussion. (And more informative than a good third of the stuff that gets linked.)
I gave a talk about this very thing at PyCodeConf this week. Here are the slides: http://python-for-humans.heroku.com
I'm still fairly new to gevent and I'm curious if others consider this good style for a library?
So yeah, this is suboptimal, but not the worst thing in the world. It should really be documented though.
It's pretty easy to implement, as it already works at the lower (socket) level with the ssl module, it just hasn't made it up the stack into urllib2 (or Requests..yet!).
This is false. A project released as GPL can also be released on another (commercial) license.
On a side note: last time I checked urllib2 (which actually drives Requests) could not do SSL requests over a proxy, which gave me the feeling that this implementation still isn't very mature.
One thing at a time :)
for me.
On two different machines, one OSX SL with Python 2.6 from MacPorts and the other Ubuntu 10.04.3 LTS with Python 2.6 via aptitude.
Can not find any solution for this via Google and its siblings.
I'm stuck :(
-jsl