Version 1 Base Classes

These classes are what pyTenable < 1.2 used for all interactions. They are here as most of the library will still use it until these have been phased out in favor of the newer RESTfly-derived classes.

As these classes exist only as a basis for the application packages, it isn’t recommended to use this directly. Further if you’re looking for a generic API interface to use for your own uses, take a look at the RESTfly library.

class APIResultsIterator(api, **kw)[source]

The API iterator provides a scalable way to work through result sets of any size. The iterator will walk through each page of data, returning one record at a time. If it reaches the end of a page of records, then it will request the next page of information and then continue to return records from the next page (and the next, and the next) until the counter reaches the total number of records that the API has reported.

Note that this Iterator is used as a base model for all of the iterators, and while the mechanics of each iterator may vary, they should all behave to the user in a similar manner.

count

The current number of records that have been returned

Type

int

page

The current page of data being walked through. pages will be cycled through as the iterator requests more information from the API.

Type

list

page_count

The number of record returned from the current page.

Type

int

total

The total number of records that exist for the current request.

Type

int

next()[source]

Ask for the next record

class APISession(url=None, retries=None, backoff=None, ua_identity=None, session=None, proxies=None, vendor=None, product=None, build=None, timeout=None)[source]

The APISession class is the base model for APISessions for different products and applications. This is the model that the APIEndpoints will be grafted onto and supports some basic wrapping of standard HTTP methods on it’s own.

Parameters
  • url (str, optional) –

    The base URL that the paths will be appended onto.

    For example, if you want to override the default URL base with _http://a.b.c/api_, you could then make a GET requests with self.get(‘item’). This would then inform APISession to construct a GET request to _http://ab.c./api/item_ and use whatever parameters you wanted to pass to the Requests Session object.

  • retries (int, optional) – The number of retries to make before failing a request. The default is 5.

  • backoff (float, optional) – If a 429 response is returned, how much do we want to backoff if the response didn’t send a Retry-After header.

  • ua_identity (str, optional) – An optional identifier for the application to discern it amongst other API calls.

delete(path, **kwargs)[source]

Initiates an HTTP DELETE request using the specified path. Refer to the requests.request for more detailed information on what keyword arguments can be passed:

Parameters
  • path (str) – The path to be appended onto the base URL for the request.

  • **kwargs (dict) – Keyword arguments to be passed to the Requests Sessions request method.

Returns

requests.Response

get(path, **kwargs)[source]

Initiates an HTTP GET request using the specified path. Refer to requests.request for more detailed information on what keyword arguments can be passed:

Parameters
  • path (str) – The path to be appended onto the base URL for the request.

  • **kwargs (dict) – Keyword arguments to be passed to the Requests Sessions request method.

Returns

requests.Response

head(path, **kwargs)[source]

Initiates an HTTP HEAD request using the specified path. Refer to the requests.request for more detailed information on what keyword arguments can be passed:

Parameters
  • path (str) – The path to be appended onto the base URL for the request.

  • **kwargs (dict) – Keyword arguments to be passed to the Requests Sessions request method.

Returns

requests.Response

patch(path, **kwargs)[source]

Initiates an HTTP PATCH request using the specified path. Refer to the requests.request for more detailed information on what keyword arguments can be passed:

Parameters
  • path (str) – The path to be appended onto the base URL for the request.

  • **kwargs (dict) – Keyword arguments to be passed to the Requests Sessions request method.

Returns

requests.Response

post(path, **kwargs)[source]

Initiates an HTTP POST request using the specified path. Refer to the requests.request for more detailed information on what keyword arguments can be passed:

Parameters
  • path (str) – The path to be appented onto the base URL for the request.

  • **kwargs (dict) – Keyword arguments to be passed to the Requests Sessions request method.

Returns

requests.Response

put(path, **kwargs)[source]

Initiates an HTTP PUT request using the specified path. Refer to the requests.request for more detailed information on what keyword arguments can be passed:

Parameters
  • path (str) – The path to be appended onto the base URL for the request.

  • **kwargs (dict) – Keyword arguments to be passed to the Requests Sessions request method.

Returns

requests.Response