Jump to content
  • Using Python packages in Spotfire


    This article explains how to install and use Python packages in Spotfire as well as how and admin can manage the python packages in use in the organization by distributing  selected Python packages using the Spotfire Server's deployment mechanism. This provides an opportunity for better governance of what python packages that are used in the organization.

    Using Python and Python packages

    Spotfire Analyst now comes with a bundled Python engine, and a user can add and use Python packages as desired. In order to import a Python package, so that the functions provided by the package can be used in a Spotfire data function,  one can use the pip python feature or Spotfire's inbuilt Python Tools.

    To install packages using Spotfire's Python Tools, users can access the Python Tools via the Tools menu from the Spotfire analyst. Then click on the Package Management tab. From here one will see all the currently installed packages. New packages can be installed by searching for their name in the Available Packages input box and clicking Search. Once the search has been completed, select the desired library from the list below and click Install:

    image1.png.fab551e2f63dfc486231ed6c3328f8e6.png

    The selected package will then be installed (using pip) into the Python engine. Alternatively, packages can be installed using pip commands directly. For example, using a command prompt at the location of the Python interpreter, which is in the modules folder of the Spotfire installation, typically:

     [SPOTFIRE INSTALL DIR]\Modules\Python Interpreter_[VERSION]\python\python.exe
     

    At this location, you can use the Python utility pip for example to install the nltk package.

     >python.exe -m pip install nltk
     

    This is a convenient way for individual users to add the Python packages they need, whenever they need it.

    Governed Python package management

    While it is convenient for individual users to add the packages they like to use as outlined in the earlier section, a data science manager or administrator may be concerned about which packages are used in their organization and may want to standardize and harmonize package usage among the users. Spotfire makes it easier to ensure that all Python users use the same packages and the same versions of these packages since administrators or superusers can control which packages and versions of packages are automatically available to other users within their organization. This is achieved by embedding Python packages in Spotfire .spk files.  This means that the regular package deployment mechanism on the Spotfire server can be used to deploy Python packages to users; if needed, with group-level granularity. 

    To achieve this, Spotfire comes with a Python package called spotfire.zip which makes it possible to specify a set of Python packages to package into a .spk file. This is done using the pip utility and a requirements.txt configuration file, like this:

     

    image2.png.2ff4af42769fee9f20906e7d7f548648.png

     

    The file requirements.txt defines the Python packages to include in the myspk.spk file

    On the command line, use: 

     >>python.exe -m spotfire.spk packages --analyst myspk.spk requirements.txt
     

    Note: you may have to set the PYTHONPATH. Refer to the detailed documentation if needed.

    An administrator can then deploy the created .spk file on the relevant deployment areas of the Spotfire server, which means that the regular deployment mechanism of Spotfire will be used to push the packages to the users.

    See this video for an overview of the process to create a Spotfire .spk package containing the selected Python packages.:

     

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...