Package: licensespring
LicenseSpring Python LibraryThe LicenseSpring Python Library provides convenient access to the LicenseSpring API from
applications written in the Python language.InstallationInstalllicensespringlibrary:pip install licensespringRequires: Python >=3.7Hardware (Device) IDsThis library provides preconfigured hardware identity providers:HardwareIdProvider(default)PlatformIdProviderYou can set the desired hardware identity provider when initializing the APIClient:fromlicensespring.api.hardwareimportPlatformIdProviderapi_client=APIClient(api_key="_your_api_key_",shared_key="_your_shared_key_",hardware_id_provider=PlatformIdProvider)It also supports their customization and creation of your own hardware id provider.HardwareIdProviderUsesuuid.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 byHardwareIdProvider:classHardwareIdProvider:defget_id(self):returnstr(uuid.getnode())defget_os_ver(self):returnplatform.platform()defget_hostname(self):returnplatform.node()defget_ip(self):returnsocket.gethostbyname(self.get_hostname())defget_is_vm(self):returnFalsedefget_vm_info(self):returnNonedefget_mac_address(self):return":".join(("%012X"%uuid.getnode())[i:i+2]foriinrange(0,12,2))defget_request_id(self):returnstr(uuid.uuid4())PlatformIdProviderUsessys.platformand OS queries to find the raw GUID of the device.Extends theHardwareIdProviderand overwrites only theget_idmethod:classPlatformIdProvider(HardwareIdProvider):defget_id(self):id=Noneifsys.platform=='darwin':id=execute("ioreg -d2 -c IOPlatformExpertDevice | awk -F\\\"'/IOPlatformUUID/{print $(NF-1)}'")ifsys.platform=='win32'orsys.platform=='cygwin'orsys.platform=='msys':id=read_win_registry('HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography','MachineGuid')ifnotid:id=execute('wmic csproduct get uuid').split('\n')[2].strip()ifsys.platform.startswith('linux'):id=read_file('/var/lib/dbus/machine-id')ifnotid:id=read_file('/etc/machine-id')ifsys.platform.startswith('openbsd')orsys.platform.startswith('freebsd'):id=read_file('/etc/hostid')ifnotid:id=execute('kenv -q smbios.system.uuid')ifnotid:id=super().get_id()returnidCustomizationExtend any of the preconfigured hardware identity providers, overwrite the methods you want and provide it when initializing the APIClient:classCustomHardwareIdProvider(HardwareIdProvider):defget_id(self):return"_my_id_"api_client=APIClient(api_key="_your_api_key_",shared_key="_your_shared_key_",hardware_id_provider=CustomHardwareIdProvider)APIClient Usage ExamplesSet app versionimportlicensespringlicensespring.app_version="MyApp 1.0.0"Create APIClientfromlicensespring.apiimportAPIClientapi_client=APIClient(api_key="_your_api_key_",shared_key="_your_shared_key_")Activate key based licenseproduct="lkprod1"license_key="GPB7-279T-6MNK-CQLK"license_data=api_client.activate_license(product=product,license_key=license_key)print(license_data)Activate user based licenseproduct="uprod1"username="user1@email.com"password="nq64k1!@"license_data=api_client.activate_license(product=product,username=username,password=password)print(license_data)Deactivate key based licenseproduct="lkprod1"license_key="GPUB-J4PH-CGNK-C7LK"is_deactivated=api_client.deactivate_license(product=product,license_key=license_key)print(is_deactivated)Deactivate user based licenseproduct="uprod1"username="user1@email.com"password="nq64k1!@"license_data=api_client.deactivate_license(product=product,username=username,password=password)print(license_data)Check key based licenseproduct="lkprod1"license_key="GPBQ-DZCP-E9SK-CQLK"license_data=api_client.check_license(product=product,license_key=license_key)print(license_data)Check user based licenseproduct="uprod1"username="user2@email.com"password="1l48y#!b"license_data=api_client.check_license(product=product,username=username)print(license_data)Add consumptionproduct="lkprod1"license_key="GPSU-QTKQ-HSSK-C9LK"# Add 1 consumptionconsumption_data=api_client.add_consumption(product=product,license_key=license_key)# Add 3 consumptionsconsumption_data=api_client.add_consumption(product=product,license_key=license_key,consumptions=3)# Add 1 consumption, allow overages and define max overagesconsumption_data=api_client.add_consumption(product=product,license_key=license_key,allow_overages=True,max_overages=10)print(consumption_data)Add feature consumptionproduct="lkprod1"license_key="GPTJ-LSYZ-USEK-C8LK"feature="lkprod1cf1"# Add 1 consumptionfeature_consumption_data=api_client.add_feature_consumption(product=product,license_key=license_key,feature=feature)# Add 3 consumptionsfeature_consumption_data=api_client.add_feature_consumption(product=product,license_key=license_key,feature=feature,consumptions=3)print(feature_consumption_data)Trial keyproduct="lkprod2"trial_license_data=api_client.trial_key(product=product)print(trial_license_data)Product detailsproduct="lkprod1"product_data=api_client.product_details(product=product)print(product_data)Track device variablesproduct="lkprod1"license_key="GPUB-SZF9-AB2K-C7LK"variables={"variable_1_key":"variable_1_value","variable_2_key":"variable_2_value"}device_variables=api_client.track_device_variables(product=product,license_key=license_key,variables=variables)print(device_variables)Get device variablesproduct="lkprod1"license_key="GPUB-SZF9-AB2K-C7LK"device_variables=api_client.get_device_variables(product=product,license_key=license_key)print(device_variables)Floating borrowproduct="lkprod1"license_key="GPUC-NGWU-3NJK-C7LK"# Borrow for 2 hoursborrowed_until=(datetime.utcnow()+timedelta(hours=2)).isoformat()floating_borrow_data=api_client.floating_borrow(product=product,license_key=license_key,borrowed_until=borrowed_until)print(floating_borrow_data)Floating releaseproduct="lkprod1"license_key="GPUC-NGWU-3NJK-C7LK"is_released=api_client.floating_release(product=product,license_key=license_key)print(is_released)Change passwordusername="user4@email.com"password="_old_password_"new_password="_new_password_"is_password_changed=api_client.change_password(username=username,password=password,new_password=new_password)print(is_password_changed)Versionsproduct="lkprod1"license_key="GPB7-279T-6MNK-CQLK"# Get versions for all environmentsversions_data=api_client.versions(product=product,license_key=license_key)# Get versions for mac environmentmac_versions_data=api_client.versions(product=product,license_key=license_key,env="mac")print(versions_data)Installation fileproduct="lkprod1"license_key="GPB7-279T-6MNK-CQLK"# Get the latest installation fileinstallation_file_data=api_client.installation_file(product=product,license_key=license_key)# Get the latest installation file for linux environmentinstallation_file_data=api_client.installation_file(product=product,license_key=license_key,env="linux")# Get the latest installation file for version 1.0.0installation_file_data=api_client.installation_file(product=product,license_key=license_key,version="1.0.0")print(installation_file_data)Customer license usersproduct="uprod1"customer='c1@c.com'customer_license_users_data=api_client.customer_license_users(product=product,customer=customer)print(customer_license_users_data)SSO URLproduct="uprod1"customer_account_code="ccorp"sso_url_data=api_client.sso_url(product=product,customer_account_code=customer_account_code)print(sso_url_data)SSO URL withcoderesponse typeproduct="uprod1"customer_account_code="ccorp"sso_url_data=api_client.sso_url(product=product,customer_account_code=customer_account_code,response_type="code",)print(sso_url_data)Activate offlineproduct="lkprod1"license_key="GPY7-VHX9-MDSK-C3LK"# Generate data for offline activationactivate_offline_data=api_client.activate_offline_dump(product=product,license_key=license_key)# Write to filewithopen('activate_offline.req',mode='w')asf:print(activate_offline_data,file=f)# Activate offlinelicense_data=api_client.activate_offline(data=activate_offline_data)print(license_data)Activate offline load# Read from filewithopen('./ls_activation.lic')asfile:ls_activation_data=file.read()license_data=api_client.activate_offline_load(ls_activation_data)print(license_data)Deactivate offlineproduct="lkprod1"license_key="GPYC-X5J2-L5SK-C3LK"# Generate data for offline deactivationdeactivate_offline_data=api_client.deactivate_offline_dump(product=product,license_key=license_key)# Write to filewithopen('deactivate_offline.req',mode='w')asf:print(deactivate_offline_data,file=f)# Deactivate offlineis_deactivated=api_client.deactivate_offline(data=deactivate_offline_data)print(is_deactiavted)Key based license feature checkproduct="lkprod1"license_key="GPB7-279T-6MNK-CQLK"feature="lkprod1f1"license_feature_data=api_client.check_license_feature(product=product,feature=feature,license_key=license_key)print(license_feature_data)Key based license floating feature releaseproduct="lkprod1"license_key="GPB7-279T-6MNK-CQLK"feature="lkprod1f1"is_released=api_client.floating_feature_release(product=product,feature=feature,license_key=license_key)print(is_released)LicenseCopyright (C) 2023 by Cense Data Inc.,support@licensespring.comDependency licensesNameVersionLicenseURLcertifi2023.7.22Mozilla Public License 2.0 (MPL 2.0)https://github.com/certifi/python-certificharset-normalizer3.3.0MIT Licensehttps://github.com/Ousret/charset_normalizeridna3.4BSD Licensehttps://github.com/kjd/idnapycryptodome3.19.0Apache Software License; BSD License; Public Domainhttps://www.pycryptodome.orgrequests2.31.0Apache Software Licensehttps://requests.readthedocs.iourllib32.0.7MIT Licensehttps://github.com/urllib3/urllib3/blob/main/CHANGES.rstwinregistry1.1.1MIT Licensehttps://github.com/shpaker/winregistry