LicenseSpring Python Library
The LicenseSpring Python Library provides convenient access to the LicenseSpring API from applications written in the Python language.
Installation
Install licensespring library:
pip install licensespring
Requires: Python >=3.9
Set app version
import licensespring
licensespring.app_version = "MyApp 1.0.0"
Hardware (Device) IDs
This library provides preconfigured hardware identity providers:
HardwareIdProvider(default)PlatformIdProviderHardwareIdProviderSource(recommended)
You can set the desired hardware identity provider when initializing the Configuration:
from licensespring.hardware import PlatformIdProvider
from licensespring.licensefile.config import Configuration
conf = Configuration(product="your_product_short_code", hardware_id_provider=PlatformIdProvider)
It also supports their customization and creation of your own hardware id provider.
HardwareIdProvider
Uses uuid.getnode() to generate unique ID per device as described:
Get the hardware address as a 48-bit positive integer. The first time this runs, it may launch a separate program, which could be quite slow. If all attempts to obtain the hardware address fail, we choose a random 48-bit number with the multicast bit (least significant bit of the first octet) set to 1 as recommended in RFC 4122. “Hardware address” means the MAC address of a network interface. On a machine with multiple network interfaces, universally administered MAC addresses (i.e. where the second least significant bit of the first octet is unset) will be preferred over locally administered MAC addresses, but with no other ordering guarantees.
All of the methods exposed by HardwareIdProvider:
class HardwareIdProvider:
def get_id(self):
return str(uuid.getnode())
def get_os_ver(self):
return platform.platform()
def get_hostname(self):
return platform.node()
def get_ip(self):
return socket.gethostbyname(self.get_hostname())
def get_is_vm(self):
return False
def get_vm_info(self):
return None
def get_mac_address(self):
return ":".join(("%012X" % uuid.getnode())[i : i + 2] for i in range(0, 12, 2))
def get_request_id(self):
return str(uuid.uuid4())
HardwareIdProviderSource
Utilizes a proprietary in-house algorithm for our SDKs (recommended algorithm) Hardware ID Algorithm.
class HardwareIdProviderSource(HardwareIdProvider):
def get_id(self):
hardware_id = get_hardware_id(HardwareIdAlgorithm.Default)
if logging.getLogger().hasHandlers():
logs = get_logs()
version = get_version()
logging.info("Version: ",version)
logging.info("Hardware ID:",hardware_id)
for log_line in logs:
logging.info(log_line)
return hardware_id
PlatformIdProvider
Uses sys.platform and OS queries to find the raw GUID of the device.
Extends the HardwareIdProvider and overwrites only the get_id method:
class PlatformIdProvider(HardwareIdProvider):
def get_id(self):
id = None
if sys.platform == 'darwin':
id = execute("ioreg -d2 -c IOPlatformExpertDevice | awk -F\\\" '/IOPlatformUUID/{print $(NF-1)}'")
if sys.platform == 'win32' or sys.platform == 'cygwin' or sys.platform == 'msys':
id = read_win_registry('HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography', 'MachineGuid')
if not id:
id = execute('wmic csproduct get uuid').split('\n')[2].strip()
if sys.platform.startswith('linux'):
id = read_file('/var/lib/dbus/machine-id')
if not id:
id = read_file('/etc/machine-id')
if sys.platform.startswith('openbsd') or sys.platform.startswith('freebsd'):
id = read_file('/etc/hostid')
if not id:
id = execute('kenv -q smbios.system.uuid')
if not id:
id = super().get_id()
return id
Customization
Extend any of the preconfigured hardware identity providers, overwrite the methods you want and provide it when initializing the Configuration:
class CustomHardwareIdProvider(HardwareIdProvider):
def get_id(self):
return "_my_id_"
conf = Configuration(product="your_product_short_code", hardware_id_provider=CustomHardwareIdProvider)
Licensefile
Licensefile setup
The licensefile is encrypted (AES-256-GCM) automatically; no manual key/IV setup is required. The encryption password is derived from your shared_key (API keys) or client_secret (OAuth). file_key/file_iv on Configuration are optional overrides, only needed if you're migrating a licensefile created with a custom key/IV on an older SDK version.
Configuration Setup
from licensespring.licensefile.config import Configuration
conf = Configuration(product="your_product_short_code",
api_key="your_api_key",
shared_key="your_shared_key",
file_key=None,
file_iv=None,
hardware_id_provider=HardwareIdProviderSource,
verify_license_signature=True,
signature_verifier=SignatureVerifier,
api_domain="api.licensespring.com",
api_version="v4",
filename="License",
file_path=None,
file_extension="key",
grace_period_conf=24,
air_gap_public_key="your_air_gap_public_key",
client_id="your_client_id",
client_secret="your_client_secret",
certificate_chain_path="path_to_certificate/chain.pem",
enable_airgapped_skip_time_check=False,
enable_process_safety=False,
tpm_enabled=False)
- product (str): product short code.
- 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, optional): Only needed when migrating a licensefile created with a custom key on an older SDK version; otherwise the password is derived automatically from
shared_key/client_secret. See Licensefile setup. - file_iv (str, optional): Used alongside
file_keyfor the same migration case. - 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
HardwareIdProviderSource. - 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.
- file_extension (str, optional): The extension used for the saved license file, without the leading dot. Defaults to "key" (e.g. "License.key"). The lock file used for cross-process safety is derived from this too (e.g. "License.key.lock").
- grace_period_conf (int, optional): The number of hours to allow as a grace period for Defaults to 24 hours.
- air_gap_public_key (str, optional): Air gap public key from platform check here for more
- 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): Used for singature verification for Floating Server v2 (e.g "path_to_cert_chain/chain.pem"). This file is provided by the platform.
- enable_airgapped_skip_time_check (bool, optional): When set to True, SDK would skip checking date time with airgap licenses, until turned on again.
- enable_process_safety (bool, optional): Opt-in flag for cross-process-safe licensefile writes (advisory OS-level file locking). Defaults to False: the SDK does not acquire or wait on any lock.
- tpm_enabled (bool, optional): Opt-in flag to bind the license to this device's TPM/Secure Enclave key pair in addition to the hardware ID. Defaults to False.
Warning:
hardware_id_providernow defaults toHardwareIdProviderSource; passhardware_id_provider=HardwareIdProviderexplicitly if you need the legacy provider.- if both API keys and OAuth is specified SDK will use OAuth for authorization
LicenseID
- 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
license_id = LicenseID.from_key("your_license_key")
User-based setup
license_id = LicenseID.from_user(username="email@email.com",password="password")
LicenseManager
from licensespring.licensefile.license_manager import LicenseManager,LicenseID
manager = LicenseManager(conf)
Configuration parameters
conf (Configuration): A configuration object
Activation methods
Methods for activating a license, grouped by whether they require a live connection to the license server (Online) or not (Offline).
Online
activate_license
Activates a license with the license server and updates local license data. When activating user based license we advise that unique_license_id is set which represent "id" field within the license check.
Key-based
manager = LicenseManager(conf)
license_id = LicenseID.from_key("H6QM-6H5R-ZENJ-VBLK")
license = manager.activate_license(license_id)
User-based
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)
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.
Return: License object representing the activated license.
Offline
create_offline_activation_file
Creates .req file for offline activation, including various optional parameters related to the device and software environment.
Parameters:
- license_id (LicenseID): An instance containing the license key or user credentials.
- req_path (str): Specify the path where to create .req file.
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')
Return (str): Path of the .req file created for activation.
activate_license_offline
Activates a license offline using a .lic file provided via the specified path.
Parameters:
- ls_activation_path (str): Path to the activation file.
file_path = 'offline_files/ls_activation.lic'
manager = LicenseManager(conf)
license = manager.activate_license_offline(file_path)
Raises:
- LicenseActivationException: Activation data is not valid.
- LicenseActivationException: Response file ID mismatch.
- LicenseActivationException: License does not belong to this device.
Return(License): Returns a License object representing the activated license.
get_air_gap_activation_code
Get activation code for air gap license
Parameters:
- initialization_code (str): initialization code
- license_key (str): license key
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
Activate 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
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
load_license
Loads the license file and sets attributes for the LicenseData instance. Returns an instance of the License class reflecting the loaded license.
manager = LicenseManager(conf)
license = manager.load_license()
Return: License object representing the activated license.
reconfigure
Change the current configuration
Parameters:
- conf (Configuration): Configuration object
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,
)
)
LicenseManager getters and utilities
Accessor and utility methods on the LicenseManager object, grouped by whether they read purely local data (Offline) or make a network call to the license server (Online). Used the same way as manager.current_config().
Offline
current_config()->dict: Get current configurationis_license_file_corrupted()->bool: Checks if the licensefile is corruptedclear_local_storage(): Clear all data from the current productdata_location()->str: Get licensefile locationset_data_location(path: str): Set data locationlicense_file_name()->str: Get licensefile nameset_license_file_name(name: str): Set licensefile name
Online
is_online(throw_e: bool = True)->bool: Checks if the licensing server is accessibleget_version_list(license_id: LicenseID, channel: str = None, unique_license_id: int = None, env: str = None)->list: Get the list of available versions for a licenseget_product_details(include_latest_version: bool = False, include_custom_fields: bool = False, env: str = None)->dict: Get product details from the serverget_installation_file(license_id: LicenseID, unique_license_id: int = None, env: str = None, version: str = None, channel: str = None)->dict: Get the installation file for a versionget_customer_license_users(customer: Customer)->dict: Get the license users belonging to a customerget_user_licenses(license_id: LicenseID = None, customer_account_code: str = None, id_token: str = None, code: str = None, redirect_uri: str = None)->list: Get the licenses belonging to a userget_sso_url(account_code: str, use_auth_code: bool = True)->dict: Get the SSO url for a customer account
get_trial_license
Creates LicenseID for trial licenses
Parameters:
- customer (Customer): Customer object
- license_policy (str,optional): license policy code. Defaults to None.
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.
Bundle Manager
Object responsible for Bundle operations
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)
Online
Methods that make a network call to the license server.
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.
#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.
check_bundle
Check bundle and update the licensefile
Parameters:
- license_id (LicenseID): license_id
- 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.
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): license_id
- 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.
license_id = LicenseID.from_key("VNFT-7KPY-D5BQ-5NLK")
bundle_manager.deactivate_bundle(license_id,"file_path")
Offline
Methods that operate on local licensefile/cache data or offline activation files, without contacting the license server.
get_current_bundle
Get current bundle from cache or licensefile.
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.
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
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): license_id offline_path (str): path of the .req file unique_license_id (int): unique license id
license_id = LicenseID.from_key("VNFT-7KPY-D5BQ-5NLK")
bundle_manager.deactivate_bundle_offline(license_id,"file_path")
Return(str): path of the deactivation file
License object
Object responsible for license operations
License getters
Read-only accessors on the License object that return cached license data (no network calls or side effects), most taking no arguments, used the same way as license.is_expired():
is_floating_expired()->bool: Determines whether the license's floating period has expiredfloating_timeout()->int: Retrieve the license floating timeoutis_floating()->bool: Check if license is floating (Floating Server or Floating Cloud)floating_client_id()->str: Get floating client idis_controlled_by_floating_server()->bool: Check if license is controlled by Floating Serverfloating_in_use_devices()->int: Number of floating devices in usefloating_end_date()->datetime: Datetime when the floating license will be releasedmax_floating_users()->int: Number of max floating usersis_validity_period_expired()->bool: Determines whether the license's validity period has expiredvalidity_period()->datetime: Gets validity period of the licensevalidity_with_grace_period()->datetime: Gets the validity period with grace period of the licenselicense_user()->dict: Gets the license usermaintenance_days_remaining()->int: Gets how many days are left until the maintenance endsdays_remaining()->int: Gets how many days are left until the validity period endscustomer_information()->dict: Gets customer informationid()->int: Gets license idmax_transfers()->int: Get the max transferstransfer_count()->int: Get the transfer countis_device_transfer_allowed()->bool: Get if the device transfer is allowedis_device_transfer_limited()->bool: Get if the device transfer is limiteddays_since_last_check()->int: Get how many days passed since last checkstart_date()->datetime: Get the start date of the licensemaintenance_period()->datetime: Get the maintenance period of the licenseis_maintenance_period_expired()->bool: Checks if the maintenance period has expiredlast_check()->datetime: Gets when the last check was performedlast_usage()->datetime: Gets when the license was last usedactivation_date()->datetime: Gets when the license was last usedlicense_type()->str: Gets the license typemax_activations()->int: Gets the license max activationsmetadata()->dict: Gets the license metadataallow_unlimited_activations()->bool: Check if unlimited activations are allowedallow_grace_subscription_period()->bool: Check if grace subscription period is allowedis_subscription_grace_period_started()->bool: Check if grace subscription period has startedis_grace_period_started()->bool: Check if license is in grace periodgrace_period_hours_remaining()->int: Get remain hours of grace periodget_grace_period()->int: Get grace periodsubscription_grace_period()->int: Get subscription grace periodis_expired()->bool: Checks if the license validity has expiredlicense_enabled()->bool: Checks if the license is enabledlicense_active()->bool: Checks if the license is activeis_valid()->bool: Checks if the license is valid (license is active, enabled and didn't expired)prevent_vm()->bool: Checks if the license prevents virtual machinesis_trial()->bool: Checks if the license is trialexpiry_date()->datetime: Get expiry date of floating licenseborrow_until()->datetime: Get the date until a license is borrowedis_borrowed()->bool: Check if a license is borrowedlocal_consumptions()->int: Get local consumptionsmax_consumptions()->int: Get max consumptionstotal_consumptions()->int: Get total consumptionsmax_overages()->int: Get max overagesallow_unlimited_consumptions()->int: Check if unlimited consumptions is allowedconsumption_reset()->bool: Check if there is consumption resetallow_overages()->bool: Check if overages are allowedconsumption_period()->str: Get consumption periodfeatures()->list: Get feature listget_product_details()->dict: Get product details from licensefile (offline)custom_fields()->list: Get custom fields from licensefile ->[{name, value},..]get_custom_field(field_name)->dict: Get a single custom field by name from licensefile ->{name, value}is_tpm_auth()->bool: Check if license is bound to a TPM/Secure Enclave key pairtpm_signing_public_key()->str: Get the TPM/Secure Enclave signing public key enrolled with the licenseget_feature_data(feature_code)->dict: Get feature datais_grace_period(ex)->bool: Determines if the current license state is within its grace period following a specific exceptionget_device_variable(variable_name)->dict: Get device variable if exists
check_license_status
Verifies the current status of the license. It raises exceptions if the license is not enabled, not active, or expired
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"
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, such as invalid credentials or unauthorized access.
RequestException: Raised if there's a problem with the request to the licensing server, such as network issues or server unavailability.
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.
manager = LicenseManager(conf)
license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")
license = manager.activate_license(license_id)
license.deactivate()
Return: None
local_check
This method 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.
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. This is more relevant if is_floating_expired is later implemented to perform actual checks.
ClockTamperedException: Raised if there is evidence of tampering with the system's clock, detected by comparing the system's current time with the last usage time recorded in the license file.
Return: None
add_local_consumption
Adds local consumption records for consumption-based licenses. Parameters:
- consumptions (bool, optional): The number of consumptions to add locally
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 (i.e., not a consumption-based license).
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.
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, for instance, due to network issues or server unavailability.
Return (bool): True if the consumption data was successfully synchronized; False otherwise.
change_password
Changes password of a user
Parameters:
- password (str): Old password of license user
- new_password(str): New password of license user
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(password="7t_x3!o9",new_password="12345678")
Return (str): "password_changed"
setup_license_watch_dog
Initializes and starts the license watchdog with the specified callback and timeout settings.
Parameters:
callback (Callable): A callable to be executed by the watchdog in response to specific events or conditions.
timeout (int): The period in minutes after which the watchdog should perform its checks.
deamon (bool, optional): Run thread as deamon. Defaults to False.
run_immediately (bool,optional): run license check immediately, if False wait for timeout first.
manager = LicenseManager(conf)
license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")
license = manager.activate_license(license_id)
license.setup_license_watch_dog(callback,timeout)
Return: None
stop_license_watch_dog
Stops the license watchdog if it is currently running, effectively halting its monitoring and callback activities.
manager = LicenseManager(conf)
license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")
license = manager.activate_license(license_id)
license.setup_license_watch_dog(callback,timeout)
license.stop_license_watch_dog()
Return: None
setup_feature_watch_dog
Initializes and starts the feature watchdog with the specified callback and timeout.
Parameters:
callback (Callable): A callable to be executed by the watchdog in response to specific events or conditions.
timeout (int): The period in minutes after which the watchdog should perform its checks.
deamon (bool, optional): Run thread as deamon. Defaults to False.
manager = LicenseManager(conf)
license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")
license = manager.activate_license(license_id)
license.setup_feature_watch_dog(callback,timeout)
Return: None
stop_feature_watch_dog
Stops the feature watchdog if it is currently running.
manager = LicenseManager(conf)
license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")
license = manager.activate_license(license_id)
license.setup_feature_watch_dog(callback,timeout)
license.stop_feature_watch_dog()
Return: None
add_local_feature_consumption
Adds local consumption to the feature.
Parameters:
- feature (str): feature code.
- consumptions (int,optional): Number of consumptions.
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_codedoes 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.
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")
Return (bool): True if the consumption data was successfully synchronized; False otherwise.
floating_borrow
Attempts to borrow a floating license until the specified date, updating the system status based on the outcome of the borrow attempt.
Parameters:
- borrow_until (str): A string representing the date until which the license should be borrowed.
- password (str,optional): Password for the license if required.
- id_token (str, optional): id_token. Defaults to None.
- code (str, optional): code. Defaults to None.
- customer_account_code (str, optional): customer account code. Defaults to None.
- redirect_uri (str,optinal): redirect uri. Defaults to None.
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.
manager = LicenseManager(conf)
license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")
license = manager.activate_license(license_id)
license.check()
license.floating_release(False)
Return: None
check_feature
Checks for a specific license feature and updates the license cache accordingly.
Parameters:
- feature(str): feature code.
manager = LicenseManager(conf)
license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")
license = manager.activate_license(license_id)
license.check_feature("lkprod1f1fc1")
Return: None
release_feature
Releases a borrowed license feature and updates the license cache accordingly.
Parameters:
- feature(str): feature code.
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")
Return: None
borrow_feature
Borrow license feature.
Parameters:
- feature (str): feature code
- borrow_until (str): borrow until e.g "2029-05-06T00:00:00Z"
- password(str, optional): password. Defaults to None.
- id_token (str, optional): id_token. Defaults to None.
- code (str, optional): code. Defaults to None.
- customer_account_code (str, optional): customer account code. Defaults to None.
manager = LicenseManager(conf)
license_id = LicenseID.from_key("H7G3-F4PJ-4AEJ-UKYL")
license = manager.activate_license(license_id)
license.check_feature("lkprod1f1fc1")
license.borrow_feature("lkprod1f1fc1","2029-05-06T00:00:00Z")
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
file_path = 'path_to_lic_file/license.lic'
manager = LicenseManager(conf)
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
get_deactivation_code
Get deactivation code for air gap licenses
Parameters:
- initialization_code (str): initialization_code
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
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
deactivate_offline
Generates .req file for the offline deactivation
Parameters:
- offline_path(str): path of the .req file
- device_variables (dict): device variables
file_path = 'path_to_lic_file/license.lic'
manager = LicenseManager(conf)
license = manager.activate_license_offline(file_path)
license.deactivate_offline('path_where_to_create_req_file')
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
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): Lateset version information. Defaults to False.
- env (str, optional): "win", "win32", "win64", "mac", "linux", "linux32" or "linux64"
manager = LicenseManager(conf)
license_id = LicenseID.from_key("H9V3-72XX-ZRAJ-S6LK")
license = manager.activate_license(license_id)
response = license.product_details()
Raises:
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.
manager = LicenseManager(conf)
license_id = LicenseID.from_key("H9V3-72XX-ZRAJ-S6LK")
license = manager.activate_license(license_id)
license.set_device_variables({"english":"value"})
Raises:
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.
manager = LicenseManager(conf)
license_id = LicenseID.from_key("H9V3-72XX-ZRAJ-S6LK")
license = manager.activate_license(license_id)
license.get_device_variables(get_from_be=True)
Raises:
- RequestException (Grace period not allowed)
Return(list): List of device variables
send_device_variables
Send device variables to LicenseSpring server. Handles GracePeriod
manager = LicenseManager(conf)
license_id = LicenseID.from_key("H9V3-72XX-ZRAJ-S6LK")
license = manager.activate_license(license_id)
license.send_device_variables()
Raises:
- RequestException (Grace period not allowed)
Return(bool): True if new variables are sent to LicenseSpring server otherwise, False
Floating Server
Floating Manager:
- This object is responsible for managing operations with the Floating Server, while also integrating the license file
Floating Manager
To initialize Floating Manager Configuration needs to be created. For Floating server you can set arbitrary values for shared_key and api_key keys. To enable signature verification in Floating Server v2, set the certificate_chain_path in the Configuration object.
auth
Authenticate
Parameters:
- username (str): username
- password (str): password
from licensespring.licensefile.config import Configuration
from licensespring.licensefile.floating_manager import FloatingManager
fs_manager = FloatingManager(conf=conf)
fs_manager.auth(username="admin",password="tetejac")
Return(dict): Response
register
Register license
Parameters:
- os_hostname (str, optional): os hostname. Defaults to None.
- ip_local (str, optional): ip local. Defaults to None.
- user_info (str, optional): user info. Defaults to None.
- license_id (int, optional):license id. Defaults to None.
from licensespring.licensefile.config import Configuration
from licensespring.licensefile.floating_manager import FloatingManager
conf = Configuration(
product=product,
api_key="arbitrary",
shared_key="arbitrary",
file_key="your_file_key",
file_iv="your_file_iv",
api_domain="api_domain",
api_protocol="http/https",
certificate_chain_path="certificate_chain_path/chain.pem" # used for signature verification
)
fs_manager = FloatingManager(conf=conf)
license = fs_manager.register()
Return(License): License object
unregister
Parameters
- license_id (int, optional): license id. Defaults to None.
Unregister license
fs_manager = FloatingManager(conf=conf)
# There are multiple options to unregister a license
# 1. floating manager
fs_manager.unregister()
# 2.1. license object -> deactivate method
license.deactivate()
#2.2 license object -> floating release
license.floating_release(False)
Return(str): "user_unregistered"
unregister_all
Unregister all users
fs_manager = FloatingManager(conf=conf)
fs_manager.unregister_all()
borrow_license
Borrow license
Parameters
- borrowed_until (str): borrow until date
- os_hostname (str, optional): os hostname. Defaults to None.
- ip_local (str, optional): ip local. Defaults to None.
- user_info (str, optional): user info. Defaults to None.
- license_id(int, optional):license id. Defaults to None.
fs_manager = FloatingManager(conf=conf)
license = fs_manager.borrow("2031-05-06T00:00:00Z")
# borrow can be also used within the License object
license.floating_borrow("2031-05-06T00:00:00Z")
Return(License): License object
is_online
Checks if floating server is online
Parameters
- throw_e (bool, optional): True if you want raise exception. Defaults to False.
fs_manager = FloatingManager(conf=conf)
response = fs_manager.is_online()
Raises:
- ex: Exception
Return(bool): True if server is online, otherwise False
fetch_licenses
List licenses
Parameters
- product (str,optional): product short code filter
fs_manager = FloatingManager(conf=conf)
response = fs_manager.fetch_licenses(product="test")
print(response)
Return(dict): Response
Methods supported inside License object
License consumptions, feature consumptions, register feature, release feature are supported within License object for Floating Server
License
LicenseSpring SDK Source Code License (LSSCL)
Preamble: This LicenseSpring SDK Source Code License (LSSCL) governs the use, distribution, and modification of the source code for this LicenseSpring SDKs. This SDK is designed to facilitate the integration of LicenseSpring's license management service into your applications. By accessing, using, or modifying the SDK, you agree to the terms and conditions set forth in this license.
-
Permissions:
- You are permitted to access, read, and modify the source code of this LicenseSpring SDK.
- You may create derivative works that include this SDK, provided all derivative works are used solely as part of the LicenseSpring service.
-
Distribution:
- You may distribute the original or modified versions of software that incorporates the SDK, provided that all distributed versions retain this LSSCL license.
- Distributed versions, including modifications, must be used to facilitate the integration of LicenseSpring’s service and may not be:
- Provided as part of a hosted or cloud-based service that allows others to access the SDK’s functionality without interacting directly with the LicenseSpring service.
- Integrated into other services which compete with or do not use the LicenseSpring service.
-
Usage Restrictions:
- The SDK, in its original or modified form, may only be used as part of the LicenseSpring service, whether on a free or paid plan.
- You are prohibited from using the SDK independently or as part of any service that does not interact with the LicenseSpring service.
-
Prohibited Actions:
- You may not circumvent or disable any technical measures that control access to the SDK.
- You must not remove, alter, or obscure any license notices, copyright notices, or other proprietary notices from the SDK.
-
Termination:
- Any violation of these terms will result in the automatic termination of your rights under this license.
- Upon termination, you must cease all use and distribution of the SDK and destroy all copies in your possession.
-
Disclaimer of Warranty and Liability:
THE SOFTWARE IS PROVIDED "AS IS" AND LICENSESPRING DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. LICENSESPRING SHALL NOT BE LIABLE FOR ANY DAMAGES ARISING OUT OF OR RELATED TO THE USE OR PERFORMANCE OF THE SOFTWARE.
Copyright 2024 Cense Data Inc DBA LicenseSpring Contact: support@licensespring.com
Dependency licenses
| Name | Version | License | URL |
|---|---|---|---|
| certifi | 25.1.0 | Mozilla Public License 2.0 (MPL 2.0) | https://github.com/certifi/python-certifi |
| charset-normalizer | 3.4.1 | MIT License | https://github.com/Ousret/charset_normalizer |
| idna | 3.10 | BSD License | https://github.com/kjd/idna |
| pycryptodome | 3.21.0 | Apache Software License; BSD License; Public Domain | https://www.pycryptodome.org |
| requests | 2.32.3 | Apache Software License | https://requests.readthedocs.io |
| urllib3 | 2.3.0 | MIT License | https://github.com/urllib3/urllib3/blob/main/CHANGES.rst |
| winregistry | 2.1.0 | UNKNOWN | https://github.com/shpaker/winregistry |
Metadata
Release files for licensespring 4.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| licensespring-4.0.0.tar.gz | 85.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| licensespring-4.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 169.9 kB
Release files / licensespring-4.0.0.tar.gz
| Download URL | licensespring-4.0.0.tar.gz |
|---|---|
| Size | 85.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
50add3aa4d24c8b717198e8a6bb65493fca0c916f3e51ef5e614fe37fe0d2fa4
|
|
BLAKE2b-256 checksum How to use checksums |
3bcbea68678f6f1cf9459839b669aa895b0f7fa0bdd31893e26d9eaf18420ef4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.2 CPython/3.9.21 Darwin/25.1.0
|
Release files / licensespring-4.0.0-py3-none-any.whl
| Download URL | licensespring-4.0.0-py3-none-any.whl |
|---|---|
| Size | 84.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
653e329bd5a59caf25f6e4825c3120cf64b4298db893be9e1ac6603979ae63f8
|
|
BLAKE2b-256 checksum How to use checksums |
8662885e09daf0f09155738aa5c2384cae15f8e42fe7dd30c5744c291b2b9567
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.2 CPython/3.9.21 Darwin/25.1.0
|