Python Interface¶
The Python package allows to interact with the NxLib from Python.
Installation¶
The package requires the Ensenso SDK to be installed.
Installation from the Ensenso SDK¶
The installation of the Ensenso SDK includes wheels for the Python package, which can be found in $ENSENSO_INSTALL/development/python. To install the package into your Python environment run:
pip3 install --upgrade --force-reinstall --find-links "$ENSENSO_INSTALL/development/python" nxlib
pip3 install --upgrade --force-reinstall --find-links "$env:ENSENSO_INSTALL\development\python" nxlib
pip3 install --upgrade --force-reinstall --find-links "%ENSENSO_INSTALL%\development\python" nxlib
The --upgrade --force-reinstall flags ensure that the package is (re)installed even if a version of the nxlib package is already present in your Python environment. You can omit --force-reinstall in case of an upgrade to avoid reinstalling the transitive dependencies of the package.
Installation from PyPI¶
Alternatively, the Python package can also be installed from PyPI. For each version of the Ensenso SDK there is a corresponding version of the package and you have to make sure to install the correct version for the Ensenso SDK you installed.
pip3 install --upgrade nxlib==<Installed Ensenso SDK Version>
Getting started¶
After a successful installation you should be able to import the Python interface (e.g. in an interpreter session):
import nxlib
The Python interface package nxlib consists of the following modules:
nxlib.api- Wraps the global NxLib functionsnxlib.constants- Contains the NxLib constants provided by the corresponding SDK versionnxlib.item- Contains the NxLibItem class implementationnxlib.command- Contains the NxLibCommand class implementationnxlib.exception- Contains the NxLibException class implementationnxlib.context- Contains context managers which wrap API functionsnxlib.log- Contains NxLog class implementation
The classes implemented in the described modules can be imported directly from
the nxlib package without specifying the complete path via the
following shortcut:
# Standard import
from nxlib.item import NxLibItem,
from nxlib.command import NxLibCommand
from nxlib.exception import NxLibException
# Shortcut
from nxlib import NxLibItem, NxLibCommand, NxLibException
It is helpful and recommended to import the constants module since your
IDE will then know all the constants definitions and will on the one hand not display
any warnings and on the other hand provide code suggestions for you.
# Import all constants
from nxlib.constants import *
Usually import * should be avoided. In this case however, it is unlikely that
the constants defined by nxlib have the same name as other variables in
your project. Otherwise you will have to access them within a namespace like the
following:
# Import all constants with namespace
import nxlib.constants as consts
# Call them in your code with the defined namespace
consts.ITM_NXLIB_CONSTANT
To get further insight into how the Python interface works, see the provided Examples.