blob: bf5c8affd52d6744b88987bf8c8298fd99b75eaa [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
jcgregorio864fa042007-02-14 03:37:33 +0000141<pre>svn co https://httplib2.svn.sourceforge.net/svnroot/httplib2/trunk httplib2</pre>
142
jcgregorio4ce467a2006-03-22 14:48:43 +0000143
jcgregoriof9c28352006-07-03 18:17:02 +0000144<h3>Documentation</h3>
145
146<p>In addition to the <a href="ref/">Python library style documentation</a> there
147are also two articles on XML.com, <a href="http://www.xml.com/pub/a/2006/02/01/doing-http-caching-right-introducing-httplib2.html">
148 Doing HTTP Caching Right: Introducing httplib2</a> and
149<a href="http://www.xml.com/pub/a/2006/03/29/httplib2-http-persistence-and-authentication.html">
150httplib2: HTTP Persistence and Authentication </a>.
151
152</p>
jcgregorio4ce467a2006-03-22 14:48:43 +0000153
154<h3>Feedback</h3>
155
156<p>Bugs and enhancement requests are handled through
157<a href="http://sourceforge.net/projects/httplib2/">SourceForge</a>, and anything is up for discussion
158on the <a href="http://sourceforge.net/mail/?group_id=161082">httplib2 mailing list</a>.
159</p>
160
161<h3>To Do</h3>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000162
163<p>This module is not perfect and needs the following:</p>
164<ul>
165 <li>Support for Proxies</li>
jcgregorioa39ff0a2007-02-14 03:41:53 +0000166 <li>A pluggable store for the cache is in place, with plugins for
167 flat files and memcached.
168 I eventually want to have plugins that allow keeping the cache in Berkeley DB, MySQL, etc.</li>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000169 <li>More unit tests</li>
170</ul>
171
jcgregorio4ce467a2006-03-22 14:48:43 +0000172<h3>Project Goal</h3>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000173
jcgregorio92ff8082006-07-31 13:43:28 +0000174<p>To become a worthy addition to the Python core library.</p>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000175
jcgregorio4ce467a2006-03-22 14:48:43 +0000176<h3>Additional Information</h3>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000177
178<p>
179 <dl>
180 <dt>Author</dt>
181 <dd>Joe Gregorio</dd>
182
183 <dt>License</dt>
184 <dd>MIT</dd>
185
186 <dt>Contributors</dt>
jcgregorio22a9e162006-03-22 14:45:46 +0000187
jcgregorio92088922006-07-01 05:53:21 +0000188 <dd> Thomas Broyer (t.broyer@ltgt.net) </dd>
189 <dd> James Antill </dd>
190 <dd> Xavier Verges Farrero </dd>
191 <dd> Jonathan Feinberg </dd>
192 <dd> Blair Zajac </dd>
193 <dd> (Your Name Here) </dd>
jcgregorio22a9e162006-03-22 14:45:46 +0000194 </dl>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000195</p>
196
jcgregorio1eed40f2006-02-15 18:56:46 +0000197 <p style="font-size: small">This page last updated on: $LastChangedDate$.</p>
jcgregorio2d66d4f2006-02-07 05:34:14 +0000198
199 </div>
200 </div>
201 <!--#include virtual="footer.html" -->
202 </div>
203</body>
204
205</html>