API Reference

httsleep.httsleep(url_or_request, until=None, alarms=None, status_code=None, json=None, jsonpath=None, text=None, callback=None, auth=None, headers=None, polling_interval=2, max_retries=50, ignore_exceptions=None, loglevel=40)

Convenience wrapper for the HttSleeper class. Creates a HttSleeper object and automatically runs it.

Returns:requests.Response object.
class httsleep.HttSleeper(url_or_request, until=None, alarms=None, status_code=None, json=None, jsonpath=None, text=None, callback=None, auth=None, headers=None, polling_interval=2, max_retries=50, ignore_exceptions=None, loglevel=40)
Parameters:
  • url_or_request – either a string containing the URL to be polled, or a requests.Request object.
  • until – a list of success conditions, respresented by dicts, or a single success condition dict.
  • alarms – a list of error conditions, respresented by dicts, or a single error condition dict.
  • status_code – deprecated. Shorthand for a success condition dependent on the response’s status code.
  • json – Deprecated. Shorthand for a success condition dependent on the response’s JSON payload.
  • jsonpath – Deprecated. Shorthand for a success condition dependent on the evaluation of a JSONPath expression.
  • text – Deprecated. Shorthand for a success condition dependent on the response’s body payload.
  • callback – shorthand for a success condition dependent on a callback function that takes the response as an argument returning True.
  • auth – a (username, password) tuple for HTTP authentication.
  • headers – a dict of HTTP headers.
  • polling_interval – how many seconds to sleep between requests.
  • max_retries – the maximum number of retries to make, after which a StopIteration exception is raised.
  • ignore_exceptions – a list of exceptions to ignore when polling the endpoint.
  • loglevel – the loglevel to use. Defaults to ERROR.

url_or_request must be provided, along with at least one success condition (until).

run()

Polls the endpoint until either:

  • a success condition in self.until is reached, in which case a requests.Request object is returned
  • an error condition in self.alarms is encountered, in which case an Alarm exception is raised
  • self.max_retries is reached, in which case a StopIteration exception is raised
Returns:requests.Response object.

Exceptions

exception httsleep.exceptions.Alarm(response, alarm_condition)

Exception raised when an alarm condition has been met. Contains the following extra attributes:

  • response: The response the matched the alarm condition
  • alarm: The alarm condition that was triggered