This guide will walk you through creating a simple Python application that gets the current version of the SmartPackager on your Linux desktop environment. Once this is working and verifies that your environment and project are set up correctly, the guide will walk you through the steps to create a protected package .yip file.
First, you will need to install Python 3 on your desktop.
Under a debian-based Linux desktop (such as Ubuntu) install Python 3 via:
sudo apt update
sudo apt install python3 python3-venv libglib2.0-0
The SDK needs Python 3.8 or later on Linux x86_64 (Ubuntu 22.04 or later).
Verify the version, output should be "3.x.x"
python3 -V
For other distributions, check your distribution's documentation
If you prefer, many Integrated Development Environments (IDE) support Python 3. This guide will utilize only the Linux command-line, rather than any IDE, for simplicity.
Next, you will need to obtain the PackageAPI .whl file.
Create a directory for the project ex. package_api_python_sdk
mkdir package_api_python_sdk
cd package_api_python_sdk
Create a Python virtual environment for the project and activate it. (Recent Ubuntu versions don't allow installing packages system-wide with pip.)
python3 -m venv .venv
source .venv/bin/activate
This adds (.venv) to the front of your shell prompt. The environment includes pip; check it with:
pip --version
If you have an old version of the Python PackageAPI SDK installed, uninstall PackageAPI SDK
pip uninstall package_api
Copy the .whl package file to the current directory
then install the PackageAPI Python .whl package
cp <path to .whl file> .
pip install package_api-<version>-cp38-abi3-linux_x86_64.whl
Verify package_api python SDK is installed
"package_api" should be in the output
pip list
To show package info
pip show package_api
Create a project python file and add this code.
For example
program.py
import package_api
try:
api = package_api.PackageAPI()
versionResult = api.getVersion()
print("version: " + versionResult)
except Exception as e:
print("Exception: " + str(e))
python3 ./program.py
If successful, the output will be
version: <version>
If successful, this verifies your environment and project script are configured correctly.
When program.py is run, it instantiates an instance of the PackageAPI class and assigns it to the variable api. Calling the class method getVersion() returns the version of SmartPackager whose package code the SDK contains. This isn't the version of the PackageAPI SDK; getSdkVersion() returns that.
Creating protected .yip packages requires a private key and a package JSON template file. Once created, only the holder of that private key (or Yaskawa) can change the package or read its contents with getJson. Its name, version, vendor and type can be read without the key. Anyone with the package file can install it, so don't put secrets in it.
To create a private key, edit the program.py file and replace the code with this:
program.py
import package_api
try:
api = package_api.PackageAPI()
newKeyFile = "private.key"
# create private key
newKeyResult = api.generateVendorKey(newKeyFile)
if newKeyResult:
print("Private key successfully created.")
else:
print("Failed to create private key.")
except Exception as e:
print("Exception: " + str(e))
python3 ./program.py
The output should be:
Private key successfully created.
The private key will be written to the file "private.key". If an exception occurs, it will be caught and the cause will be written to output.
All of the method definitions for the Python PackageAPI SDK are located at the Python PackageAPI SDK Reference
In order to create a package, you must use a .json file that describes the package. The documentation for the package json format is here: Install Package Json Format
Once you have created your private key file and package template .json file, you can create a protected package .yip file.
Create a new Python script or edit the existing one, and replace the code with the following.
The following code assumes:
program.py
import package_api
try:
api = package_api.PackageAPI()
newPkgFile = "protected_pkg.yip"
pkgTemplateFile = "pkg_template.json"
archiveDir = "ArchiveDir"
privateKey = "private.key"
pkgVariables = ""
# create protected package
newPkgResult = api.createProtectedPackage(newPkgFile,
pkgTemplateFile,
archiveDir,
privateKey,
pkgVariables)
if newPkgResult:
print("Protected package successfully created.")
else:
print("Failed to create protected package: " + api.getLastError())
except Exception as e:
print("Exception: " + str(e))
python3 ./program.py
If successful, the output will be:
Protected package successfully created.
If an exception occurs, it will be caught and the cause will be written to output.