pypureclient package

Subpackages

Submodules

pypureclient.api_token_manager module

class pypureclient.api_token_manager.APITokenManager(token_endpoint, api_token, verify_ssl=True)

Bases: object

A APITokenManager is to handle api token-based authentication for REST 2.X API calls internally. A valid session token is stored in memory.

__init__(token_endpoint, api_token, verify_ssl=True)

Initialize a APITokenManager. Should be treated as a static object.

Parameters:
  • token_endpoint (str) – URL to POST to for exchanging an API token for a session token.
  • api_token (str) – API token for the user.
Raises:

PureError – If there was any issue retrieving an session token.

get_session_token(refresh=False)

Get the last used session token.

Parameters:refresh (bool, optional) – Whether to retrieve a new session token. Defaults to False.
Returns:str
Raises:PureError – If there was an error retrieving an session token.

pypureclient.client_settings module

pypureclient.exceptions module

exception pypureclient.exceptions.PureError(reason=None)

Bases: Exception

Exception type raised by Pure Storage code.

pypureclient.keywords module

class pypureclient.keywords.Headers

Bases: object

A class for static header names.

api_token = 'api-token'
authorization = 'Authorization'
x_auth_token = 'x-auth-token'
x_ratelimit_min = 'X-RateLimit-Limit-minute'
x_ratelimit_remaining_min = 'X-RateLimit-Remaining-minute'
x_ratelimit_remaining_sec = 'X-RateLimit-Remaining-second'
x_ratelimit_sec = 'X-RateLimit-Limit-second'
x_request_id = 'X-Request-ID'
class pypureclient.keywords.Parameters

Bases: object

A class for static parameter names.

continuation_token = 'continuation_token'
filter = 'filter'
limit = 'limit'
offset = 'offset'
sort = 'sort'
x_request_id = 'x_request_id'
class pypureclient.keywords.Responses

Bases: object

A class for static response names.

context = 'context'
errors = 'errors'
message = 'message'

pypureclient.properties module

class pypureclient.properties.Filter(operation, operand1, operand2=None)

Bases: object

A Filter object models a filter string by keeping track of operations between Properties, values, and other Filters. It is converted to a string when calling any API and can also be replaced by a string.

__and__(other)

The & operator. Create a Filter that is the AND of two Filters.

Parameters:other (Filter) – The Filter to AND.
Returns:Filter
Raises:PureError – If other is not of the proper type.
__init__(operation, operand1, operand2=None)

Initialize a Filter. Should not be used directly. Instead, use the static methods to create Filters.

Parameters:
  • operation (_Operation) – The operation.
  • operand1 (any) – The first operand.
  • operand2 (any, optional) – The second operand, if the operation is binary. Defaults to None.
__invert__()

The ~ operator. Create a Filter that is the inverse of another Filter.

Returns:Filter
__or__(other)

The | operator. Create a Filter that is the OR of two Filters.

Parameters:other (Filter) – The Filter to OR.
Returns:Filter
Raises:PureError – If other is not of the proper type.
__repr__()

Return the string value of the Filter.

Returns:str
static and_(operand1, operand2)

Create a Filter that is the AND of two Filters.

Parameters:
  • operand1 (Filter) – The first Filter.
  • operand2 (Filter) – The second Filter.
Returns:

Filter

Raises:

PureError – If either operand is not of the proper type.

static contains(operand1, operand2)

Create a Filter that checks for substring containment.

Parameters:
  • operand1 (Property, str) – The Property to check.
  • operand2 (str) – The value to check for.
Returns:

Filter

Raises:

PureError – If either operand is not of the proper type.

static eq(operand1, operand2)

Create a Filter that checks for equality.

Parameters:
  • operand1 (Property, str) – The Property to compare.
  • operand2 (str, int, bool) – The value to compare to.
Returns:

Filter

Raises:

PureError – If either operand is not of the proper type.

static exists(operand1)

Create a Filter that checks for existance of a Property.

Parameters:operand1 (Property, str) – The Property to check for.
Returns:Filter
Raises:PureError – If the operand is not of the proper type.
static ge(operand1, operand2)

Create a Filter that checks for greater than or equal.

Parameters:
  • operand1 (Property, str) – The Property to compare.
  • operand2 (str, int) – The value to compare to.
Returns:

Filter

Raises:

PureError – If either operand is not of the proper type.

static gt(operand1, operand2)

Create a Filter that checks for greater than.

Parameters:
  • operand1 (Property, str) – The Property to compare.
  • operand2 (str, int) – The value to compare to.
Returns:

Filter

Raises:

PureError – If either operand is not of the proper type.

static in_(operand1, operand2)

Create a Filter that checks if a Property is in a list of values.

Parameters:
  • operand1 (Property, str) – The Property to check.
  • operand2 (list[str], list[int]) – The list of values.
Returns:

Filter

Raises:

PureError – If either operand is not of the proper type.

static le(operand1, operand2)

Create a Filter that checks for less than or equal.

Parameters:
  • operand1 (Property, str) – The Property to compare.
  • operand2 (str, int) – The value to compare to.
Returns:

Filter

Raises:

PureError – If either operand is not of the proper type.

static lt(operand1, operand2)

Create a Filter that checks for less than.

Parameters:
  • operand1 (Property, str) – The Property to compare.
  • operand2 (str, int) – The value to compare to.
Returns:

Filter

Raises:

PureError – If either operand is not of the proper type.

static ne(operand1, operand2)

Create a Filter that checks for inequality.

Parameters:
  • operand1 (Property, str) – The Property to compare.
  • operand2 (str, int, bool) – The value to compare to.
Returns:

Filter

Raises:

PureError – If either operand is not of the proper type.

static not_(operand1)

Create a Filter that is the inverse of another Filter.

Parameters:operand1 (Filter) – The Filter to invert.
Returns:Filter
Raises:PureError – If the operand is not of the proper type.
static or_(operand1, operand2)

Create a Filter that is the OR of two Filters.

Parameters:
  • operand1 (Filter) – The first Filter.
  • operand2 (Filter) – The second Filter.
Returns:

Filter

Raises:

PureError – If either operand is not of the proper type.

static tags(operand1, operand2)

Create a Filter that checks for a key-value tag.

Parameters:
  • operand1 (str) – The key of the tag.
  • operand2 (str) – The value of the tag.
Returns:

Filter

Raises:

PureError – If either operand is not of the proper type.

class pypureclient.properties.Property(value)

Bases: object

A Property object models a property of a resource and allows for easy compounding, sorting, and filtering with them. It is converted to a string when calling any API and can also be replaced by a string.

__add__(other)

The + operator. Create a subproperty.

Parameters:other (Property) – The Property to be the subproperty of the given Property.
Returns:Property
Raises:PureError – If other is not of the proper type.
__eq__(other)

The == operator. Create a Filter that checks for equality.

Parameters:other (str, int, bool) – The value to compare to.
Returns:Filter
Raises:PureError – If other is not of the proper type.
__ge__(other)

The >= operator. Create a Filter that checks for greater than or equal.

Parameters:other (str, int) – The value to compare to.
Returns:Filter
Raises:PureError – If other is not of the proper type.
__getitem__(index)

The [] operator. Create a list Property with the given index.

Parameters:index (str) – The list index to use.
Returns:Property
Raises:PureError – If index is not “all” or “any”.
__gt__(other)

The > operator. Create a Filter that checks for greater than.

Parameters:other (str, int) – The value to compare to.
Returns:Filter
Raises:PureError – If other is not of the proper type.
__init__(value)

Initialize a Property.

Parameters:value (str) – The name of the property.
__le__(other)

The <= operator. Create a Filter that checks for less than or equal.

Parameters:other (str, int) – The value to compare to.
Returns:Filter
Raises:PureError – If other is not of the proper type.
__lt__(other)

The < operator. Create a Filter that checks for less than.

Parameters:other (str, int) – The value to compare to.
Returns:Filter
Raises:PureError – If other is not of the proper type.
__ne__(other)

The != operator. Create a Filter that checks for inequality.

Parameters:other (str, int, bool) – The value to compare to.
Returns:Filter
Raises:PureError – If other is not of the proper type.
__repr__()

Return the string value of the Property.

Returns:str
all()

Create a list Property indexed by “all”.

Returns:Property
any()

Create a list Property indexed by “any”.

Returns:Property
ascending()

Create a Property that can be sorted in ascending order.

Returns:Property
descending()

Create a property that can be sorted in descending order.

Returns:Property
exists()

Create a Filter that checks for existance of the given Property.

Returns:Filter
subproperty(other)

Create a subproperty.

Parameters:other (Property) – The Property to be the subproperty of the given Property.
Returns:Property
Raises:PureError – If other is not of the proper type.

pypureclient.responses module

class pypureclient.responses.ApiError(context, message)

Bases: object

An object that models the error response from the server.

__init__(context, message)

Initialize an ApiError.

Parameters:
  • context (str) – The context in which the error occurred.
  • message (str) – The error message.
__repr__()

Return a pretty formatted string of the object.

Returns:str
to_dict()

Return a dictionary of the class attributes.

Returns:dict
class pypureclient.responses.ErrorResponse(status_code, errors, headers)

Bases: pypureclient.responses.Response

A response that indicates there was an error with the request and has the list of errors.

__init__(status_code, errors, headers)

Initialize an ErrorResponse.

Parameters:
  • status_code (int) – The HTTP status code.
  • errors (list[ApiError]) – The list of errors encountered.
  • headers (dict) – Response headers from the server.
__repr__()

Return a pretty formatted string of the object.

Returns:str
to_dict()

Return a dictionary of the class attributes.

Returns:dict
class pypureclient.responses.ItemIterator(client, api_endpoint, kwargs, continuation_token, total_item_count, items, x_request_id, more_items_remaining=None, response_size_limit=1000)

Bases: object

An iterator for items of a collection returned by the server.

__init__(client, api_endpoint, kwargs, continuation_token, total_item_count, items, x_request_id, more_items_remaining=None, response_size_limit=1000)

Initialize an ItemIterator.

Parameters:
  • client (Client) – A Pure1 Client that can call the API.
  • api_endpoint (function) – The function that corresponds to the internal API call.
  • kwargs (dict) – The kwargs of the initial call.
  • continuation_token (str) – The continuation token provided by the server. May be None.
  • total_item_count (int) – The total number of items available in the collection.
  • items (list[object]) – The items returned from the initial response.
  • x_request_id (str) – The X-Request-ID to use for all subsequent calls.
__iter__()

Creates a new iterator.

Returns:ItemIterator
__len__()

Get the length of collection. Number of items returned is not guaranteed to be the length of collection at the start.

Returns:int
__next__()

Get the next item in the collection. If there are no items left to get from the last response, it calls the API again to get more items.

Returns:object
Raises:StopIteration – If there are no more items to return, or if there was an error calling the API.
next()

Get the next item in the collection. If there are no items left to get from the last response, it calls the API again to get more items.

Returns:object
Raises:StopIteration – If there are no more items to return, or if there was an error calling the API.
class pypureclient.responses.Response(status_code, headers)

Bases: object

An abstract response that is extended to a valid or error response.

__init__(status_code, headers)

Initialize a Response.

Parameters:
  • status_code (int) – The HTTP status code.
  • headers (dict) – Response headers from the server.
class pypureclient.responses.ResponseHeaders(x_request_id, x_ratelimit_limit_second, x_ratelimit_limit_minute, x_ratelimit_remaining_second, x_ratelimit_remaining_minute)

Bases: object

An object that includes headers from the server response.

__init__(x_request_id, x_ratelimit_limit_second, x_ratelimit_limit_minute, x_ratelimit_remaining_second, x_ratelimit_remaining_minute)

Initialize a ResponseHeaders.

Parameters:
  • x_request_id (str) – The X-Request-ID from the client or generated by the server.
  • x_ratelimit_limit_second (int) – The number of requests available per second.
  • x_ratelimit_limit_minute (int) – The number of requests available per minute.
  • x_ratelimit_remaining_second (int) – The number of requests remaining in that second.
  • x_ratelimit_remaining_minute (int) – The number of requests remaining in that minute.
__repr__()

Return a pretty formatted string of the object.

Returns:str
to_dict()

Return a dictionary of the class attributes.

Returns:dict
class pypureclient.responses.ValidResponse(status_code, continuation_token, total_item_count, items, headers, total=None, more_items_remaining=None)

Bases: pypureclient.responses.Response

A response that indicates the request was successful and has the returned data.

__init__(status_code, continuation_token, total_item_count, items, headers, total=None, more_items_remaining=None)

Initialize a ValidResponse.

Parameters:
  • status_code (int) – The HTTP status code.
  • continuation_token (str) – An opaque token to iterate over a collection of resources. May be None.
  • total_item_count (int) – The total number of items available in the collection.
  • items (ItemIterator) – An iterator over the items in the collection.
  • headers (dict) – Response headers from the server.
__repr__()

Return a pretty formatted string of the object. Does not convert the items to a list of items by using the iterator.

Returns:str
to_dict()

Return a dictionary of the class attributes. It will convert the items to a list of items by exhausting the iterator. If any items were previously iterated, they will be missed.

Returns:dict

pypureclient.token_manager module

class pypureclient.token_manager.TokenManager(token_endpoint, id_token=None, private_key_file=None, private_key_password=None, payload=None, headers=None, verify_ssl=True)

Bases: object

A TokenManager is to handle authentication for API calls internally. It accepts an app ID and private key to be able to generate an internal ID token. Alternatively, the ID token itself can be provided. A valid access token is stored in memory and on disk. When an access token is expired, a new one is retrieved. Access tokens on disk are reused when a new TokenManager is instantiated.

ALGORITHM = 'RS256'
EXP_TIME_IN_SECONDS = 315360000
__init__(token_endpoint, id_token=None, private_key_file=None, private_key_password=None, payload=None, headers=None, verify_ssl=True)

Initialize a TokenManager. Should be treated as a static object.

Parameters:
  • token_endpoint (str) – URL to POST to for exchanging an ID token for an access token.
  • id_token (str, optional) – The ID token to use rather than creating one. If expired, all requests to get an access token will fail. Required if app ID and private key information not given.
  • private_key_file (str, optional) – Filepath to the private key that matches the public key used to register the app ID.
  • private_key_password (str, optional) – Password to the private key file, if encrypted.
  • payload (dict) – a dictionary that contains key-values for JSON Web Token claims, like iss(issuer), aud(audience), etc.
  • headers (dict) – a dictionary that contains key-values for JSON Web Token header.
Raises:

PureError – If there was any issue generating an ID token or retrieving an access token.

get_access_token(refresh=False)

Get the last used access token. Tries to read from memory, read from disk, or retrieve a new one, in that order.

Parameters:refresh (bool, optional) – Whether to retrieve a new access token. Defaults to False.
Returns:str
Raises:PureError – If there was an error retrieving an access token.
get_header(refresh=False)

Get the bearer Authorization header.

Parameters:refresh (bool, optional) – Whether to retrieve a new access token. Defaults to False.
Returns:str
Raises:PureError – If there was an error retrieving an access token.

Module contents