9 ms·
Requests, Python HTTP for Humans, reached v1.0
- jimmytucson 14y agoCan we all agree that it's a little weird to pause mid-article to fawn upon one's own code? I love Kenneth Reitz and admire his skill but "come on, man."
- mattdeboard 14y agoNo, we can't all agree that anything about that post was "weird". I didn't even see any "fawning". Just someone who's enthusiastic about his code. It's ok to love something you made and let people you think it's great. "Fawning" doesn't even mean what you think it means.
- kenneth_reitz 14y agoYeah, it's not like I want to tattoo the source code all over my body or anything.
- Rayne 14y agoWell, now I kind of want you to.
- dguaraglia 14y agoHaha, on the other hand, one of the typical interview questions is 'mention something you built that you are proud of'. A developer's satisfaction with his own craftsmanship is, to me, a must.
- slurgfest 14y agoSo you can't just produce good, solid output without congratulating yourself in public? Interesting.
- dguaraglia 14y agoNo, what I meant is that if someone is proud of their code and aren't afraid to share it with the world you should know probably lighten the hell up and let them be.
- jimmytucson 14y agoI wasn't trying to be mean, I just chuckled when you said, "Beautiful." I'm grateful for the love and care you've put into libraries like 'requests'. When I've been toiling away at a program for hours and it winds up resembling something like spaghetti mixed with beer shits, I find that if I stop and study some of your code, I am instantly a better programmer.
- kenneth_reitz 14y agoOh, I was just poking fun at the guy that responded. He has a testimonial on the requests homepage: http://docs.python-requests.org/en/v1.0.0/ http://docs.python-requests.org/en/v1.0.0/ > I’m going to get @kennethreitz’s Python requests module tattooed on my body, somehow. The whole thing. — Matt DeBoard
- mattdeboard 14y agoNow that sounds like a great idea.
- Radim 14y agoGood job I guess (I use `requests` all the time and didn't even notice any issues, that's how neat it is). But the marketing-speak here makes my hair bristle! "Requests is SEXY AWESOME!" "No wait, it's crap, complex, hard-to-follow code. But the NEW version is SEXY AWESOME!" (...at least until the next release, I suppose)
- kenneth_reitz 14y agoThe developer interface was elegant, but the internal code left something to be desired. That is no longer the case.
- Goranek 14y agoDude you are my hero. I've printed requests source code and use it as an example of great python code. You and guys like Armin Ronacher are the reason why I use and like Python so much !!! (when jerking stops) Question: I have a feeling that with Requests you're just hiding the problem and not trying to solve it (Urllib is still in the back). Shouldn't urllib(1,2,3...) be rewritten instead?
- jevinskie 14y agoProbably, but rewriting a core module (this would be urllib4!?) is a lot harder (politically at least) than creating a 3rd party wrapper module.
- kenneth_reitz 14y agoThanks! Urllib isn't used at all, actually. Internally, I use a project called 'urllib3', but it's totally unrelated to urlilb. It's name is actually a joke. It is essentially a light wrapper around httplib that provides connection pooling :)
- ak217 14y agoBy the way, I found a bug in httplib where, when sending a request body, if the peer closes the socket early with an error (HTTP/1.1 compliant behavior), the request will time out instead of returning the correct error information. To my knowledge, this is also present in httplib2. This is because the socket write in both libraries is blocking (which seems simply wrong). I'm hoping to send a patch sometime soon. Regardless, httplib2 seems to have lots of other technical advantages over httplib - have you considered using it?
- fatbird 14y agoCongratulations Kenneth! Well earned, well deserved.
- graue 14y agoIs the blog post the only direct documentation of what needs to change to upgrade to 1.0? Details seem relatively scant. But maybe that's because response.json() is the only feature I'm using that changed...
- domrdy 14y agoVery nice, Thank you! I'm curious, why did you remove the json property?
- gardarh 14y agoI just started using requests and one of the first questions I asked myself was "Hey, why isnt't this a function rather than a property?" . I'm not that seasoned python developer but it feels wrong to me that you have to perform work in order to calculate a property, making it a function feels more explicit about that "there is work being done here". Requests is great by the way, had already written some code to abstract away the urllib/urllib2 mess but this module is so much more complete (of course) and cleaner.
- sophacles 14y agoI actually disagree with this - the point of properties (in many languages) is to handle exactly the case of "there may be some transforms on this data, and they depend on internals, but really it is just a data view, it should be accessible like other data." A good example is C#/.NET issues (and somewhat java) where you have .length .Length and .Length() and .Size() and .Count() and so on. It makes changing a data type an exercise in annoyance, and on the one hand there is a decent argument about semantic meaning of the name, on the other hand, tracking each and every subtle use of "I need to know how many things I'm dealing with" in several different ways becomes an exercise in yak shaving. As for the specific of .json - A lot of python web frameworks provide a .json attribute/property to the request structure, so I presume the earlier version of Requests was mirroring that for conceptual continuity.
- kenneth_reitz 14y agoThe issue is you don't want to raise an exception when returning a property.
- gardarh 14y agoI was dead wrong on what the issue was, but the actual explanation does actually hint that that doing error-prone calculation (such as deserialization) to magically calculate a property is not a good idea. I haven't seen the .json property used before but that only shows that I haven't looked into that many frameworks. I'm not sure why java uses .length for arrays and .size() for collections ... but could it be that it was for similar reasons?
- aidos 14y agoCongrats, Kenneth - Requests is a very nice library. I've been using it a lot recently (though I've never had to go too deep into it). I'm impressed with the simplification and removal of code in this release. If only that was a goal for every project :)
- pjscott 14y agoA nice thing about requests is that you almost never have to go deep into it. Out of the box, it almost always just does what you want. That's harder than it sounds, as evidenced by the failure of the standard library's urllib and urllib2 modules.
- cmancini 14y agoCongrats. Requests has been super useful to me. Awesome stuff.
- SiVal 14y agoThis sounds great. I assume it's Python 3, right?
- kenneth_reitz 14y ago2.6–3.3
- SiVal 14y agoWoo hoo! If you don't mind a suggestion, you might add that fact to your feature list. It can hardly be taken for granted and is a very important feature to those who are already past their legacy upgrade hurdles.
- TorKlingberg 14y agoIf you can share some advice on Python 2/3 compatibility that would we very interesting. Especially things related to Unicode and testing. I see you have a single codebase for both versions. That is the same approach I took with my (much smaller) library, but several people advised against it. I also see you have very few "from __future__ import ..." Is that a conscious decision? In any case, thank you! I will use Requests as an example to follow.
- tshepang 14y agoUsing a single codebase for both Python 2 and 3 seems the most fashionable thing these days. It is, after all, the approach followed by Pyramid and Django. I also think it makes maintenance easier. The __future__ import is a consequence of it.
- jkbr 14y agoCongrats, Kenneth! Any hints on how to solve these incompatibilities between HTTPie and Requests v1.0 appreciated: https://github.com/jkbr/httpie/issues/113 https://github.com/jkbr/httpie/issues/113.
- kros 14y agoNext step... Tablib v1.0? ;)
- kenneth_reitz 14y agoActually, yes :)
- kros 14y agoGreat! There is a problem with pip install tablib: http://dpaste.com/hold/847350/ http://dpaste.com/hold/847350/ xlwt3 development stopped: http://pypi.python.org/pypi/xlwt3/0.1.2 http://pypi.python.org/pypi/xlwt3/0.1.2 Maybe xlwt3 could be replace by openpyxl? http://pypi.python.org/pypi/openpyxl/1.6.1 http://pypi.python.org/pypi/openpyxl/1.6.1
- kenneth_reitz 14y agoGoing to do something similar. Remove all the formats. Pull them into separate libraries.
- takluyver 14y agoxlrd is going to get Python 3 compatibility: https://github.com/python-excel/xlrd/pull/21 https://github.com/python-excel/xlrd/pull/21 Once that's done, someone has volunteered to add Python 3 support to xlwt as well. openpyxl isn't a direct replacement: it uses the XML-based xlsx format, whereas xlrd/xlwt use the binary xls format.
- shill 14y agoI was hoping Dates & Times for Humans would be next. ;)
- alexholehouse 14y agoThis is great new - I recently integrated requests into my current project, and it's made many things a lot easier!
- mixmastamyk 14y agoGreat work. It's a shame these nice libs weren't built a few years ago, they might have had a chance to become the default in python3. Would be a killer feature to push more people to it. "The entire codebase has been rearchitected" I hope there are a few tests to check for regressions? ;)
- SoftwareMaven 14y agoThis is the part that concerns me. Generally, I think of code tightening in on a release, which major swings early in the processes and minor tweaks later. While I all for everything that happened in this change, I wonder if a 0.2 (or even 0.9) would have been appropriate first. Version x.0 in open source software implies "this is ready for production" (as opposed to commercial software, where it seems to mean "let the beta test really commence). (I just noticed it is at 1.0.2 now. I think I'm going to have to give this a couple weeks before I upgrade any of my projects.)
- j-kidd 14y agoLook out for the change to the Request constructor that makes `url` no longer the first parameter. Rather poor backward compatibility there.
- sethish 14y agoIt's a major revision number change, that's the only time to do such a major api change.
- j-kidd 14y agoWhile your point is valid, I didn't expect this to happen with requests. Just two weeks ago, I was telling my colleague that requests is such a nice library, we have nothing to worry about when installing a new version. Simply grab the latest! Then 1.0 happens. I have now moved requests to the "thoroughly test before upgrade" pile.
- isabre 14y agoUsed Requests in one of my projects. Definitely one of the best modules out there. Great news for all Python devs.
- leoplct 14y agoWhat's the equivalent for Ruby?
- nilved 14y agohttparty
- Goopplesoft 14y agoRestclient as well from https://github.com/archiloque/rest-client https://github.com/archiloque/rest-client
- nicolasp 14y agoIs the verbose mode still around? Not having any configuration is nice, but what replaces this? session.config['verbose'] = sys.stderr I couldn't find anything about it in the API docs.
- kenneth_reitz 14y agoI replaced it with real logging! Need to show how to use it in the docs still.
- michaelmior 14y agoLooks great! Unfortunately this broke one of our external dependencies which was careless enough to specify any version greater than 0.14.
- j-kidd 14y agoThis is why we should maintain our own pypi repository. Your external dependency did nothing wrong.
- beaumartinez 14y agoWow, that's annoying. Which project was it? Could you let them know, perhaps pull request a fix?
- antoncohen 14y agoThe choice of Apache 2.0 for the license is interesting. It makes the library incompatible with GPLv2 software[1], but compatible with being integrated into the Python standard library[2]. [1] http://www.gnu.org/licenses/license-list.html#apache2 http://www.gnu.org/licenses/license-list.html#apache2 [2] http://wiki.python.org/moin/PythonSoftwareFoundationLicenseFaq#line-75 http://wiki.python.org/moin/PythonSoftwareFoundationLicenseF...
- DArcMattr 14y agoI'd hardly characterize the ISC license as "esoteric". It's fairly compact, yet plain in its language. Apache 2.0 takes a lawyer's help in trying to understand.
- funkiee 14y agoThere's this interesting narrative that develops from time to time in Hacker News. Maybe it's just observer bias, but I had never heard of requests for Python until I read an article on HN about scraping, which in turn got me interested in Python, and now a week later a major release of Requests happens with a top story on HN.
- bob_hancock 14y agoLast week, I showed requests to a class of sysadmins to whom I was teaching Python and they were blown away. Great work.