blob: da6c640bc5750e19c93eefd6b6abbbd5aac8fc7e [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>
30 <dd>The following three types of HTTP Authentication are supported.
31 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>
36 </ul>
37 </dd>
38
39 <dt>Caching</dt>
40 <dd>The module can optionally operate with a private
41 cache that understands the Cache-Control: header and
42 uses both the ETag and Last-Modified cache validators.
43 </dd>
44
45 <dt>All Methods</dt>
46 <dd>The module can handle any HTTP request method, not just GET and POST.</dd>
47
48 <dt>Redirects</dt>
49 <dd>Automatically follows 3XX redirects on GETs.</dd>
50
51 <dt>Compression</dt>
jcgregorioa0713ab2006-07-01 05:21:34 +000052 <dd>Handles both 'deflate' and 'gzip' types of compression.</dd>
jcgregorio2d66d4f2006-02-07 05:34:14 +000053
54 <dt>Lost update support</dt>
55 <dd>Automatically adds back ETags into PUT requests to resources
56 we have already cached. This implements Section 3.2 of
57 <a href="http://www.w3.org/1999/04/Editing/#Table">Detecting the Lost Update Problem Using Unreserved Checkout</a></dd>
58
59 <dt>Unit Tested</dt>
60 <dd>A large and growing set of unit tests.</dd>
61
62 </dl>
63
jcgregorio4ce467a2006-03-22 14:48:43 +000064<h3>Usage</h3>
jcgregorio2d66d4f2006-02-07 05:34:14 +000065
66<p>A simple retrieval:</p>
67
jcgregoriob7753b32006-02-15 19:04:08 +000068<pre><code>import httplib2
69h = httplib2.Http(".cache")
70resp, content = h.request("http://example.org/", "GET")
jcgregorio2d66d4f2006-02-07 05:34:14 +000071</code></pre>
72
73<p>The 'content' is the content retrieved from the URL.
74The content is already decompressed or unzipped if necessary.
jcgregoriob7753b32006-02-15 19:04:08 +000075The 'resp' contains all the response headers.
jcgregorio2d66d4f2006-02-07 05:34:14 +000076</p>
77
78<p>To PUT some content to a server that uses SSL
79and Basic authentication:</p>
80
jcgregoriob7753b32006-02-15 19:04:08 +000081<pre><code>import httplib2
82h = httplib2.Http(".cache")
jcgregorioe34942d2006-05-08 01:06:37 +000083h.add_credentials('name', 'password')
jcgregoriob7753b32006-02-15 19:04:08 +000084resp, content = h.request("https://example.org/chap/2",
85 "PUT", body="This is text",
86 headers={'content-type':'text/plain'} )
jcgregorio2d66d4f2006-02-07 05:34:14 +000087</code></pre>
88
89<p>Use the Cache-Control: header to control
90 how the caching operates.</p>
91
jcgregoriob7753b32006-02-15 19:04:08 +000092<pre><code>import httplib2
93h = httplib2.Http(".cache")
94resp, content = h.request("http://bitworking.org/")
95 ...
96resp, content = h.request("http://bitworking.org/",
97 headers={'cache-control':'no-cache'})
jcgregorio2d66d4f2006-02-07 05:34:14 +000098</code></pre>
99
100<p>The first request will be cached and since this is a request to
101bitworking.org it will be set to be cached for two hours, because
102that is how I have my server configured.
103Any subsequent GET to that URI will return the value from the
104on-disk cache and no request will be made to the server.
105You can use the Cache-Control: header to change the caches behavior and
106in this example the second request adds the Cache-Control: header with a value
107of 'no-cache' which tells the library that the cached copy
108must not be used when handling this request.
109</p>
110
jcgregorio4ce467a2006-03-22 14:48:43 +0000111<h3>Requirements</h3>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000112
jcgregorio1eed40f2006-02-15 18:56:46 +0000113<p>Requires Python 2.3 or later. Does not require
jcgregorio2d66d4f2006-02-07 05:34:14 +0000114any libraries beyond what is found in the core library.</p>
115
jcgregorio4ce467a2006-03-22 14:48:43 +0000116<h3>Download/Installation</h3>
jcgregorio1eed40f2006-02-15 18:56:46 +0000117
118<p>The httplib2 module is shipped as a distutils package. To install
119the library, first unpack the distribution archive, and issue the following
120command:</p>
121
122<pre><code>$ python setup.py install</code></pre>
123
124<p><a href="dist">Download the distribution archives from here</a>. </p>
125
126<p> <a href="test">The resources used in the unit test cases</a>
127 are available also. More documentation on them will be forthcoming.</p>
128
jcgregorioec114932006-03-03 16:23:26 +0000129<p>You can also get the sources directly from the SourceForge hosted
130 subversion repository.</p>
131
jcgregorio4ce467a2006-03-22 14:48:43 +0000132<pre>svn co https://svn.sourceforge.net/svnroot/httplib2/trunk httplib2</pre>
133
134
135<h3>Feedback</h3>
136
137<p>Bugs and enhancement requests are handled through
138<a href="http://sourceforge.net/projects/httplib2/">SourceForge</a>, and anything is up for discussion
139on the <a href="http://sourceforge.net/mail/?group_id=161082">httplib2 mailing list</a>.
140</p>
141
142<h3>To Do</h3>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000143
144<p>This module is not perfect and needs the following:</p>
145<ul>
146 <li>Support for Proxies</li>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000147 <li>A pluggable store for the cache. Right now the store is just flat files in a directory.
148 I would like to have plugins that allow keeping the cache in Berkeley DB, Squid, MySQL, etc.</li>
149 <li>More unit tests</li>
150</ul>
151
jcgregorio4ce467a2006-03-22 14:48:43 +0000152<h3>Project Goal</h3>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000153
154<p>To become a worthy addition to the Pyhton core library.</p>
155
jcgregorio4ce467a2006-03-22 14:48:43 +0000156<h3>Additional Information</h3>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000157
158<p>
159 <dl>
160 <dt>Author</dt>
161 <dd>Joe Gregorio</dd>
162
163 <dt>License</dt>
164 <dd>MIT</dd>
165
166 <dt>Contributors</dt>
jcgregorio22a9e162006-03-22 14:45:46 +0000167
jcgregorio92088922006-07-01 05:53:21 +0000168 <dd> Thomas Broyer (t.broyer@ltgt.net) </dd>
169 <dd> James Antill </dd>
170 <dd> Xavier Verges Farrero </dd>
171 <dd> Jonathan Feinberg </dd>
172 <dd> Blair Zajac </dd>
173 <dd> (Your Name Here) </dd>
jcgregorio22a9e162006-03-22 14:45:46 +0000174 </dl>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000175</p>
176
jcgregorio1eed40f2006-02-15 18:56:46 +0000177 <p style="font-size: small">This page last updated on: $LastChangedDate$.</p>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000178
179 </div>
180 </div>
181 <!--#include virtual="footer.html" -->
182 </div>
183</body>
184
185</html>