In the SPEC tab of the Component Editor you'll configure your component, including loading dependencies. This article covers loading dependencies for Python components.


(For a primer on what it's like working with Python in the Exaptive Studio, check out the Python article in our Working with Your Favorite Technology section.)




Pip Dependencies


Python packages in PyPI can be installed by specifying them as "pip" dependencies in the component's spec file. When such dependencies are specified, the Exaptive system will try to  

create a new Docker container for the component containing the requested packages on spec save.


Specifying pip dependencies is equivalent to installing Python packages with the following command: 


pip install <dep1> <dep2> ...


where  <dep1>, <dep2>, etc are replaced by actual package names. Pleases see the example below on how to specify the names.


If the installation is successful, you can access the packages as you would in any Python script.


In your SPEC file: 

"dependencies": {
  "pip": [
    {"path": "requests"}
  ]
}

 

In your SCRIPT: 

import requests
def myinput(self):
  state = self.api.inputstate.export()
  ... 

 

With the release of version 4.6.2 of the studio,  pip dependencies can optionally have a version specifier.


{
  "path": "kitchen",
  "version": "<=1.1.5, >=1.1.1"
}


If no version is provided, the latest version is used. Since this was how the version was selected prior to this feature, this feature is backwards compatible. See pep 440 for the version specifier syntax: 

https://www.python.org/dev/peps/pep-0440/#version-specifiers

 

Apt Dependencies


Some Python packages can only be installed using apt. For these dependencies, the user must create a new list in the spec just for apt dependencies. Additionally, it is best to load apt dependencies prior to pip dependencies as the dependencies from apt are often required by libraries in pip. Below is an example with both pip and apt dependencies:


"dependencies": {
  "apt": [
    {
      "path": "libffi-dev"
    },
    {
      "path": "libssl-dev"
    }
  ],
  "pip": [
    {
      "path": "numpy"
    },
    {
      "path": "quandl"
    }
  ]
}