Lets setup a virtual environment and install wheezy.core package:
virtualenv env env/bin/easy_install wheezy.coreLaunch python from virtual environment (env/bin/python) and try this:
>>> from wheezy.core.httpclient import HTTPClient >>> c = HTTPClient('http://buildbot.buildbot.net/json/') >>> c.get('project') 200 >>> project = c.json >>>> str(project.title) BuildbotHere is another example that demonstarates etag handling (the second time we request events the server responds with HTTP status code 304, not modified):
>>> base = 'https://api.github.com/repos/python/cpython/' >>> c = HTTPClient(base) >>> c.get('events') 200 >>> c.headers['content-encoding'] ['gzip'] >>> c.get('events') 304The HTTPClient supports HTTP(S) GET/HEAD/POST verbs, follows redirects, handles cookies and etags between requests, gzip content decoding.
Your project seems very interesting, looking to use it in future.
ReplyDeleteSuggestion: describe better what it does, purposes, etc.
Does you agree that "wheezy.core is a python package written in pure Python code. It provides core features. It is optimized for performance, well tested and documented." is very uninformative?
Thanks
Well, I hope get this improved over time.
DeleteIs this better than https://pypi.python.org/pypi/requests
ReplyDeleteKeep things simple.
DeleteHTTP in the real world is NOT simple. urllib2 failed not because it wasn't simple to use (btw, I don't agree with people who say it has bad API) but because it lacks many features needed in day-to-day work which requests/urllib3 provide out of the box. “Everything should be made as simple as possible, but no simpler.” - Albert Einstein
DeleteJust wanted to enumerate the features you are referencing to: gzip decoding, file posting, ssl verification, connection reuse... am I missing something? - Kšyštof
DeleteSo what was so complicated about Requests and urllib3 that you had to write your own http client library?
Delete16102 lines of python code in requests vs 3835 in urllib3 vs 255.
DeleteHow about timeout?
ReplyDeleteSupported by python 2.6+ (in seconds):
Deletec = HTTPClient(...)
c.connection.timeout = 10