API Documentation

cocoPy

class cocoAPI.cocoPy.cocoPy(email, password)[source]

Bases: object

Class for COCONUT API.

Parameters:
  • email – Email address for COCONUT account

  • password – Password for COCONUT account

cocoLog

class cocoAPI.cocoLog.cocoLog[source]

Bases: object

login(email, password)[source]

Log in to the COCONUT API and store the access token. On success, stores the access token and sets the Authorization header.

Parameters:
  • email – Email address for COCONUT account

  • password – Password for COCONUT account

Returns:

Raises errors if found

Return type:

error

logout()[source]

Log out from the COCONUT API. Clears stored access token and Authorization header.

cocoBase

class cocoAPI.cocoBase.cocoBase(cocoLog)[source]

Bases: object

Base class for COCONUT API GET and POST requests.

_get(endpoint, params=None)[source]

Performs GET request to the COCONUT API endpoint.

Parameters:
  • endpoint – COCONUT API endpoint

  • params – GET parameters

Returns:

  • dict – JSON response from the COCONUT API endpoint

  • error – Raises errors if found

_post(endpoint, json_body)[source]

Performs POST request to the COCONUT API endpoint.

Parameters:
  • endpoint – COCONUT API endpoint

  • json_body – JSON body for the POST request

Returns:

  • dict – JSON response from the COCONUT API endpoint

  • error – Raises errors if found

cocoGet

class cocoAPI.cocoGet.cocoGet(cocoLog)[source]

Bases: cocoBase

Class for COCONUT API GET requests.

resource_fields(resource_endpoint)[source]

Retrieves resource fields from the COCONUT API endpoint.

Parameters:

resource_endpoint – COCONUT API endpoint

Returns:

  • dict – Resource fields from the COCONUT API endpoint

  • error – Raises errors if found

resource_json(resource_endpoint)[source]

Retrieves resource JSON from the COCONUT API endpoint.

Parameters:

resource_endpoint – COCONUT API endpoint

Returns:

  • dict – Resource JSON from the COCONUT API endpoint

  • error – Raises errors if found

cocoSearch

class cocoAPI.cocoSearch.cocoSearch(cocoLog)[source]

Bases: cocoBase

Class for COCONUT API search endpoints.

_build_search_req(resource_endpoint, search_query)[source]

Builds search request from a search_query list of entries, where each entry has format [key, field, value].

Parameters:
  • resource_endpoint – COCONUT API endpoint to search

  • search_query – List of entries, where each entry has format [key, field, value]

Returns:

Search request from search_query

Return type:

dict

_check_search_query(resource_endpoint, search_query)[source]

Performs several checks on search_query to ensure correct format.

Parameters:
  • resource_endpoint – COCONUT API endpoint to search

  • search_query – List of entries, where each entry has format [key, field, value]

Returns:

Raises errors if found

Return type:

error

_paginate_search_data(endpoint, json_body, sleep_time)[source]

Performs pagination on the data returned from the COCONUT API search request.

Parameters:
  • endpoint – COCONUT API endpoint

  • json_body – JSON body for the search request

  • sleep_time – Time to sleep between requests to avoid rate limiting

Returns:

  • dict – Complete results from the COCONUT API search request

  • error – Raises errors if found

get_all_records(resource_endpoint, pg_limit=25, sleep_time=0)[source]

Get all records from COCONUT API endpoint to search.

Parameters:
  • resource_endpoint – COCONUT API endpoint to search

  • pg_limit – Number of results per page

  • sleep_time – Time to sleep to avoid rate limiting

Returns:

  • dict – Complete results from search request

  • error – Raises errors if found

query(resource_endpoint, search_query, sleep_time=0)[source]

Performs COCONUT search request and returns the json response.

Parameters:
  • resource_endpoint – COCONUT resource to search

  • search_query – List of entries, where each entry has format [key, field, value]

  • sleep_time – Time to sleep between requests to avoid rate limiting

Returns:

  • dict – Complete results from search request

  • error – Raises errors if found

cocoAdvSearch

class cocoAPI.cocoAdvSearch.cocoAdvSearch(cocoLog)[source]

Bases: cocoBase

Class for COCONUT API advanced search endpoint.

_build_adv_search_req(adv_search_query)[source]

Builds advanced search request from a adv_search_query list of entries, where each entry has format [type, tag|filter, value].

Parameters:

adv_search_query – List of entries, where each entry has format [type, tag|filter, value]

Returns:

  • dict – Advanced search request from adv_search_query

  • error – Raises errors if found

_check_adv_search_query(adv_search_query)[source]

Performs several checks on adv_search_query to ensure correct format.

Parameters:

adv_search_query – List of entries, where each entry has format [type, tag|filter, value]

Returns:

Raises errors if found

Return type:

error

_paginate_adv_search_data(json_body: dict, sleep_time: int = 0, pg_limit: int = 25)[source]

Performs pagination on the data returned from the COCONUT API advanced search request.

Parameters:
  • json_body – JSON body for the advanced search request

  • sleep_time – Time to sleep to avoid rate limiting. Default is 0

  • pg_limit – Number of results per page. Default is 25

Returns:

  • dict – Complete results from the COCONUT API advanced search request

  • error – Raises errors if found

advanced_query(adv_search_query, sleep_time: int = 0, pg_limit: int = 25)[source]

Runs advanced search request from adv_search_query and returns the json response.

Parameters:
  • adv_search_query – List of entries, where each entry has format [type, tag|filter, value]

  • sleep_time – Time to sleep between requests to avoid rate limiting. Default is 0

  • pg_limit – Number of results per page. Default is 25

Returns:

  • dict – Complete results from the COCONUT API advanced search request

  • error – Raises errors if found

get_all_adv_records(pg_limit: int = 25, sleep_time: int = 0)[source]

Get all records from COCONUT API advanced search endpoint.

Parameters:
  • pg_limit – Number of results per page. Default is 25

  • sleep_time – Time to sleep to avoid rate limiting. Default is 0

Returns:

  • dict – Complete results from the COCONUT API advanced search request

  • error – Raises errors if found