> ## 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 2 / IronPython: Key

> Activate, retrieve and release licenses, and create trial keys.

Python 2 / IronPython implementation. [Reviewed source revision](https://github.com/Cryptolens/cryptolens-python/tree/8f38b5a37580f2aba1c9374f581cdc85e251950f).

```python theme={null}
from cryptolens_python2 import Key
```

Import these methods from the separate `cryptolens_python2` module. This implementation provides activation, retrieval, trial-key creation and deactivation; it does not include the Python 3 SDK's administrative methods.

<a id="cryptolens_python2.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` | Forwarded to the API, but the legacy wrapper does not expose a third metadata result. |
| `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

Returns `(license_key, message)`, where `license_key` is a `LicenseKey` object. This legacy implementation returns two items even when `metadata=True`; it does not return or separately verify metadata.

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 2 activation response and verifies the license signature. It does not independently apply your application's expiry, product, feature or machine checks.

[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="cryptolens_python2.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 implementation returns two items and does not expose or verify metadata. |
| `floating_time_interval` | `0` | Passed to GetKey to request floating information; it does not renew a 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 response and verifies the license signature. This legacy lookup does not explicitly send ModelVersion. It does not activate or renew a floating seat, enforce expiry, or reject a returned blocked flag by itself.

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

<a id="cryptolens_python2.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)
```

### 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. |

### Result

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

Returns `(None, message)` on an API rejection or a handled request failure, including a missing key field. Invalid response JSON 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="cryptolens_python2.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).

## 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)
