Creating an SPK for Python Packages on the node manager

An installation of Spotfire Service for Python on the node manager includes a Python interpreter and a set of packages to enable using Python in Spotfire.

The package named "spotfire" 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.

Important: You must build a package for the operating system on which your Spotfire Server node manager is installed. You can build the SPK from either a Linux or a Windows computer running the node manager. This topic describes building the SPK using the 'spotfire' package supplied with download bundle. (You can find it in the zipped archive at python/spotfire-<version#>-py2.py3-none-any.whl.)
  • If you are building an SPK for Linux only, then the SPK is deployed to the node manager. The packages it contains are used by data functions in analyses accessed through a web browser by Business Author and Consumer users.
  • If you are building an SPK for Windows only, then the SPK can be deployed to the node manager, to other Spotfire Analyst users, or to both. Packages deployed to the node manager are used by data functions in analyses accessed through a web browser by Business Author and Consumer users. (Alternatively, you can build the SPK from an installation of Spotfire Analyst. For those details, see Creating an SPK for Python Packages from Spotfire Analyst on Windows.

The package builder relies on pip, the Python command-line application for Python package installation. The package builder 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.

Perform this task from a command prompt on the Linux or Windows computer where the node manager includes the installation of Spotfire Service for Python.

Prerequisites

  • You must have write access to the computer running the node manager where Spotfire Service for Python is installed.
  • 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
  • Linux servers only: You must first install the 'spotfire' package into the Python interpreter.

Procedure

  1. From the command line, type the following command.
    "%Python_Service_Home%/python/python" -m spotfire.spk packages  [--name "<package-name>"] [--analyst] <name.spk> <path-to>requirements.txt
    where "%Python_Service_Home% is the Python Service installation location. By default, this is usually /opt/tibco/tsnm/<server-version#>/nm/services/Python Service Linux-<installed-service-guid>
    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.whl by typing the following command:

    "%Python_Service_Home%/python/python" -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 Linux" for server packages.
    --analyst This option 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.
    "%Python_Service_Home%/python/python" -m spotfire.spk packages --name "my_pkgs.spk opt/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"}}
  2. Locate the SPK you created in the working directory where you ran the command.
  3. 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.