Base API Resource

All resource objects you will be using in Prevision.io’s Python SDK inherit from this base parent class.

In the SDK, a resource is an object that can be fetched from the platform, used in your code, updated, deleted… previsionio.usecase.BaseUsecase, previsionio.dataset.Dataset and previsionio.model.Model are all resources.

class previsionio.api_resource.ApiResource(*args, **params)

Base parent class for all SDK resource objects.

delete()

Delete a resource from the actual [client] workspace.

Raises:PrevisionException – Any error while deleting data from the platform
edit(**kwargs)

Edit a resource on the platform. You simply pass the function a dictionary of all the fields you want to update (as kwargs), with the name of the field as key and the new data for the field as value.

Note

The parameters you can update can be listed by calling:

print(my_resource.resource_params)
Returns:Updated resource data
Return type:dict
Raises:PrevisionException – Any error while updating data on the platform or parsing result
classmethod from_id(_id=None, specific_url=None)

Get a resource from the platform by its unique id. You must provide either an _id or a specific_url.

Parameters:
  • _id (str, optional) – Unique id of the resource to retrieve
  • specific_url (str, optional) – Specific (already parametrized) url to fetch the resource from
Returns:

Fetched resource

Return type:

ApiResource

Raises:
  • Exception – If neither an _id nor a specific_url was provided
  • PrevisionException – Any error while fetching data from the platform or parsing result
classmethod from_name(name, raise_if_non_unique=False, partial_match=False)

Get a resource from the platform by its name.

Parameters:
  • name (str) – Name of the resource to retrieve
  • raise_if_non_unique (bool, optional) – Whether or not to raise an error if duplicates are found (default: False)
  • partial_match (bool, optional) – If true, resources with a name containing the requested name will also be returned; else, only perfect matches will be found (default: False)
Raises:

PrevisionException – Error if duplicates are found and the raise_if_non_unique is enabled

Returns:

Fetched resource

Return type:

ApiResource

classmethod list(all=False)

List all available instances of this resource type on the platform.

Parameters:all (boolean, optional) – Whether to force the SDK to load all items of the given type (by calling the paginated API several times). Else, the query will only return the first page of result.
Returns:Fetched resources
Return type:dict
update_status(specific_url=None)

Get an update on the status of a resource.

Parameters:specific_url (str, optional) – Specific (already parametrized) url to fetch the resource from (otherwise the url is built from the resource type and unique _id)
Returns:Updated status info
Return type:dict
class previsionio.api_resource.ApiResourceType

All the different resource types and matching API endpoints.