blob: cf847357e421f7ebccd5372579bc019db7e63ae1 [file] [log] [blame]
jcgregorio2d66d4f2006-02-07 05:34:14 +00001<html>
2<head>
3 <!--#include virtual="header.html" -->
4 <title>Joe Gregorio | BitWorking | Projects | httplib2.py</title>
5</head>
6<body class='main' id="top" name="top" >
7 <div class="body">
8 <!--#include virtual="titlebar.html" -->
9
10 <div class="content">
11
jcgregorio4ce467a2006-03-22 14:48:43 +000012 <div>
jcgregorio2d66d4f2006-02-07 05:34:14 +000013
14 <h2>Httplib2</h2>
15 <p>A comprehensive HTTP client library, <code>httplib2.py</code>
16 supports many features left out of other HTTP libraries.
17 </p>
18 <dl>
19 <dt>HTTP and HTTPS</dt>
20 <dd>HTTPS support is only available if the socket module was compiled with SSL support.
21 </dd>
22
23 <dt>Keep-Alive</dt>
24 <dd>Supports HTTP 1.1 Keep-Alive, keeping the socket
25 open and performing multiple requests over the same connection
26 if possible.
27 </dd>
28
29 <dt>Authentication</dt>
jcgregorio48bb3572006-08-28 17:31:06 +000030 <dd>The following types of HTTP Authentication are supported.
jcgregorio2d66d4f2006-02-07 05:34:14 +000031 These can be used over both HTTP and HTTPS.
32 <ul>
33 <li><a href="http://www.faqs.org/rfcs/rfc2617.html">Digest</a></li>
34 <li><a href="http://www.faqs.org/rfcs/rfc2617.html">Basic</a></li>
35 <li><a href="http://www.xml.com/pub/a/2003/12/17/dive.html">WSSE</a></li>
jcgregorio48bb3572006-08-28 17:31:06 +000036 <li><a href="http://franklinmint.fm/2006/02/28/draft-sayre-http-hmac-digest.html">HMAC Digest</a></li>
37 <li><a href="http://code.google.com/apis/accounts/AuthForInstalledApps.html">Google Account Authentication</a></li>
jcgregorio2d66d4f2006-02-07 05:34:14 +000038 </ul>
39 </dd>
40
41 <dt>Caching</dt>
42 <dd>The module can optionally operate with a private
43 cache that understands the Cache-Control: header and
44 uses both the ETag and Last-Modified cache validators.
45 </dd>
46
47 <dt>All Methods</dt>
48 <dd>The module can handle any HTTP request method, not just GET and POST.</dd>
49
50 <dt>Redirects</dt>
51 <dd>Automatically follows 3XX redirects on GETs.</dd>
52
53 <dt>Compression</dt>
jcgregorioa0713ab2006-07-01 05:21:34 +000054 <dd>Handles both 'deflate' and 'gzip' types of compression.</dd>
jcgregorio2d66d4f2006-02-07 05:34:14 +000055
56 <dt>Lost update support</dt>
57 <dd>Automatically adds back ETags into PUT requests to resources
58 we have already cached. This implements Section 3.2 of
59 <a href="http://www.w3.org/1999/04/Editing/#Table">Detecting the Lost Update Problem Using Unreserved Checkout</a></dd>
60
61 <dt>Unit Tested</dt>
62 <dd>A large and growing set of unit tests.</dd>
63
64 </dl>
65
jcgregorio4ce467a2006-03-22 14:48:43 +000066<h3>Usage</h3>
jcgregorio2d66d4f2006-02-07 05:34:14 +000067
68<p>A simple retrieval:</p>
69
jcgregoriob7753b32006-02-15 19:04:08 +000070<pre><code>import httplib2
71h = httplib2.Http(".cache")
72resp, content = h.request("http://example.org/", "GET")
jcgregorio2d66d4f2006-02-07 05:34:14 +000073</code></pre>
74
75<p>The 'content' is the content retrieved from the URL.
76The content is already decompressed or unzipped if necessary.
jcgregoriob7753b32006-02-15 19:04:08 +000077The 'resp' contains all the response headers.
jcgregorio2d66d4f2006-02-07 05:34:14 +000078</p>
79
80<p>To PUT some content to a server that uses SSL
81and Basic authentication:</p>
82
jcgregoriob7753b32006-02-15 19:04:08 +000083<pre><code>import httplib2
84h = httplib2.Http(".cache")
jcgregorioe34942d2006-05-08 01:06:37 +000085h.add_credentials('name', 'password')
jcgregoriob7753b32006-02-15 19:04:08 +000086resp, content = h.request("https://example.org/chap/2",
87 "PUT", body="This is text",
88 headers={'content-type':'text/plain'} )
jcgregorio2d66d4f2006-02-07 05:34:14 +000089</code></pre>
90
91<p>Use the Cache-Control: header to control
92 how the caching operates.</p>
93
jcgregoriob7753b32006-02-15 19:04:08 +000094<pre><code>import httplib2
95h = httplib2.Http(".cache")
96resp, content = h.request("http://bitworking.org/")
97 ...
98resp, content = h.request("http://bitworking.org/",
99 headers={'cache-control':'no-cache'})
jcgregorio2d66d4f2006-02-07 05:34:14 +0000100</code></pre>
101
102<p>The first request will be cached and since this is a request to
103bitworking.org it will be set to be cached for two hours, because
104that is how I have my server configured.
105Any subsequent GET to that URI will return the value from the
106on-disk cache and no request will be made to the server.
107You can use the Cache-Control: header to change the caches behavior and
108in this example the second request adds the Cache-Control: header with a value
109of 'no-cache' which tells the library that the cached copy
110must not be used when handling this request.
111</p>
112
jcgregorio4ce467a2006-03-22 14:48:43 +0000113<h3>Requirements</h3>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000114
jcgregorio1eed40f2006-02-15 18:56:46 +0000115<p>Requires Python 2.3 or later. Does not require
jcgregorio2d66d4f2006-02-07 05:34:14 +0000116any libraries beyond what is found in the core library.</p>
117
jcgregorio4ce467a2006-03-22 14:48:43 +0000118<h3>Download/Installation</h3>
jcgregorio1eed40f2006-02-15 18:56:46 +0000119
jcgregorio1ad5dd52006-07-01 19:36:36 +0000120<p>The latest release of httplib2 is 0.2.0 and
121can be <a href="dist">downloaded from the from
122 the dist directory</a>. See the
123<a href="CHANGELOG">CHANGELOG</a> for what's new in this
124version.</p>
125
126
jcgregorio1eed40f2006-02-15 18:56:46 +0000127<p>The httplib2 module is shipped as a distutils package. To install
128the library, first unpack the distribution archive, and issue the following
129command:</p>
130
131<pre><code>$ python setup.py install</code></pre>
132
133<p><a href="dist">Download the distribution archives from here</a>. </p>
134
135<p> <a href="test">The resources used in the unit test cases</a>
136 are available also. More documentation on them will be forthcoming.</p>
137
jcgregorioec114932006-03-03 16:23:26 +0000138<p>You can also get the sources directly from the SourceForge hosted
139 subversion repository.</p>
140
jcgregorio4ce467a2006-03-22 14:48:43 +0000141<pre>svn co https://svn.sourceforge.net/svnroot/httplib2/trunk httplib2</pre>
142
jcgregoriof9c28352006-07-03 18:17:02 +0000143<h3>Documentation</h3>
144
145<p>In addition to the <a href="ref/">Python library style documentation</a> there
146are also two articles on XML.com, <a href="http://www.xml.com/pub/a/2006/02/01/doing-http-caching-right-introducing-httplib2.html">
147 Doing HTTP Caching Right: Introducing httplib2</a> and
148<a href="http://www.xml.com/pub/a/2006/03/29/httplib2-http-persistence-and-authentication.html">
149httplib2: HTTP Persistence and Authentication </a>.
150
151</p>
jcgregorio4ce467a2006-03-22 14:48:43 +0000152
153<h3>Feedback</h3>
154
155<p>Bugs and enhancement requests are handled through
156<a href="http://sourceforge.net/projects/httplib2/">SourceForge</a>, and anything is up for discussion
157on the <a href="http://sourceforge.net/mail/?group_id=161082">httplib2 mailing list</a>.
158</p>
159
160<h3>To Do</h3>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000161
162<p>This module is not perfect and needs the following:</p>
163<ul>
164 <li>Support for Proxies</li>
jcgregorio1ad5dd52006-07-01 19:36:36 +0000165 <li><del>A pluggable store for the cache.</del> Right now the store is just flat files in a directory.
166 I would like to have plugins that allow keeping the cache in Berkeley DB, <del>memcached</del>, Squid, MySQL, etc.</li>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000167 <li>More unit tests</li>
168</ul>
169
jcgregorio4ce467a2006-03-22 14:48:43 +0000170<h3>Project Goal</h3>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000171
jcgregorio92ff8082006-07-31 13:43:28 +0000172<p>To become a worthy addition to the Python core library.</p>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000173
jcgregorio4ce467a2006-03-22 14:48:43 +0000174<h3>Additional Information</h3>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000175
176<p>
177 <dl>
178 <dt>Author</dt>
179 <dd>Joe Gregorio</dd>
180
181 <dt>License</dt>
182 <dd>MIT</dd>
183
184 <dt>Contributors</dt>
jcgregorio22a9e162006-03-22 14:45:46 +0000185
jcgregorio92088922006-07-01 05:53:21 +0000186 <dd> Thomas Broyer (t.broyer@ltgt.net) </dd>
187 <dd> James Antill </dd>
188 <dd> Xavier Verges Farrero </dd>
189 <dd> Jonathan Feinberg </dd>
190 <dd> Blair Zajac </dd>
191 <dd> (Your Name Here) </dd>
jcgregorio22a9e162006-03-22 14:45:46 +0000192 </dl>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000193</p>
194
jcgregorio1eed40f2006-02-15 18:56:46 +0000195 <p style="font-size: small">This page last updated on: $LastChangedDate$.</p>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000196
197 </div>
198 </div>
199 <!--#include virtual="footer.html" -->
200 </div>
201</body>
202
203</html>