Ignition Scripting API now available via pypi

In the past I have shared with this community the Ignition repo I maintain at GitHub:

And inspired by a comment made by @kgamble and someone’s fork, I created the ignition-api package available to anyone interested.

Currently I have only created releases for versions 8.0.17 (8.0 branch from the repo), 8.1.9, and 8.1.10 (main branch from the repo).

I recommend using Python 2.7.18, and to install you may use any of the following:

To get the latest and/or upgrade:

$ python2 -m pip install --upgrade ignition-api

Or to get a specific version:

$ python2 -m pip install ignition-api==8.0.17.post1

or

$ python2 -m pip install ignition-api==8.1.9

For the 7.9 branch I am relying on Python 2.5 (since Ignition relies on Jython 2.5.3), so pip doesn’t appear to work, but you may still do the following:

$ git clone --single-branch --branch 7.9 https://github.com/thecesrom/Ignition.git 7.9
$ cd 7.9
$ python2 setup.py install --record files.txt

Note: Starting with release 7.9.19 all you’d have to do is download the source code for its release, un[zip|tar] it and use the setup.py from each release.

The --record option is so you create a receipt of all installed files in case you want to uninstall it by running:

$ cat files.txt | xargs rm -rf

As for the jython branch, the process is somewhat similar to 7.9's but with certain distinctions.

Note: I recommend installing Jython with pip included to make it a lot easier to install/uninstall packages.

Starting with the 8.1.10-jython release, just run the following:

$ jython -m pip install https://github.com/thecesrom/Ignition/archive/refs/tags/v8.1.10-jython.zip
DEPRECATION: A future version of pip will drop support for Python 2.7.
Collecting https://github.com/thecesrom/Ignition/archive/refs/tags/v8.1.10-jython.zip
  Using cached https://github.com/thecesrom/Ignition/archive/refs/tags/v8.1.10-jython.zip
Installing collected packages: ignition-api-jython
  Running setup.py install for ignition-api-jython ... done
Successfully installed ignition-api-jython-8.1.10

Just replace v#.#.#-jython.zip using the latest stable version.

And to uninstall:

$ jython -m pip uninstall ignition-api -y

And that’s it.

Happy coding!

10 Likes

This has been tested using Python 2.7.18, 2.5.6, and Jython 2.7.1 and 2.7.2, as well as PyCharm. All of this was so it could also work on Visual Studio Code, but unfortunately it does not.

See here:

1 Like

If at some point jython -m pip install ignition-api-jython from PyPI works, I have also created that package.

Alternatively if you wish to install it, you may use the latest release from the jython branch.

For release 8.1.10-jython you would do the following:

$ jython -m pip install https://github.com/thecesrom/Ignition/archive/refs/tags/v8.1.10-jython.zip
Collecting https://github.com/thecesrom/Ignition/archive/refs/tags/v8.1.10-jython.zip
  Downloading https://github.com/thecesrom/Ignition/archive/refs/tags/v8.1.10-jython.zip
     \ 225kB 1.6MB/s
Installing collected packages: ignition-api-jython
  Running setup.py install for ignition-api-jython ... done
Successfully installed ignition-api-jython-8.1.10
$ jython -m pip list
Package             Version
------------------- -------
ignition-api-jython 8.1.10
pip                 19.1
setuptools          41.0.1

This will allow you to do something like:

$ jython
Jython 2.7.2 (v2.7.2:925a3cc3b49d, Mar 21 2020, 10:03:58)
[OpenJDK 64-Bit Server VM (Azul Systems, Inc.)] on java11.0.11
Type "help", "copyright", "credits" or "license" for more information.
>>> import system.gui
>>> system.gui.warningBox("This one is a warning.")

image

Just make sure you change the version number from the URL, i.e. v#.#.#-jython.zip to the latest. But note that the ignition-api-jython package is for version 8.1.10 onwards.

1 Like

An update.

After pip-installing ignition-api I am able to get code completion on Visual Studio Code, so I can mark the following feature request as implemented.

The following versions now include the com.inductiveautomation package, just consider that it is not a one-to-one implementation. I have only created the necessary code for some use cases.

Latest versions and how to install them:

8.1.10

$ python2 -m pip install ignition-api

8.0.17

$ python2 -m pip install ignition-api==8.0.17.post3

7.9.18

$ python2 -m pip install ignition-api==7.9.18.post2

Code completion works on PyCharm 2021.2.2 (also when running the code from its Python Console) and Visual Studio Code 1.60.2 for the following versions:
7.9.18 (from 7.9 branch)
8.0.17 (from 8.0 branch)
8.1.10 (from main branch)

As for 8.1.10-jython, Visual Studio Code does not appear to support Jython as an interpreter, and on PyCharm these are the features that work:
Code completion (a.k.a. intellisense)
Python Console (see: PY-44759, PY-50491)

And apparently Jython appears to struggle when trying to import anything under com.inductiveautomation.

So, considering all of the above, the jython branch, as fun as it was to work on it, will no longer be maintained. It will be kept until 8.1.11 is released just in case something or someone steps in.

3 Likes

How would I leverage this package to read memory tags from an ignition gateway?

You wouldn’t, that’s not its purpose. It’s a bunch of mocks that can be used when editing code in an editor with auto completion, so that mocks for Ignition’s system functions also auto complete.

Start a new topic about what you’re asking.

Ok understood. Thank you!

My new topic is Accessing Ignition tags from external micro service

Hi guys, can somebody guide me how to use this in the visual studio code, i have tried cloning the repo and i was able to see all those in my vs code editor and then i created a python file, but no auto completion or code execution is happening.
python version is 2.7.18
even for system function its showing to import
image
somebody please guide. Am i missing something, any configurations in the vs code editor?

Hello, @John_S1.

You should either install ignition-api on Python 2.7.18 or a virtual environment created with Python 2.7.18.

  1. Install virtualenv:

    python2 -m pip install virtualenv
    
  2. Create virtual environment:

    python2 -m virtualenv .venv
    
  3. Activate virtual environment:

    a. Linux/macOS

    source .venv/bin/activate
    

    b. Windows

    .\.venv\Scripts\Activate.ps1
    
  4. On Visual Studio Code, select ./.venv/bin/python as your project's interpreter.

  5. Install ignition-api:

    python -m pip install ignition-api
    
  6. Get code completion:

devcontainer.json all-in-one
{
	"name": "Ignition",
	"dockerComposeFile": [
		"docker-compose.yaml",
		"docker-compose.stack.yaml"
	],
	"service": "Ignition",
	"workspaceFolder": "/usr/local/bin/ignition", // /data”,
	"features": {
		"ghcr.io/rocker-org/devcontainer-features/apt-packages:1": {
			"upgradePackages": true,
			"packages": "build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev git ca-certificates"
		}
	},
	"postCreateCommand": "bash -c 'curl https://pyenv.run | bash && export PYENV_ROOT=\"$HOME/.pyenv\" && [[ -d $PYENV_ROOT/bin ]] && export PATH=\"$PYENV_ROOT/bin:$PATH\" && eval \"$(pyenv init -)\" && eval \"$(pyenv virtualenv-init -)\" && pyenv install 2.7.18 && pyenv global 2.7.18 && pip install ignition-api && pip install --upgrade pip'",
    "customizations": {
        "vscode": {
            "extensions": [
                "donjayamanne.python-extension-pack",
				"donjayamanne.git-extension-pack"
            ],
            "settings": {
				"python.autoComplete.extraPaths": [
					"/root/.pyenv/versions/2.7.18/lib/python2.7/site-packages/"
				],
				"python.analysis.extraPaths": [
					"/root/.pyenv/versions/2.7.18/lib/python2.7/site-packages/"
				]
            }
        }
    },
	"remoteUser": "root"
}

1 Like

For dev containers I use quay.io/ignition-devs/devcontainer-base, which uses quay.io/coatldev/six as base.

And devcontainer.json:

1 Like

Also have to import system