Urlquick II: Requests, but with caching¶
Urlquick II¶
Urlquick 2 is a wrapper for requests that add’s support for http caching. It acts just like requests but with a few extra parameters and features. ‘Requests’ itself is left untouched.
All GET, HEAD and POST requests are cached locally for a period of 4 hours, this can be changed. When the cache expires, conditional headers are added to any new request e.g. “Etag” and “Last-modified”. Then if the server returns a 304 Not-Modified response, the cache is used, saving having to re-download the content body.
All of Requests get
, head
, post
and request
functions/methods all get 2 extra optional parameters.
Both these 2 parameters can also be set on a session object too.
max_age
: Age the ‘cache’ can be before it’s considered stale.raise_for_status
: Boolean that when set toTrue
will callresp.raise_for_status()
for you automatically.
The Requests response objects also gets too new methods.
parse()
: Parse’s “HTML” document into a element tree using HTMLement.xml()
: Parse’s XML document into a element tree.
API¶
Globals¶
-
urlquick.
MAX_AGE
= 14400¶ The time in seconds where a cache item is considered stale. Stale items will stay in the database to allow for conditional headers.
-
urlquick.
CACHE_LOCATION
= "."¶ Location for the cache directory. Defaults to the current working directory.
Session¶
Response¶
-
class
urlquick.
Response
[source]¶ This class is idendical to the requests RESPONSE class, except for 2 small differences.
-
parse
(tag='', attrs=None)[source]¶ Parse’s “HTML” document into a element tree using HTMLement.
See also
The htmlement documentation can be found at.
http://python-htmlement.readthedocs.io/en/stable/?badge=stable
Parameters: Returns: The root element of the element tree.
Return type:
-
xml
()[source]¶ Parse’s XML document into a element tree.
Returns: The root element of the element tree. Return type: xml.etree.ElementTree.Element
-
External Links¶
Requests Docs: https://requests.readthedocs.io/en/master/
HTMLement Docs: https://python-htmlement.readthedocs.io/en/stable/?badge=stable
Requests Docs: https://requests.readthedocs.io/en/master/
Bug Tracker: https://github.com/willforde/urlquick/issues