Async Usage

The async Usage module provides functionality for working with user usage reports.

class AsyncUsage(api, user)[source]

Bases: AsyncBase

Parameters:
BASE_ENDPOINT = 'usage/'
__init__(api, user)[source]

Constructs the necessary attributes for the Usage object.

Parameters:
__repr__()[source]

Return a string representation of the Usage object.

Returns:

A string representation of the Usage object.

Return type:

str

async classmethod get_api_usage(api, resource, scale, param, from_date=None, to_date=None, days_before_now=None, limit=None)[source]

[async] Get the api usage of a user

Parameters:
  • api (AsyncGeoboxClient) – The AsyncGeoboxClient instance for making requests.

  • resource (AsyncUser | AsyncApiKey) – User or ApiKey object.

  • scale (UsageScale) – the scale of the report.

  • param (UsageParam) – traffic or calls.

  • from_date (datetime, optional) – datetime object in this format: “%Y-%m-%dT%H:%M:%S”.

  • to_date (datetime, optional) – datetime object in this format: “%Y-%m-%dT%H:%M:%S”.

  • days_before_now (int, optional) – number of days befor now.

  • limit (int, optional) – Number of items to return. default is 10.

Raises:
  • ValueError – one of days_before_now or from_date/to_date parameters must have value

  • ValueError – resource must be a ‘user’ or ‘apikey’ object

Returns:

usage report

Return type:

List

Example

>>> from geobox.aio import AsyncGeoboxClient
>>> from geobox.aio.usage import AsyncUsage
>>> async with AsyncGeoboxClient() as client:
>>>     user = await client.get_user() # gets current user
>>>     usage = await AsyncUsage.get_api_usage(client,
...                                         resource=user,
...                                         scale=UsageScale.Day,
...                                         param=UsageParam.Calls,
...                                         days_before_now=5)
or
>>>     usage = await client.get_api_usage(resource=user,
...                                         scale=UsageScale.Day,
...                                         param=UsageParam.Calls,
...                                         days_before_now=5)
async classmethod get_process_usage(api, user_id=None, from_date=None, to_date=None, days_before_now=None)[source]

[async] Get process usage of a user in seconds

Parameters:
  • api (AsyncGeoboxClient) – The AsyncGeoboxClient instance for making requests.

  • user_id (int, optional) – the id of the user. leave blank to get the current user report.

  • from_date (datetime, optional) – datetime object in this format: “%Y-%m-%dT%H:%M:%S”.

  • to_date (datetime, optional) – datetime object in this format: “%Y-%m-%dT%H:%M:%S”.

  • days_before_now (int, optional) – number of days befor now.

Raises:

ValueError – one of days_before_now or from_date/to_date parameters must have value

Returns:

process usage of a user in seconds

Return type:

float

Example

>>> from geobox.aio import AsyncGeoboxClient
>>> from geobox.aio.usage import AsyncUsage
>>> async with AsyncGeoboxClient() as client:
>>>     process_usage = await AsyncUsage.get_process_usage(client, days_before_now=5)
or
>>>     process_usage = await client.get_process_usage(days_before_now=5)
async classmethod get_usage_summary(api, user_id=None)[source]

[async] Get the usage summary of a user

Parameters:
  • api (AsyncGeoboxClient) – The API instance.

  • user_id (int, optional) – the id of the user. leave blank to get the current user report.

Returns:

the usage summary of the users

Return type:

Dict

Returns:

>>> from geobox.aio import AsyncGeoboxClient
>>> from geobox.aio.usage import AsyncUsage
>>> async with AsyncGeoboxClient() as client:
>>>     usage_summary = await AsyncUsage.get_usage_summary(client)
or
>>>     usage_summary = await client.get_usage_summary()

async classmethod update_usage(api, user_id=None)[source]

[async] Update usage of a user

Parameters:
  • api (AsyncGeoboxClient) – The API instance.

  • user_id (int, optional) – the id of the user. leave blank to get the current user report.

Returns:

the updated data

Return type:

Dict

Example

>>> from geobox.aio import AsyncGeoboxClient
>>> from geobox.aio.usage import AsyncUsage
>>> async with AsyncGeoboxClient() as client:
>>>     await AsyncUsage.update_usage(client)
or
>>>     await client.update_usage()