> ## Documentation Index
> Fetch the complete documentation index at: https://help.cryptolens.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Python 3: AI

> Read usage analytics and Web API logs, and record application events.

Python 3 package `licensing 0.54`. [Reviewed source revision](https://github.com/Cryptolens/cryptolens-python/tree/8f38b5a37580f2aba1c9374f581cdc85e251950f).

```python theme={null}
from licensing.methods import AI
```

<a id="licensing.methods.AI.get_daily_aggregates" />

## get\_daily\_aggregates

Read daily usage totals by product.

```python theme={null}
AI.get_daily_aggregates(
    token,
    product_id=0,
    limit=100,
    starting_after=0,
    ending_before=0,
    start='',
    end=''
)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | An access token with the **Usage Analytics permission**. |
| `product_id` | `0` | The numeric product ID. |
| `limit` | `100` | The maximum number of records to request in this page. |
| `starting_after` | `0` | The forward cursor from a previously returned record. |
| `ending_before` | `0` | The backward cursor from a previously returned record. |
| `start` | `''` | The first date to include, in `yyyy-MM-dd` format. |
| `end` | `''` | The last date to include, in `yyyy-MM-dd` format. |

### Result

Returns `(items, '')`, where `items` is the API's `aggregates` list. Each item is a dictionary using the API's camelCase field names.

Returns `(None, message)` for API rejection or a handled request failure. Malformed response data can raise an exception.

### Checks

The API checks the access token's permissions. This method does not verify a signed license response.

[Web API reference](/api-reference/generated/GetDailyAggregates).

<a id="licensing.methods.AI.get_daily_country_aggregates" />

## get\_daily\_country\_aggregates

Read daily usage totals by product and country.

```python theme={null}
AI.get_daily_country_aggregates(
    token,
    product_id=0,
    country_code='',
    limit=100,
    starting_after=0,
    ending_before=0,
    start='',
    end=''
)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | An access token with the **Usage Analytics permission**. |
| `product_id` | `0` | The numeric product ID. |
| `country_code` | `''` | The country code to filter on, for example `SE`. |
| `limit` | `100` | The maximum number of records to request in this page. |
| `starting_after` | `0` | The forward cursor from a previously returned record. |
| `ending_before` | `0` | The backward cursor from a previously returned record. |
| `start` | `''` | The first date to include, in `yyyy-MM-dd` format. |
| `end` | `''` | The last date to include, in `yyyy-MM-dd` format. |

### Result

Returns `(items, '')`, where `items` is the API's `aggregates` list. Each item is a dictionary using the API's camelCase field names.

Returns `(None, message)` for API rejection or a handled request failure. Malformed response data can raise an exception.

### Checks

The API checks the access token's permissions. This method does not verify a signed license response.

[Web API reference](/api-reference/generated/GetDailyCountryAggregates).

<a id="licensing.methods.AI.get_key_usage_summaries" />

## get\_key\_usage\_summaries

Read usage summaries for license keys.

```python theme={null}
AI.get_key_usage_summaries(
    token,
    product_id=0,
    key_id=0,
    key='',
    limit=100,
    starting_after=0,
    ending_before=0,
    start='',
    end=''
)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | An access token with the **Usage Analytics permission**. |
| `product_id` | `0` | The numeric product ID. |
| `key_id` | `0` | The numeric license ID, rather than its license-key string. |
| `key` | `''` | The license-key string, rather than the numeric license ID. |
| `limit` | `100` | The maximum number of records to request in this page. |
| `starting_after` | `0` | The forward cursor from a previously returned record. |
| `ending_before` | `0` | The backward cursor from a previously returned record. |
| `start` | `''` | The first date to include, in `yyyy-MM-dd` format. |
| `end` | `''` | The last date to include, in `yyyy-MM-dd` format. |

### Result

Returns `(items, '')`, where `items` is the API's `summaries` list. Each item is a dictionary using the API's camelCase field names.

Returns `(None, message)` for API rejection or a handled request failure. Malformed response data can raise an exception.

### Checks

The API checks the access token's permissions. This method does not verify a signed license response.

[Web API reference](/api-reference/generated/GetKeyUsageSummaries).

<a id="licensing.methods.AI.get_key_devices" />

## get\_key\_devices

Read device usage associated with license keys.

```python theme={null}
AI.get_key_devices(
    token,
    product_id=0,
    key_id=0,
    key='',
    machine_code='',
    limit=100,
    starting_after=0,
    ending_before=0,
    start='',
    end=''
)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | An access token with the **Usage Analytics permission**. |
| `product_id` | `0` | The numeric product ID. |
| `key_id` | `0` | The numeric license ID, rather than its license-key string. |
| `key` | `''` | The license-key string, rather than the numeric license ID. |
| `machine_code` | `''` | The device or process identifier used for this activation. Reuse the same value when renewing or releasing it. |
| `limit` | `100` | The maximum number of records to request in this page. |
| `starting_after` | `0` | The forward cursor from a previously returned record. |
| `ending_before` | `0` | The backward cursor from a previously returned record. |
| `start` | `''` | The first date to include, in `yyyy-MM-dd` format. |
| `end` | `''` | The last date to include, in `yyyy-MM-dd` format. |

### Result

Returns `(items, '')`, where `items` is the API's `devices` list. Each item is a dictionary using the API's camelCase field names.

Returns `(None, message)` for API rejection or a handled request failure. Malformed response data can raise an exception.

### Checks

The API checks the access token's permissions. This method does not verify a signed license response.

[Web API reference](/api-reference/generated/GetKeyDevices).

<a id="licensing.methods.AI.get_license_activity_buckets" />

## get\_license\_activity\_buckets

Read license activity grouped into time buckets.

```python theme={null}
AI.get_license_activity_buckets(
    token,
    product_id=0,
    key_id=0,
    key='',
    machine_code='',
    limit=100,
    starting_after=0,
    ending_before=0,
    start='',
    end=''
)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | An access token with the **Usage Analytics permission**. |
| `product_id` | `0` | The numeric product ID. |
| `key_id` | `0` | The numeric license ID, rather than its license-key string. |
| `key` | `''` | The license-key string, rather than the numeric license ID. |
| `machine_code` | `''` | The device or process identifier used for this activation. Reuse the same value when renewing or releasing it. |
| `limit` | `100` | The maximum number of records to request in this page. |
| `starting_after` | `0` | The forward cursor from a previously returned record. |
| `ending_before` | `0` | The backward cursor from a previously returned record. |
| `start` | `''` | The first date to include, in `yyyy-MM-dd` format. |
| `end` | `''` | The last date to include, in `yyyy-MM-dd` format. |

### Result

Returns `(items, '')`, where `items` is the API's `buckets` list. Each item is a dictionary using the API's camelCase field names.

Returns `(None, message)` for API rejection or a handled request failure. Malformed response data can raise an exception.

### Checks

The API checks the access token's permissions. This method does not verify a signed license response.

[Web API reference](/api-reference/generated/GetLicenseActivityBuckets).

<a id="licensing.methods.AI.get_web_api_log" />

## get\_web\_api\_log

Retrieve Web API log records matching the supplied filters.

```python theme={null}
AI.get_web_api_log(
    token,
    product_id=0,
    key='',
    machine_code='',
    friendly_name='',
    limit=10,
    starting_after=0,
    ending_before=0,
    order_by=''
)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | Your access token. It needs the permission required by the linked Web API method. |
| `product_id` | `0` | The numeric product ID. |
| `key` | `''` | The license-key string, rather than the numeric license ID. |
| `machine_code` | `''` | The device or process identifier used for this activation. Reuse the same value when renewing or releasing it. |
| `friendly_name` | `''` | A display name for the activation. It does not replace the machine code. |
| `limit` | `10` | The maximum number of records to request in this page. |
| `starting_after` | `0` | The forward cursor from a previously returned record. |
| `ending_before` | `0` | The backward cursor from a previously returned record. |
| `order_by` | `''` | The API's ordering expression. |

### Result

Returns `(logs, '')`, where `logs` is a list of API dictionaries.

Returns `(None, message)` for API rejection or a handled request failure. Malformed response data can raise an exception.

### Checks

The API checks the access token's permissions. This method does not verify a signed license response.

[Web API reference](/api-reference/generated/GetWebAPILog).

<a id="licensing.methods.AI.get_events" />

## get\_events

Retrieve registered application events.

```python theme={null}
AI.get_events(token, limit=10, starting_after=0, product_id=0, key='', metadata='')
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | Your access token. It needs the permission required by the linked Web API method. |
| `limit` | `10` | The maximum number of records to request in this page. |
| `starting_after` | `0` | The forward cursor from a previously returned record. |
| `product_id` | `0` | The numeric product ID. |
| `key` | `''` | The license-key string, rather than the numeric license ID. |
| `metadata` | `''` | Accepted by this SDK signature, but not sent to the API in version 0.54. It does not change the request. |

### Result

Returns `(events, '')`, where `events` is a list of API dictionaries.

Returns `(None, message)` for API rejection or a handled request failure. Malformed response data can raise an exception.

### Checks

The API checks the access token's permissions. This method does not verify a signed license response.

[Web API reference](/api-reference/generated/GetEvents).

<a id="licensing.methods.AI.register_event" />

## register\_event

Record an application event, such as a feature being used.

```python theme={null}
AI.register_event(
    token,
    product_id=0,
    key='',
    machine_code='',
    feature_name='',
    event_name='',
    value=0,
    currency='',
    metadata=''
)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | Your access token. It needs the permission required by the linked Web API method. |
| `product_id` | `0` | The numeric product ID. |
| `key` | `''` | The license-key string, rather than the numeric license ID. |
| `machine_code` | `''` | The device or process identifier used for this activation. Reuse the same value when renewing or releasing it. |
| `feature_name` | `''` | The name of the feature associated with this event. |
| `event_name` | `''` | The name of the event being recorded. |
| `value` | `0` | The numeric value associated with the event. |
| `currency` | `''` | The ISO currency code, for example `USD`. |
| `metadata` | `''` | Additional event metadata passed to the API. |

### Result

Returns `(True, message)` on success.

Returns `(False, message)` for API rejection and `(None, message)` for a handled request failure. Malformed response data can raise an exception.

### Checks

The API checks the access token's permissions. This method does not verify a signed license response.

[Web API reference](/api-reference/generated/RegisterEvent).

[Python SDK Reference](/libraries/python-api)
