> ## 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: Key

> Activate, retrieve, create and update license keys.

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

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

Calls that create licenses or change administrative settings belong on your server. Use an access token with only the permissions the application needs.

<a id="licensing.methods.Key.activate" />

## activate

Activate a license for a machine or process.

```python theme={null}
Key.activate(
    token,
    rsa_pub_key,
    product_id,
    key,
    machine_code,
    fields_to_return=0,
    metadata=False,
    floating_time_interval=0,
    max_overdraft=0,
    friendly_name=None
)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | Your access token. It needs the permission required by the linked Web API method. |
| `rsa_pub_key` | Required | Your account's complete RSA public key in XML form. |
| `product_id` | Required | The numeric product ID. |
| `key` | Required | The license-key string, rather than the numeric license ID. |
| `machine_code` | Required | The device or process identifier used for this activation. Reuse the same value when renewing or releasing it. |
| `fields_to_return` | `0` | The returned-field mask; `0` requests the standard license fields. See the linked API reference before masking fields your application uses. |
| `metadata` | `False` | Request signed metadata. Read the third item only after activation succeeds; it may contain a metadata-signature error instead of a dictionary. |
| `floating_time_interval` | `0` | The floating interval in seconds. `0` leaves floating licensing disabled for activation. |
| `max_overdraft` | `0` | The number of extra floating seats allowed above the license's machine limit; `0` allows no overdraft. |
| `friendly_name` | `None` | A display name for the activation. It does not replace the machine code. |

### Result

Normally returns `(license_key, message)`, where `license_key` is a `LicenseKey` object. With `metadata=True`, a successful license result has a third item: verified metadata as a dictionary, or the string `Signature check for metadata object failed.`. Failure results can still have only two items.

Returns `(None, message)` if the API rejects activation, the signature fails, or a handled request/parsing error occurs. An incorrectly formatted RSA public key can raise before these result checks.

### Checks

Requests a signed ModelVersion 3 response and verifies the license signature with `rsa_pub_key`. With `metadata=True`, it also checks the metadata signature. It does not independently enforce your application's product, features, expiry or machine-binding policy.

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

### Example

Replace the access token and RSA public key placeholders, product ID and example license key with your own values. `example-device` represents the identifier supplied by your application.

```python theme={null}
result = Key.activate(
    token="YOUR_ACCESS_TOKEN", rsa_pub_key="YOUR_RSA_PUBLIC_KEY",
    product_id=3349, key="ICVLD-VVSZR-ZTICT-YKGXL",
    machine_code="example-device")
if result[0] is None:
    print("Activation failed: {0}".format(result[1]))
else:
    print("Activation succeeded.")
```

<a id="licensing.methods.Key.get_key" />

## get\_key

Retrieve license information without registering a device or renewing a floating seat.

```python theme={null}
Key.get_key(
    token,
    rsa_pub_key,
    product_id,
    key,
    fields_to_return=0,
    metadata=False,
    floating_time_interval=0
)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | Your access token. It needs the permission required by the linked Web API method. |
| `rsa_pub_key` | Required | Your account's complete RSA public key in XML form. |
| `product_id` | Required | The numeric product ID. |
| `key` | Required | The license-key string, rather than the numeric license ID. |
| `fields_to_return` | `0` | The returned-field mask; `0` requests the standard license fields. See the linked API reference before masking fields your application uses. |
| `metadata` | `False` | Forwarded to the API, but this wrapper still returns only `(license_key, message)`. |
| `floating_time_interval` | `0` | Passed to GetKey for the requested view of floating information. It does not renew a floating seat. |

### Result

Returns `(license_key, message)`. The parsed license is a `LicenseKey` object. Even with `metadata=True`, this method returns two items; it does not return a separately verified metadata dictionary.

Returns `(None, message)` on API rejection, a failed signature or a handled request/parsing error. A malformed RSA public key can raise an exception.

### Checks

Requests a signed ModelVersion 3 response and verifies the license signature. A successful lookup can include a blocked license; check `license_key.block`. The method does not apply your application's expiry policy or acquire a floating seat.

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

<a id="licensing.methods.Key.create_trial_key" />

## create\_trial\_key

Create a trial key for the specified machine, or retrieve its previously created trial key.

```python theme={null}
Key.create_trial_key(token, product_id, machine_code, friendly_name='')
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | Your access token. It needs the permission required by the linked Web API method. |
| `product_id` | Required | The numeric product ID. |
| `machine_code` | Required | 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. |

### Result

Returns `(key_string, '')`. The first item is the license-key string, not a `LicenseKey` object.

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

### Checks

The API applies its trial-key rules. This method does not activate the returned key or verify a signed license; activate it using `Key.activate`.

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

<a id="licensing.methods.Key.create_key" />

## create\_key

Create one or more licenses, optionally linked to a customer.

```python theme={null}
Key.create_key(
    token,
    product_id,
    period=0,
    f1=False,
    f2=False,
    f3=False,
    f4=False,
    f5=False,
    f6=False,
    f7=False,
    f8=False,
    notes='',
    block=False,
    customer_id=0,
    new_customer=False,
    add_or_use_existing_customer=False,
    trial_activation=False,
    max_no_of_machines=0,
    no_of_keys=1,
    name=None,
    email=None,
    company_name=None,
    enable_customer_association=False,
    allow_activation_management=False
)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | Your access token. It needs the permission required by the linked Web API method. |
| `product_id` | Required | The numeric product ID. |
| `period` | `0` | The license period in days, passed to CreateKey. |
| `f1` | `False` | Whether feature 1 is enabled on the new license. |
| `f2` | `False` | Whether feature 2 is enabled on the new license. |
| `f3` | `False` | Whether feature 3 is enabled on the new license. |
| `f4` | `False` | Whether feature 4 is enabled on the new license. |
| `f5` | `False` | Whether feature 5 is enabled on the new license. |
| `f6` | `False` | Whether feature 6 is enabled on the new license. |
| `f7` | `False` | Whether feature 7 is enabled on the new license. |
| `f8` | `False` | Whether feature 8 is enabled on the new license. |
| `notes` | `''` | The license notes. |
| `block` | `False` | Whether the new license is blocked. |
| `customer_id` | `0` | The numeric customer ID; see the method reference for the meaning of `0`. |
| `new_customer` | `False` | Create and associate a new customer. Customer creation requires both the **CreateKey permission** and the **AddCustomer permission**. |
| `add_or_use_existing_customer` | `False` | Associate a customer using the supplied email, creating one if necessary. Requires both the **CreateKey permission** and the **AddCustomer permission**. |
| `trial_activation` | `False` | Whether the license period starts on its first activation. |
| `max_no_of_machines` | `0` | The machine limit. `0` disables machine registration. |
| `no_of_keys` | `1` | How many license keys to create. |
| `name` | `None` | The customer name. |
| `email` | `None` | The customer's or user's email address. |
| `company_name` | `None` | The customer's company name. |
| `enable_customer_association` | `False` | Allow the customer to associate licenses through the customer portal. |
| `allow_activation_management` | `False` | Allow the customer to manage activations through the customer portal. |

### Result

Returns `(response_dict, '')`. The dictionary contains the API response fields, including the created key data.

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/CreateKey).

<a id="licensing.methods.Key.deactivate" />

## deactivate

Release the activation identified by its machine code. Set `floating=True` for a floating seat.

```python theme={null}
Key.deactivate(token, product_id, key, machine_code, floating=False)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | Your access token. It needs the permission required by the linked Web API method. |
| `product_id` | Required | The numeric product ID. |
| `key` | Required | The license-key string, rather than the numeric license ID. |
| `machine_code` | Required | The device or process identifier used for this activation. Reuse the same value when renewing or releasing it. |
| `floating` | `False` | Set to `True` when releasing a floating activation. |

### Result

Returns `(True, '')` when deactivation succeeds.

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/Deactivate).

<a id="licensing.methods.Key.extend_license" />

## extend\_license

Adjust the license's expiry date.

```python theme={null}
Key.extend_license(token, product_id, key, no_of_days)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | Your access token. It needs the permission required by the linked Web API method. |
| `product_id` | Required | The numeric product ID. |
| `key` | Required | The license-key string, rather than the numeric license ID. |
| `no_of_days` | Required | The number of days by which to adjust the expiry date. |

### Result

Returns `(True, message)` on success; the message is the API's message.

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/ExtendLicense).

<a id="licensing.methods.Key.change_customer" />

## change\_customer

Change the customer associated with a license.

```python theme={null}
Key.change_customer(token, product_id, key, customer_id)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | Your access token. It needs the permission required by the linked Web API method. |
| `product_id` | Required | The numeric product ID. |
| `key` | Required | The license-key string, rather than the numeric license ID. |
| `customer_id` | Required | The numeric customer ID; see the method reference for the meaning of `0`. |

### Result

Returns `(True, message)` on success; the message is the API's message.

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/ChangeCustomer).

<a id="licensing.methods.Key.unblock_key" />

## unblock\_key

Remove the blocked flag from a license.

```python theme={null}
Key.unblock_key(token, product_id, key)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | Your access token. It needs the permission required by the linked Web API method. |
| `product_id` | Required | The numeric product ID. |
| `key` | Required | The license-key string, rather than the numeric license ID. |

### Result

Returns `(True, message)` on success; the message is the API's message.

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/UnblockKey).

<a id="licensing.methods.Key.block_key" />

## block\_key

Block a license.

```python theme={null}
Key.block_key(token, product_id, key)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | Your access token. It needs the permission required by the linked Web API method. |
| `product_id` | Required | The numeric product ID. |
| `key` | Required | The license-key string, rather than the numeric license ID. |

### Result

Returns `(True, message)` on success; the message is the API's message.

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/BlockKey).

<a id="licensing.methods.Key.machine_lock_limit" />

## machine\_lock\_limit

Set the license's maximum number of machines.

```python theme={null}
Key.machine_lock_limit(token, product_id, key, number_of_machines)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | Your access token. It needs the permission required by the linked Web API method. |
| `product_id` | Required | The numeric product ID. |
| `key` | Required | The license-key string, rather than the numeric license ID. |
| `number_of_machines` | Required | The new maximum number of machines for the license. |

### Result

Returns `(True, message)` on success; the message is the API's message.

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/MachineLockLimit).

<a id="licensing.methods.Key.change_notes" />

## change\_notes

Replace a license's notes.

```python theme={null}
Key.change_notes(token, product_id, key, notes)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | Your access token. It needs the permission required by the linked Web API method. |
| `product_id` | Required | The numeric product ID. |
| `key` | Required | The license-key string, rather than the numeric license ID. |
| `notes` | Required | The license notes. |

### Result

Returns `(True, message)` on success; the message is the API's message.

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/ChangeNotes).

<a id="licensing.methods.Key.change_reseller" />

## change\_reseller

Change the reseller associated with a license.

```python theme={null}
Key.change_reseller(token, product_id, key, reseller_id)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | Your access token. It needs the permission required by the linked Web API method. |
| `product_id` | Required | The numeric product ID. |
| `key` | Required | The license-key string, rather than the numeric license ID. |
| `reseller_id` | Required | The numeric reseller ID. |

### Result

Returns `(True, message)` on success; the message is the API's message.

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/ChangeReseller).

<a id="licensing.methods.Key.create_key_from_template" />

## create\_key\_from\_template

Create a license using a license template.

```python theme={null}
Key.create_key_from_template(token, license_template_id)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | Your access token. It needs the permission required by the linked Web API method. |
| `license_template_id` | Required | The numeric license-template ID. |

### Result

Returns `(key_string, raw_response, message)` on success. These are the API's `key`, `rawResponse` and `message` fields.

Failures have two items: `(False, message)` for API rejection or `(None, message)` for a handled request failure. Check the first item before unpacking the success tuple. 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/CreateKeyFromTemplate).

<a id="licensing.methods.Key.add_feature" />

## add\_feature

Enable one of the eight feature flags.

```python theme={null}
Key.add_feature(token, product_id, key, feature)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | Your access token. It needs the permission required by the linked Web API method. |
| `product_id` | Required | The numeric product ID. |
| `key` | Required | The license-key string, rather than the numeric license ID. |
| `feature` | Required | The feature number, from 1 to 8. |

### Result

Returns `(True, message)` on success; the message is the API's message.

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/AddFeature).

<a id="licensing.methods.Key.remove_feature" />

## remove\_feature

Disable one of the eight feature flags.

```python theme={null}
Key.remove_feature(token, product_id, key, feature)
```

### Parameters

| Parameter | Default | Meaning |
| - | - | - |
| `token` | Required | Your access token. It needs the permission required by the linked Web API method. |
| `product_id` | Required | The numeric product ID. |
| `key` | Required | The license-key string, rather than the numeric license ID. |
| `feature` | Required | The feature number, from 1 to 8. |

### Result

Returns `(True, message)` on success; the message is the API's message.

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/RemoveFeature).

## FAQ

<AccordionGroup>
  <Accordion title="Can One Access Token Activate and Deactivate?" id="can-one-access-token-activate-and-deactivate">
    Yes. Select both the **Activate permission** and the **Deactivate permission** on the access token. The Activate permission alone does not grant deactivation. See the [access-token guide](/getting-started/access-token#can-one-token-activate-and-deactivate-a-license).
  </Accordion>

  <Accordion title="Do I Need Another Signature Check After Activation?" id="do-i-need-another-signature-check-after-activation">
    No. A `LicenseKey` returned by `Key.activate` has already passed the SDK's signature check. Other checks depend on the application; see the [license-check FAQ](/examples/key-verification#does-a-successful-api-response-mean-the-license-is-valid).
  </Accordion>

  <Accordion title="How Do Floating Renewals Work?" id="how-do-floating-renewals-work">
    Call `Key.activate` with the same process identifier and floating interval for each renewal. Call `Key.deactivate` with the same identifier and `floating=True` when releasing it. `Key.get_key` does not renew the seat. See the [floating guide](/licensing-models/floating) for renewal timing and crash recovery.
  </Accordion>
</AccordionGroup>

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