Creating an SPK for Python Packages from Spotfire Analyst on Windows

An installation of Spotfire Analyst includes a Python interpreter and a set of packages to enable using Python in Spotfire.

One of these packages, spotfire.zip, provides tools for building SPKs to share Python packages with other data function authors in an organization, or to enable Spotfire Business Author and Consumer users to see Python-enabled analyses in a web browser. For more information about package workflow, see Package management for Spotfire Service for Python.

Important: You must build a package for the operating system on which your Spotfire Server node manager is installed. This topic describes building the SPK using the spotfire.zip package supplied with your Windows installation of Spotfire Analyst. If you are installing the SPK on a Linux node, see Creating an SPK for Python Packages on the node manager.

Spotfire Analyst relies on pip, the Python command-line application for Python package installation. Spotfire Analyst uses a requirements.txt file to specify the packages to include in your SPK.

Note: By default, the file requirements.txt searches the PyPI package site for the specified package and version.
  • To include a package from a different repository or in a local file path, in the requirements.txt file, use the option -i or --index-url, followed by the location URL.
    #example
    #
    mylib -i http://my.domain.org/lib/1.0.0/mylib/
  • To include a .whl package, in the requirements.txt file, provide the relative path to the package from the current working directory.
    #simple-example
    #
    ./my_path/my_package.whl
    packaging==1.0.0
Note: Avoid installing packages that are already included in the Spotfire Service for Python. Installing a different version of an included package can cause unexpected results. For a list of these packages, see Included Packages.

For more information about creating a requirements.txt file for your package list, see its documentation at the following location.

Python users perform this task from a command prompt on the Windows computer where Spotfire Analyst is installed.

Caution: An installation of Spotfire Analyst relies on the Python packages included in the installation. Removing any of these packages causes your Spotfire Analyst installation to not work with the included Python interpreter. See Included Packages for more information.

Prerequisites

  • You must have the appropriate Spotfire license for authoring data functions.
  • You must have created the file requirements.txt containing the list of packages to include in your SPK.
    The following example specifies these packages and specified versions from PyPI.
    #
    ####### example-requirements.txt #######
    #
    scipy == 1.3.3
    matplotlib == 3.1.2
    statsmodels == 0.10.2

Procedure

  1. At the command prompt, set the Python path (PYTHONPATH) to the directory where the Python package spotfire.zip is installed.
    set PYTHONPATH=%SPOTFIRE_HOME%\Modules\Core_<core-build-version>\python\spotfire.zip
    Note: For example purposes, we refer to the directory where Spotfire Analyst is installed as %SPOTFIRE_HOME%.
    The PYTHON_PATH environment variable is set to the directory where the spotfire.zip package is installed.
  2. From the command line, type the following command.
    "%SPOTFIRE_HOME/Modules/Python Interpreter_<version#>/python/python.exe" -m spotfire.spk packages  [--name "<package-name>"] [--analyst] <name.spk> <path-to>requirements.txt
    Note: Remember that the path to the Python interpreter has spaces in it, so you must quote the path string.
    Option Description
    spotfire.spk The package containing the Python code to download and bundle the needed packages specified in requirements.txt.
    Tip: From the command prompt, you can view help for the package spotfire.zip by typing the following command:

    "<path-to-python-interpreter>\python\python.exe" -m spotfire.spk packages --help

    packages The subcommand that creates the package bundle.
    --name A string that sets the internal name of the generated package (for deploying multiple SPK files).
    Note: If you do not specify the --name argument, then the package builder reverts to the package name that is embedded in the spotfire.spk stamp in the requirements file (located beneath "BuiltName"), to match the previous version of the package, or, if it is missing entirely, it reverts to "Python Packages Windows" for server packages.
    --analyst This argument specifies that the Spotfire Server should distribute the packages in the SPK to other Spotfire Analyst clients connected to the Spotfire Server.

    (If you do not use this option, then the packages are placed on the server for Spotfire Business Author and Consumer users who connect using the Spotfire Web Player.)

    name.spk The name of the SPK file that is created by this task.
    requirements.txt The full path to the file requirements.txt.
    Tip: Also call the command, passing in the same packages and using the --analyst flag, to create an SPK to distribute the same packages with other Spotfire Analyst users in your organization. Everyone should use the same packages and package versions.
    The following example creates an SPK named my_pkgs.spk, containing the packages specified in requirements.txt.
    "%SPOTFIRE_HOME%\Modules\Python Interpreter_3.7.5.0\python\python.exe" -m spotfire.spk packages --name "example-packages" my_pkgs.spk c:\files\requirements.txt
    The packages and all of their dependencies are written to the SPK named my-pkgs.spk in the current working directory where the command was run, and the version information is recorded in the file requirements.txt. For example:
    #
    ####### example-requirements.txt #######
    #
    scipy == 1.3.3
    matplotlib == 3.1.2
    statsmodels == 0.10.2
    
    ## spotfire.spk: {"BuiltBy":"3.7.5 (tags/v3.7.5:e09359112e, Nov  30 2019,
    ## spotfire.spk:  20:34:20) [MSC v.1916 64 bit (AMD64)]","BuiltAt":"Thu 
    ## spotfire.spk: Dec 12 15:41:32 2019","BuiltFile":"my-data.spk","BuiltN
    ## spotfire.spk: ame":"Python Packages","BuiltId":"b8b9e4ec-324d-4da1-bd
    ## spotfire.spk: 4b-6a3509c7877d","BuiltVersion":"1.0.0.0","BuiltPackage
    ## spotfire.spk: s":{"cycler":"0.10.0","kiwisolver":"1.1.0","matplotlib"
    ## spotfire.spk: :"3.1.2","numpy":"1.17.4","pandas":"0.25.3","patsy":"0.
    ## spotfire.spk: 5.1","pyparsing":"2.4.5","python-dateutil":"2.8.1","pyt
    ## spotfire.spk: z":"2019.3","scipy":"1.3.3","setuptools":"42.0.2","six"
    ## spotfire.spk: :"1.13.0","statsmodels":"0.10.2"}}
  3. Locate the SPK you created in the working directory where you ran the command.
  4. Deploy the SPK to the Spotfire Server.

Result

After the SPK is placed into the deployment area, the packages are deployed to the Spotfire Server. Business Author and Consumer users can see analyses that use the functions in the packages in a web browser. For an overview of the entire process, see Package management for Spotfire Service for Python.