Connect scripting

    will be available in the upcoming Frequent Release


    Install Python version 3.7 or better. Confirm that Python is properly installed. The simplest way to test for a Python installation is to open a command prompt. Once a command prompt window opens, type python and press Enter. If Python is installed correctly, you should see output similar to what is shown below.

    Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
     Type "help", "copyright", "credits" or "license" for more information.

    If you receive a message like:

    Python is not recognized as an internal or external command, operable program or batch file.

    Python is either not installed correctly or the system variable path has not been set.

    Python library for Connect scripting can be downloaded from Chemaxon download pages with appropriate Connect version.
    connect_api library of same version as Connect is required to run Connect Python scripts. Python library can be installed by using pip install connect-api-*.tar.gz * Pip is a tool that installs packages, pip itself is a package that someone might want to install, if it is not a part of Python.

    (this part would be removed, it is for internal Usage)or by using pip install -e. in scripting directory of connect-backend sources.

    Usage and examples


    Follwoing basic workflow when using connect_api in Python script is:

    • Create DataApi
    • Open Session
    • Run query on new Session
    • Fetch data for some of the fields

    Simple example script bellow is written for Demo Project Pubchem Grid View :

    # Create api : api = DataApi('username', 'password')
    api = DataApi('admin', 'admin')
    # Open Session
    session = api.openViewSession(
      api.getViewByName('Pubchem grid view')
    # empty query to load all data into session
    # get values for some of the columns
    result = session.getData(['Mol weight', 'Structure', 'CdId', 'Acceptors'])

    Standalone using Jupyter Notebook

    Installing Jupyter using Anaconda and conda, follow the instructions provided here. From command prompt use pip3 install jupyter For more details visit Jupyer web

    • Example of usage this demo example will guide you step by step through Connect_api functionalities

    From Connect frontend

    To use connect_api for scripting Connect frontend you need to create subclass of ConnectScript first. This lets you react on user input and modify frontend state. ConnectScript is a Python script which can be called by Connect frontend and react on the the user actions like opne view, clicking, querying etc.

    Example of simple script:

    class SimpleScript(ConnectScript):
      def onLoad(self):
         self.response.showMessage('Hello World')

    For usage from Connect Frontend, this script needs to be saved in

    More examples can be found in examples directory.

    Developing Connect frontend scripts locally

    You can use DevelopmentConnectScriptContext to make development loop shorter by running frontend script locally without copying it to server.

    Basic workflow looks like this:

    • Open Connect in browser and do any scriptable action (ex. selection)
    • use Scripting dialog to copy serialized frontend event you want to run locally
    • copy current connect URL and construct DevelopmentConnectScriptContext
    • run your script using DevelopmentConnectScriptContext
    • copy result of script run and use Scripting tools in Connect to display it on scripting panel
    • remove DevelopmentConnectScriptContext and copy finished script to server

    Example script:

    class SimpleScript(ConnectScript):
      def onLoad(self):
         self.response.showMessage('Hello World')
      connectUrl="http://localhost:3002", # Connect backend location
      sessionUrl="http://localhost:3002/grid/6C6F63616C6462_213A0E201AB2EB5DA54552018904C869/6", # URL to parse Session out of
      # Event to process - captured using Connect Frontend scripting tool
      "viewId": "6C6F63616C6462_213A0E201AB2EB5DA54552018904C869",
      "eventType": "onSelectionChange",
      "params": {
        "selection": [