Protect the export in Python
Save the example as report.py. Replace the product ID and trusted public keys from your console. Prepare two test licenses for the same product. Give only the first one the export feature.
import os
import sys
from pathlib import Path
from licentivo import Client
PRODUCT_ID = "YOUR_PRODUCT_ID"
TRUSTED_KEYS = {"YOUR_KEY_ID": "YOUR_PUBLIC_KEY"}
def main(args):
if len(args) != 1:
print("Usage: LicenseReport <output.csv>", file=sys.stderr)
return 64
output = Path(args[0])
try:
with Client.open_product(
PRODUCT_ID, TRUSTED_KEYS, os.getenv("LICENTIVO_LICENSE_KEY", "")
) as client:
client.run_feature(
"export", lambda: output.write_text("item,total\nreports,1\n", encoding="utf-8")
)
except Exception as error:
print(error, file=sys.stderr)
return 2
print(output)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))Build the Windows executable
Run these PowerShell commands on a Windows x64 build machine with Python 3.12. The dist folder contains the single executable to give the tester.
py -3.12 -m venv .venv
.\.venv\Scripts\python.exe -m pip install "licentivo-sdk==0.11.8" "PyInstaller==6.22.3"
.\.venv\Scripts\python.exe -m PyInstaller --clean --noconfirm --onefile --name LicenseReport report.pyActivate the packaged application
Copy just LicenseReport.exe into an empty folder on a Windows x64 test machine without Python. Run the commands there and enter the first test key at the hidden prompt. A successful run creates first.csv.
$key = Read-Host 'Test license key' -AsSecureString
try {
$env:LICENTIVO_LICENSE_KEY = [System.Net.NetworkCredential]::new('', $key).Password
.\LicenseReport.exe first.csv
$LASTEXITCODE
} finally {
Remove-Item Env:LICENTIVO_LICENSE_KEY -ErrorAction SilentlyContinue
$key.Dispose()
}
Test-Path -LiteralPath .\first.csvRestart under the same Windows account
Run the executable again after the key variable has been cleared. A new report confirms the SDK restored the credential saved under this Windows account.
.\LicenseReport.exe restart.csv
$LASTEXITCODE
Get-Content -LiteralPath .\restart.csvVerify a license without export permission
Switch to a fresh Windows user profile. Repeat the activation command with the second key and a new output name, denied.csv. Expect exit code 2 and no file. Use a fresh filename for each check.
The local Windows x64 build used CPython 3.12.10. Only the EXE was copied to an empty directory. It loaded Python from its own extraction directory, wrote reports on activation and restart, and returned 2 without a file for the license lacking export access.
# In the fresh profile, supply the second key.
$key = Read-Host 'Test license key' -AsSecureString
try {
$env:LICENTIVO_LICENSE_KEY = [System.Net.NetworkCredential]::new('', $key).Password
.\LicenseReport.exe denied.csv
$LASTEXITCODE
} finally {
Remove-Item Env:LICENTIVO_LICENSE_KEY -ErrorAction SilentlyContinue
$key.Dispose()
}
Test-Path -LiteralPath .\denied.csv