Python version and library support

Python version

The Aruba Network Analytics Engine supports scripts written in Python 3.5.X.

Python modules available

In addition to the standard Python libraries, the following Python modules are provided with the Aruba Network Analytics Engine:

python3-misc

Usage example:

import os

For more information, see:

https://docs.python.org/3.5/library/os.html#miscellaneous-system-information

python3-pkgutil

Usage example:

from pkgutil import extend_path
...
__path__ = extend_path(__path__, __name__)
...

For more information, see:

https://docs.python.org/3.5/library/pkgutil.html

python3-importlib

Usage example:

import importlib

For more information, see:

https://docs.python.org/3.5/library/importlib.html

python3-datetime

Usage example:

import datetime

For more information, see:

https://docs.python.org/3.5/library/datetime.html

python3-enum

Usage example:

from enum import Enum
...
class Color(Enum):
...     red = 1
...     green = 2
...     blue = 3
...

For more information, see:

https://docs.python.org/3.5/library/enum.html

python3-compression

Usage examples:

import zlib
import gzip
import bz2
import lzma
import zipfile
import tarfile

For more information, see:

https://docs.python.org/3.5/library/archiving.html

python3-numbers

Usage example:

import numbers

For more information, see:

https://docs.python.org/3.5/library/numbers.html

python3-selectors

Usage example:

import selectors

For more information, see:

https://docs.python.org/3.5/library/selectors.html

python3-signal

Usage example:

import signal
...
# Set the signal handler and a 5-second alarm
signal.signal(signal.SIGALRM, handler)
signal.alarm(5)
...

For more information, see:

https://docs.python.org/3.5/library/signal.html

tar

Usage example:

import tarfile
...
tar = tarfile.open("sample.tar.gz")
tar.extractall()
tar.close()
...

For more information, see:

https://docs.python.org/3/library/tarfile.html

Third-party Python libraries available

The following third-party Python libraries are provided with the Aruba Network Analytics Engine framework. To use the library in a script, import the library.

requests

The requests library is an HTTP library for Python.

Usage example:

import requests
...
r = requests.get('https://api.github.com/events')
r.json()
...

In a Python NAE script, when you specify the URI of a local switch resource, do not specify the external IP address or host name. Instead, use the HTTP_ADDRESS global constant.

For example, instead of the following:

LOCAL_SYSTEM = '127.0.0.1:5577'
uri = 'http://' + LOCAL_SYSTEM + '/rest/v1/system/ports/1%2F1%2F5?attributes=link_state'  

Specify the following:

uri = HTTP_ADDRESS + '/rest/v1/system/ports/1%2F1%2F5?attributes=link_state'

For more information about the requests library, see:

http://docs.python-requests.org/en/master/

jsondiff

The jsondiff library is an MIT-licensed Python library used for comparing and patching JSON and JSON-like structures in Python.

Usage example:

import jsondiff
...
diff({'a': 1, 'b': 2}, {'b': 3, 'c': 4})

For more information, see:

https://github.com/ZoomerAnalytics/jsondiff