Urlquick II: Requests, but with caching

PyPI Version Documentation Status Test Build Status Test Coverage Maintainability

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 to True will call resp.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.

exception urlquick.CacheError(*args, **kwargs)[source]

Session

class urlquick.Session

This class is idendical to the requests SESSION class, except for 2 small differences. The following parameters can also be set as a keyword only argument on all the request methods.

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:
  • tag (str) – [opt] Name of ‘element’ which is used to filter tree to required section.
  • attrs (dict) – [opt] Attributes of ‘element’, used when searching for required section. Attrs should be a dict of unicode key/value pairs.
Returns:

The root element of the element tree.

Return type:

xml.etree.ElementTree.Element

xml()[source]

Parse’s XML document into a element tree.

Returns:The root element of the element tree.
Return type:xml.etree.ElementTree.Element