> For the complete documentation index, see [llms.txt](https://docs.licensespring.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.licensespring.com/sdks/python-sdk/licensefile-setup-and-usage.md).

# Licensefile Setup and Usage

### Licensefile Setup

#### Key and IV Setup

To use licensefile inside a python SDK you should first setup your key and IV. Key and IV are used inside Python SDK for encryption and decryption process inside licensefile. This process is only required **once** at the setup.

```python
from licensespring.licensefile.default_crypto import DefaultCryptoProvider

password = "YOUR_PASSWORD"
salt = "YOUR_SALT"


crypto = DefaultCryptoProvider()

key = crypto.derive_key(password=password,salt=salt)
iv = crypto.generate_random_iv()

```

### Configuration Setup

After you have successfully setup your key and IV you should setup your Configuration.

```python
from licensespring.licensefile.config import Configuration
#from licensespring.hardware import HardwareIdProviderSource
#The commented hardware_id_provider will become the default in the next major version of the SDK
#we advise using HardwareIdProviderSource!
conf = Configuration(product="your_product_key",api_key="your_api_key",
                   shared_key="your_shared_key",file_key=key,file_iv=iv,
                   is_guard_file_enabled=True,
                   #hardware_id_provider=HardwareIdProviderSource)
```

#### Configuration Attributes

* **api\_key** (str, optional): Your unique API key used for authentication with the licensing server.
* **shared\_key** (str, optional): A shared secret key used alongside the API key for enhanced security during the license verification process.
* **file\_key** (str): The encryption key used for securing license files on the client side.
* **file\_iv** (str): The initialization vector for the encryption algorithm. This complements the **file\_key** for encrypting and decrypting license files.
* **hardware\_id\_provider** (object, optional): The provider class used for generating a unique hardware ID. This ID helps in binding the license to specific hardware. Defaults to **HardwareIdProvider**.
* **verify\_license\_signature** (bool, optional): A boolean flag indicating whether the license's digital signature should be verified. Defaults to **True** for enhanced security.
* **signature\_verifier** (object, optional): The class responsible for verifying the digital signature of licenses. Defaults to **SignatureVerifier**.
* **api\_domain** (str, optional): The domain name of the API server with which the licensing operations are performed. Defaults to **"api.licensespring.com"**.
* **api\_version** (str, optional): The version of the API to use for requests. This allows for compatibility with different versions of the licensing API. Defaults to **"v4"**.
* **filename** (str, optional): The default filename for saved license files. This can be customized as needed. Defaults to **"License"**.
* **file\_path** (str, optional): The path where license files should be saved on the client system. If not specified, a default location is used.
* **grace\_period\_conf** (int, optional): The number of hours to allow as a grace period. Defaults to 24 hours.
* **is\_guard\_file\_enabled** (bool): Enables guard protection for offline licenses if set to True.
* **air\_gap\_public\_key** (str, optional): Air gap public key.
* **client\_id** (str, optional): Client ID for OAuth authorization purposes.
* **client\_secret** (str, optional): Client Secret for OAuth authorization purposes.
* **certificate\_chain\_path** (str, optional): path to `.pem` file used in provisioning (e.g "path\_to\_chain.pem").
* **enable\_airgapped\_skip\_time\_check** (bool, optional): When set to True, SDK would skip checking date time with airgap licenses, until turned on again.

{% hint style="warning" %}

* We advise for **hardware\_id\_provider** to use a newly developed [**HardwareIdProviderSource**](/sdks/python-sdk/python-hardware-device-ids.md#hardwareidprovidersource) provider.
* On the **next major** version release **HardwareIdProviderSource** will be set as default **hardware\_id\_provider**.
* If both **API keys** and **OAuth** are specified in **Configuration**, SDK will use OAuth for authorization.
  {% endhint %}

### LicenseID

Represents a mechanism for license identification and activation, supporting both key-based and user-based activations.

#### Methods

* **from\_key(cls, key)** - class method to create a **LicenseID** instance for key-based activation.
* **from\_user(cls, username, password)** - class method to create a **LicenseID** instance for user-based activation.

#### Key-Based Setup

```python
from licensespring.licensefile.license_manager import LicenseID

license_id = LicenseID.from_key("your_license_key")            
```

#### User-Based Setup

```python
from licensespring.licensefile.license_manager import LicenseID

license_id = LicenseID.from_user(username="email@email.com",password="password")                         
```

### LicenseManager

Manages license activations, supporting a variety of parameters to accommodate different licensing scenarios.

```python
from licensespring.licensefile.license_manager import LicenseManager

manager = LicenseManager(conf)
```

#### Configuration parametres

* **conf** (Configuration): A configuration object

#### **Getters**

```python
manager.is_license_file_corrupted() # Checks if licensefile is corrupted 
manager.data_location() # Get licensefile location 
manager.license_file_name() # Get licensefile name  
manager.current_config() # Get current configuration                   
```

#### **activate\_license**

Activates a license with the license server and updates local license data. Returns an instance of the **License**.

Parameters:

* **license\_id** (LicenseID): An instance containing the license key or user credentials.
* **bundle\_code** (str, optional): specify unique bundle\_code of a bundle
* **hardware\_id** (str, optional): A unique identifier for the hardware.
* **unique\_license\_id** (int, optional): A unique identifier for the license.
* **customer\_account\_code** (str, optional): An account code for the customer.
* **redirect\_uri** (str, optional): redirect\_uri. Defaults to None.
* **id\_token** (str, optional): Token for identity verification.
* **code** (str, optional): An additional code for license verification.
* **app\_ver** (str, optional): The version of the application requesting activation.
* **os\_ver** (str, optional): The operating system version of the host.
* **hostname** (str, optional): The hostname of the device requesting activation.
* **ip** (str, optional): The IP address of the device.
* **is\_vm** (bool, optional): Indicates whether the application is running on a virtual machine.
* **vm\_info** (str, optional): Information about the virtual machine, if applicable.
* **mac\_address** (str, optional): The MAC address of the device.

**Key-based:**

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H6QM-6H5R-ZENJ-VBLK")

license = manager.activate_license(license_id)
```

**User-based:**

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_user(username="python@gmail.com",password="7t_x3!o9")

license = manager.activate_license(license_id,unique_license_id=1723642193958949)
```

{% hint style="info" %}
There is optional `unique_license_id` which specifies `license_id`. It is preferred that given argument is used when activating user based licenses.
{% endhint %}

Returns (License): License object

#### **load\_license**

Loads the license file and sets attributes for the **LicenseData** instance. Returns an instance of the **License** class reflecting the loaded license.

```python
manager = LicenseManager(conf)

license = manager.load_license()
```

#### **reconfigure**

Change the current configuration

```python
manager = LicenseManager(conf)

manager.reconfigure(
        Configuration(
            product="lkprod2",
            api_key="new_key",
            shared_key="new_key",
            file_key="file_key",
            file_iv="file_iv",
            file_path="bb",
            grace_period_conf=12,
            is_guard_file_enabled=True,
        )
    )
```

#### **clear\_local\_storage**

Delete all files for given product

```python
manager = LicenseManager(conf)
license_id = LicenseID.from_key("H6QM-6H5R-ZENJ-VBLK")  
license = manager.activate_license(license_id)  
manager.clear_local_storage()
```

#### **set\_data\_location**

Set data location

Parameters:

* **path** (str): new data location path

```python
manager = LicenseManager(conf)
manager.set_data_location()
```

Return: None

#### **set\_license\_file\_name**

Set licensefile name

Parameters:

* **name** (str): license file name

```python
manager = LicenseManager(conf)
manager.set_license_file_name()
```

Return: None

#### **is\_online**

Checks if the licensing server is accessible.

Parameters:

* **throw\_e** (bool, optional): If True throws exception, otherwise exception won't be raised.

```python
manager = LicenseManager(conf)

license = manager.is_online()
```

Returns: True if online, False otherwise.

#### **create\_offline\_activation\_file**

Creates request file for **offline activation**.

Parameters:

* **license\_id** (LicenseID)
* **req\_path** (str): path where .req file is created

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H94R-S6KB-L7AJ-SXLK")

req_file_path = manager.create_offline_activation_file(license_id,'offline_files/test')
```

Returns (str): path to request file

#### **activate\_license\_offline**

Activates the .lic file

Parameters:

* **ls\_activation\_path** (str): path to .lic file

```python
manager = LicenseManager(conf)

license = manager.activate_license_offline('path_to_lic_file/ls_activation.lic')
```

Raises:

* **LicenseActivationException**: Activation data is not valid
* **LicenseActivationException**: Response file ID mismatch
* **LicenseActivationException**: License does not belong to this device

Returns (License): License object

#### **get\_air\_gap\_activation\_code**

Get activation code for air gap license

Parameters:

* **initialization\_code** (str): initialization code
* **license\_key** (str): license key

```python
initialization_code = "Q/MWfwp1NWAYARl8Q7KSo5Cg2YKqS2QLlnQ3nEeSBsk="
license_key = "UFF3-E9GA-VUJQ-GMLK"

manager = LicenseManager(conf)
activation_code = manager.get_air_gap_activation_code(initialization_code=initialization_code, license_key=license_key)

print("Activation code:",activation_code)
```

Return (str): activation code

#### **activate\_air\_gap\_license**

Activates air gap license

Parameters:

* **confirmation\_code** (str): confirmation code
* **policy\_path** (str): policy path (file or folder)
* **license\_key** (str): license\_key
* **policy\_id** (str): policy id

```python
confirmation = "ERbQBuE8giIjqMPj972Skipehqn0szQ8TH56INyo3OdtMHO1SuTVsoCOSnJWB6rml98PJ6SjybTPymOVZTG4hQ=="
policy_id = "998"
license_key = "UFF3-E9GA-VUJQ-GMLK"
policy_path = "path_to_air_lic"

manager = LicenseManager(conf)
license = manager.activate_air_gap_license(
                confirmation_code=confirmation, policy_path=policy_path, license_key=license_key, policy_id=policy_id
            )
```

Raises:

* **LicenseActivationException**: Signature verification failed

Return (License): License

#### **get\_trial\_license**

Creates LicenseID for trial licenses

Parameters:

* **customer** (Customer): Customer object
* **license\_policy** (str, optional): license policy code. Defaults to None.

```python
customer = Customer(email='python_policy@gmail.com')  

manager = LicenseManager(conf)

license_id = manager.get_trial_license(customer=customer,license_policy='test')
    
license = manager.activate_license(license_id=license_id)
```

Return (LicenseID): Returns a LicenseID object.

#### **get\_version\_list**

Get versions

Parameters:

* **license\_id** (LicenseID): license id object
* **bundle\_code** (str, optional): specify unique bundle\_code of a bundle
* **unique\_license\_id** (int, optional): A unique identifier for the license.
* **env** (str, optional): Version of environment

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("3ZG2-K25B-76VN-WXLK")

response = manager.get_version_list(license_id=license_id)
```

Return (list): List of versions

#### **get\_installation\_file**

Get installation file

Parameters:

* **license\_id** (LicenseID): An instance containing the license key or user credentials
* **bundle\_code** (str, optional): specify unique bundle\_code of a bundle
* **unique\_license\_id** (int, optional): A unique identifier for the license.
* **env** (str, optional): Version of environment
* **version** (str, optional): Versions

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("3ZG2-K25B-76VN-WXLK")

response = manager.get_installation_file(license_id=license_id)
```

Return (dict): installation file

#### **get\_customer\_license\_users**

Get customer license users

Parameters:

* **customer** (Customer): customer

```python
manager = LicenseManager(conf)

customer = Customer(email="c1@c.com")

response = manager.get_customer_license_users(customer=customer)
```

Return (dict): customer license user

#### **get\_user\_licenses**

Get user licenses

Parameters:

* **license\_id** (LicenseID): license\_id
* **customer\_account\_code** (str, optional): customer account. Defaults to None.
* **id\_token** (str, optional): id\_tokne. Defaults to None.
* **code** (str, optional): code. Defaults to None.
* **redirect\_uri** (str, optional): redirect\_uri. Defaults to None.

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_user(username="t@tt.com", password="d#2!17vi")

response = manager.get_user_licenses(license_id)
```

Return (list): User licenses

#### **get\_sso\_url**

Parameters:

* **account\_code** (str): account code
* **use\_auth\_code** (bool, optional): Use code for response\_type. Defaults to True.

```python
manager = LicenseManager(conf)

response = manager.get_sso_url(account_code="your_account_code")
```

Return (dict): url

#### **get\_product\_details**

Parameters:

* **include\_latest\_version** (bool, optional): include\_latest\_version. Defaults to False.
* **include\_custom\_fields** (bool, optional): include\_custom\_fields. Defaults to False.
* **env** (str, optional): env. Defaults to None.

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("3ZG2-K25B-76VN-WXLK")

response = manager.get_product_details(license_id=license_id)
```

Return (dict): Product details

### Bundle Manager

Object responsible for Bundle operations

```python
from licensespring.licensefile.config import Configuration
from licensespring.licensefile.license_manager import LicenseID
from licensespring.licensefile.bundle_manager import BundleManager

conf = Configuration(
        product="your-product-code",
        api_key="your-api-key",
        shared_key="your-shared-key",
        file_key="d66db34b03c2d6961bb3e14ff40592c0c39ec7210113f194c0da50c2d4d002be",
        file_iv="a770af52b2aa3b73ad218b6cfc4e9707")

bundle_manager = BundleManager(conf)
```

#### activate\_bundle

Activates the bundle

Parameters:

* **license\_id** (LicenseID): An instance containing the license key or user credentials.
* **hardware\_id** (str, optional): A unique identifier for the hardware.
* **unique\_license\_id** (int, optional): A unique identifier for the license.
* **customer\_account\_code** (str, optional): An account code for the customer.
* **id\_token** (str, optional): Token for identity verification.
* **code** (str, optional): An additional code for license verification.
* **redirect\_uri** (str, optional): redirect\_uri. Defaults to None.
* **app\_ver** (str, optional): The version of the application requesting activation.
* **os\_ver** (str, optional): The operating system version of the host.
* **hostname** (str, optional): The hostname of the device requesting activation.
* **ip** (str, optional): The IP address of the device.
* **is\_vm** (bool, optional): Indicates whether the application is running on a virtual machine.
* **vm\_info** (str, optional): Information about the virtual machine, if applicable.
* **mac\_address** (str, optional): The MAC address of the device.

```python
# user based
license_id = LicenseID().from_user(username="ki@ki.com",password="!f53n!z2")
# key based
license_id = LicenseID().from_key("ASQU-AYHA-FX4S-FRLK")

bundles = bundle_manager.activate_bundle(license_id)
```

Return (dict\[str, License]): A dictionary where the keys are product short codes and the values are License objects.

#### get\_current\_bundle

Get current bundle from cache or licensefile.

```python
bundles = bundle_manager.get_current_bundle()
```

Return (dict\[str, License]): A dictionary where the keys are product short codes and the values are License objects.

#### create\_offline\_activation\_file

Creates .req file for activation

Parameters:

* **license\_id** (LicenseID): An instance containing the license key or user credentials.
* **req\_path** (str): Specify place where to create .req file
* **hardware\_id** (str, optional): A unique identifier for the hardware.
* **app\_ver** (str, optional): The version of the application requesting activation.
* **os\_ver** (str, optional): The operating system version of the host.
* **hostname** (str, optional): The hostname of the device requesting activation.
* **ip** (str, optional): The IP address of the device.
* **is\_vm** (bool, optional): Indicates whether the application is running on a virtual machine.
* **vm\_info** (str, optional): Information about the virtual machine.
* **mac\_address** (str, optional): The MAC address of the device.
* **device\_variables** (dict, optional): device variables.

```python
license_id = LicenseID.from_key("VNFT-7KPY-D5BQ-5NLK")
    
req_file_path = bundle_manager.create_offline_activation_file(license_id, "file_path")
```

Return (str): path of the .req file

#### activate\_bundle\_offline

Activate offline bundle licenses

Parameters:

* **ls\_activation\_path** (str): path to a .lic file

```python
bundle_manager.activate_bundle_offline("file_path_to_lic_file.lic")
```

Return (dict\[str, License]): dictionary of licenses in a bundle

#### deactivate\_bundle\_offline

Generates .req file for the offline deactivation

Parameters:

* **license\_id** (LicenseID)
* **offline\_path** (str): path of the .req file
* **unique\_license\_id** (int): unique license id

```python
license_id = LicenseID.from_key("VNFT-7KPY-D5BQ-5NLK")
file_path = bundle_manager.deactivate_bundle_offline(license_id,"file_path")
```

Return (str): path of the deactivation file

#### check\_bundle

Check bundle and update the licensefile

Parameters:

* **license\_id** (LicenseID)
* **hardware\_id** (str, optional): A unique identifier for the hardware. Defaults to None.
* **unique\_license\_id** (int, optional): A unique identifier for the license. Defaults to None.
* **include\_expired\_features** (bool, optional): If True, includes expired license features in the check. Defaults to False.
* **env** (str, optional): optional param takes "win", "win32", "win64", "mac", "linux", "linux32" or "linux64". Defaults to None.

```python
license_id = LicenseID.from_key("VNFT-7KPY-D5BQ-5NLK")
# make sure that bundle is activated
bundles = bundle_manager.check_bundle(license_id,"file_path")
```

Returns (dict\[str, License]): A dictionary where the keys are product short codes and the values are License objects.

#### deactivate\_bundle

Deactivate bundle

Parameters:

* **license\_id** (LicenseID)
* **hardware\_id** (str, optional): hardware id. Defaults to None.
* **unique\_license\_id** (int, optional): A unique identifier for the license. Defaults to None.
* **remove\_local\_data** (bool, optional): remove licensefile from storage. Defaults to False.

```python
license_id = LicenseID.from_key("VNFT-7KPY-D5BQ-5NLK")

bundle_manager.deactivate_bundle(license_id,"file_path")
```

### License

Object responsible for license operations

#### **Getters**

All getters which are reading the license fields from a local licensefile

```python
# Floating 
license.is_floating_expired() # Determines whether the license floating period has expired
license.floating_timeout() # License floating timeout
license.is_floating() # True if license if floating, otherwise False
license.floating_client_id() # Floating client id 
license.is_controlled_by_floating_server() # Check if license is controlled by Floating Server 
license.floating_in_use_devices() # Number of floating devices in use 
license.floating_end_date() # Datetime when device will be released
license.max_floating_users() # Number of max floating users
license.expiry_date() # Get the expiry date of a floating license
license.borrow_until() # Get the date until a license is borrowed
license.is_borrowed() # Check if a license is borrowed

# time-limited
license.is_validity_period_expired() # Determines whether the license's validity period has expired
license.validity_period() # Gets the license validity period in UTC
license.validity_with_grace_period() # Gets the validity period with grace period of the license in UTC
license.days_remaining() # Gets how many days are left until the validity period ends
license.is_expired() # Checks if a license validity has expired

# consumption
license.local_consumptions() # Get local consumptions
license.max_consumptions() # Get max consumptions
license.total_consumptions() # Get total consumptions
license.max_overages() # Get max overages
license.allow_unlimited_consumptions() # Check if unlimited consumptions are allowed
license.consumption_reset() # Check if there is consumption reset
license.allow_overages() # Check if overages are allowed

# subscription 
license.allow_grace_subscription_period() # Check if grace subscription period is allowed
license.is_subscription_grace_period_started() # Check if grace subscription period has started
license.get_grace_period() # Get grace period
license.subscription_grace_period() # Get subscription grace period

# all 
license.license_user() # Gets the license user
license.is_grace_period_started() # Checks if grace period has started
license.grace_period_hours_remaining() # Get remain hours of grace period
license.maintenance_days_remaining() # Gets how many days are left until the maintenance ends
license.customer_information() # Gets customer information
license.id() # Gets a license id
license.max_transfers() # Get a license max transfers
license.transfer_count() # Get the transfer count
license.is_device_transfer_allowed() # Get if a device transfer is allowed
license.is_device_transfer_limited() # Get if a device transfer is limited
license.days_since_last_check() # Get how many days passed since the last check
license.start_date() # Get a license start date in UTC
license.maintenance_period() # Get a license maintenance period in UTC
license.is_maintence_period_expired() # Checks if maintenance period has expired
license.last_check() # Get when last check was performed in UTC
license.activation_date() # Get when activation was performed in UTC
license.last_usage() # Gets a license last usage in UTC
license.license_type() # Gets the last license usage
license.max_activations() # Gets the license max activations
license.metadata() # Gets the license metadata
license.allow_unlimited_activations() # Check if unlimited activations are allowed
license.license_enabled() # Checks if a license is enabled
license.license_active() # Checks if a license is active
license.is_valid() # Checks if the license is valid (license is active, enabled and didn't expired)
license.prevent_vm() # Checks if a license prevents virtual machines
license.is_trial() # Checks if a license is trial
license.get_product_details() # Get product details
license.get_device_variable('device_var') # Get device variable if exists

# features
license.get_feature_data('feature_code') # Get feature data
```

#### **check\_license\_status**

Verifies the current status of the license. It raises exceptions if the license is not enabled, not active, or expired.

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")

license = manager.activate_license(license_id)
    
license.check_license_status()
```

Raises:

* **LicenseStateException**: Raised if the license fails one of the following checks:
  * License is **not enabled**.
  * License is **not active**.
  * License validity period has **expired**.

Return: None

#### **check**

Performs an online check to synchronize the license data with the backend. This includes syncing consumptions for consumption-based licenses.

Parameters:

* **include\_expired\_features** (bool, optional): Includes expired license features in the check.
* **env** (str, optional): "win", "win32", "win64", "mac", "linux", "linux32" or "linux64"

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")

license = manager.activate_license(license_id)
    
response = license.check()
```

Raises:

* **ClientError**: Raised if there's an issue with the API client's request.
* **RequestException**: Raised if there's a problem with the request to the licensing server.

Return (dict): The updated license cache.

#### **deactivate**

Deactivates the license and optionally deletes the local license file.

Parameters:

* **delete\_license** (bool, optional): If True, deletes the local license file upon deactivation.

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")

license = manager.activate_license(license_id)
    
license.deactivate()
```

Return: None

#### **local\_check**

Ensures the integrity and consistency of the licensing information by comparing the data stored in the local license file with the predefined configurations in the **Configuration** object.

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")

license = manager.activate_license(license_id)
    
license.local_check()
```

Raises:

* **ConfigurationMismatch**: Raised if the product code or hardware ID in the license file does not match the expected values provided in the **Configuration**.
* **VMIsNotAllowedException**: Raised if the license is used in a VM environment when the license explicitly disallows it.
* **TimeoutExpiredException**: Raised if a floating license has expired.
* **ClockTamperedException**: Raised if there is evidence of tampering with the system's clock.

Return: None

#### **add\_local\_consumption**

Adds local consumption records for consumption-based licenses.

Parameters:

* **consumptions** (int, optional): The number of consumptions to add locally.

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")

license = manager.activate_license(license_id)
    
license.add_local_consumption()
```

Raises:

* **LicenseSpringTypeError**: Raised if the license type does not support consumption.
* **ConsumptionError**: Raised if adding the specified number of consumptions would exceed the allowed maximum for the license.

Return: None

#### **sync\_consumption**

Synchronizes local consumption data with the server, adjusting for overages if specified.

Parameters:

* **req\_overages** (int, optional): Specifies behavior for consumption overages.

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")

license = manager.activate_license(license_id)

license.add_local_consumption(5)
    
license.sync_consumption()
```

Raises:

* **RequestException**: Raised if the request to synchronize consumption data with the server fails.

Return (bool): True if the consumption data was successfully synchronized; False otherwise.

#### **is\_grace\_period**

Determines if the current license state is within its grace period following a specific exception.

Parameters:

* **ex** (Exception): Raised Exception

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")

license = manager.activate_license(license_id)

try:
    license.check()

except Exception as ex:
    boolean = license.is_grace_period(ex)    
```

Return (bool): True if the license is within its grace period, False otherwise.

#### **change\_password**

Changes password of a user

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_user(username="python@gmail.com",password="7t_x3!o9")

license = manager.activate_license(license_id)

license.change_password("7t_x3!o9","12345678")
```

Return (str): "password\_changed"

#### **add\_local\_feature\_consumption**

Adds local consumption to the feature.

Parameters:

* **feature** (str): feature code.
* **consumptions** (int, optional): Number of consumptions.

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")

license = manager.activate_license(license_id)

license.add_local_feature_consumption("lkprod1cf1",3)
```

Raises:

* **ItemNotFoundError**: If the feature specified by `feature_code` does not exist.
* **LicenseSpringTypeError**: If the identified feature is not of the "consumption" type.
* **ConsumptionError**: If adding the specified number of consumptions would exceed the feature's consumption limits.

Return: None

#### **sync\_feature\_consumption**

Synchronizes local consumption data with the server.

Parameters:

* **feature** (str): feature code.

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")

license = manager.activate_license(license_id)

license.add_local_feature_consumption("lkprod1cf1",3)

license.sync_feature_consumption("lkprod1cf1")
```

Raises:

* **RequestException**: Raised if the request to synchronize consumption data with the server fails.

Return (bool): True if the consumption data was successfully synchronized; False otherwise.

#### **floating\_borrow**

Attempts to borrow a floating license until the specified date.

Parameters:

* **borrow\_until** (str): A string representing the date until which the license should be borrowed.
* **password** (str, optional)
* **id\_token** (str, optional)
* **code** (str, optional)
* **redirect\_uri** (str,optinal): redirect uri. Defaults to None.
* **customer\_account\_code** (str, optional)

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")

license = manager.activate_license(license_id)

license.floating_borrow("2031-05-06T00:00:00Z")
```

Return: None

#### **floating\_release**

Releases a borrowed floating license and updates the license status accordingly.

Parameters:

* **throw\_e** (bool): A boolean indicating whether to raise an exception on failure.

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")

license = manager.activate_license(license_id)

license.check()

license.floating_release(False)
```

Raises:

* **Exception**

Return: None

#### **check\_feature**

Checks for a specific license feature and updates the license cache accordingly.

Parameters:

* **feature** (str): feature code.
* **add\_to\_watchdog** (bool, optional): A boolean indicating whether to add the feature check to a watchdog routine. Default is False.

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")

license = manager.activate_license(license_id)

license.check_feature("lkprod1f1fc1")
```

Raises:

* **Exception**

Return: None

#### **release\_feature**

Releases a borrowed license feature and updates the license cache accordingly.

Parameters:

* **feature** (str): feature code.

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")

license = manager.activate_license(license_id)

license.check_feature("lkprod1f1fc1")

license.release_feature("lkprod1f1fc1")
```

Raises:

* **Exception**

Return: None

#### **update\_offline**

Updates license via refresh file

Parameters:

* **path** (str): path of the refresh file
* **reset\_consumption** (bool): True resets consumption otherwise False

```python
file_path = 'path_to_lic_file/license.lic'

manager = create_manager(product="lkprod1",is_guard_file_enabled=True)

license = manager.activate_license_offline(file_path)

license.update_offline('offline_files/license_refresh.lic',False)
```

Raises:

* **ConfigurationMismatch**: The update file does not belong to this device
* **ConfigurationMismatch**: The update file does not belong to this product

Return (bool): True if license was successfully updated otherwise False

#### **deactivate\_offline**

Generates .req file for the offline deactivation

Parameters:

* **offline\_path** (str): path of the .req file
* **device\_variables** (dict): device variables

```python
file_path = 'path_to_lic_file/license.lic'

manager = create_manager(product="lkprod1",is_guard_file_enabled=True)

license = manager.activate_license_offline(file_path)

license.deactivate_offline('path_where_to_create_req_file')
```

Return (str): path of the deactivation file

#### **get\_deactivation\_code**

Get deactivation code for air gap licenses

Parameters:

* **initialization\_code** (str): initialization\_code

```python
initialization_code="your_initialization_code"
manager = LicenseManager(conf)
#load air gap license
license = manager.load_license()

deactivation_code = license.get_deactivation_code(initialization_code)

print("Deactivation code:",deactivation_code)
```

Return (str): deactivation code

#### **deactivate\_air\_gap**

Deactivate air gap license and clear storage

Parameters:

* **confirmation\_code** (str): confirmation\_code

```python
confirmation_code="your_confirmation_code"
manager = LicenseManager(conf)
#load air gap license
license = manager.load_license()
license.deactivate_air_gap(confirmation_code)
```

Raises:

* **LicenseActivationException**: VerificationError

Return: None

#### **product\_details**

Update product details from LicenseSpring server

Parameters:

* **include\_custom\_fields** (bool, optional): custom fields information. Defaults to False.
* **include\_latest\_version** (bool, optional): Latest version information. Defaults to False.
* **env** (str, optional): "win", "win32", "win64", "mac", "linux", "linux32" or "linux64"

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H9V3-72XX-ZRAJ-S6LK")

license = manager.activate_license(license_id)
    
response = license.product_details() 
```

Return (dict): response

#### **set\_device\_variables**

Set device variables locally

Parameters:

* **variables** (dict): variables dict
* **save** (bool, optional): Save cache to licensefile. Defaults to True.

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H9V3-72XX-ZRAJ-S6LK")

license = manager.activate_license(license_id)
    
license.set_device_variables({"english":"value"})
```

Return: None

#### **get\_device\_variables**

Get device variables from server or locally

Parameters:

* **get\_from\_be** (bool, optional): If True collects data from LicenseSpring server. Defaults to True.

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H9V3-72XX-ZRAJ-S6LK")

license = manager.activate_license(license_id)
    
device_var_list = license.get_device_variables(get_from_be=True)  

print(device_var_list)
```

Return (list): List of device variables

#### **send\_device\_variables**

Send device variables to LicenseSpring server. Handles GracePeriod

Parameters:

* **variables** (dict): variables dict
* **save** (bool, optional): Save cache to licensefile. Defaults to True.

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H9V3-72XX-ZRAJ-S6LK")

license = manager.activate_license(license_id)
    
license.send_device_variables()
```

Return (bool): True if new variables are sent to LicenseSpring server otherwise, False

#### **custom\_fields**

Get custom fields from licensefile

```python
manager = LicenseManager(conf)

license_id = LicenseID.from_key("H9V3-72XX-ZRAJ-S6LK")

license = manager.activate_license(license_id)
    
response = license.custom_fields()
```

Return (list): Custom fields


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.licensespring.com/sdks/python-sdk/licensefile-setup-and-usage.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
