Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 

Using Python Interactive Mode on Devices Running Junos OS

 

Different variants of Junos OS have different restrictions with respect to executing Python scripts on the device. The Junos OS with Enhanced Automation software image is a full-featured version of Junos OS that bundles additional automation tools with the image and disables Veriexec enforcement. On Junos OS variants that have Veriexec enforcement enabled, unsigned Python scripts must meet certain requirements before you can execute them on the device, and you can only execute the scripts using Python’s normal script mode in which scripts are run in the Python interpreter. By contrast, devices running Junos OS with Enhanced Automation, which are generally used in development environments, enable you to run unsigned Python scripts with fewer restrictions and also use Python interactive mode in the shell.

In addition, the Junos OS Evolved image runs natively on Linux, providing direct access to all the Linux utilities and operations, including Python and the Python libraries that are part of the base image. Thus devices running Junos OS Evolved enable you to run Python scripts and use Python in interactive mode in the Linux shell.

To invoke Python 2.7 or Python 3 in interactive mode on supported devices running Junos OS, enter the python or python3 command, respectively, at the shell prompt. Python 3 is available on devices running Junos OS Release 19.4R1 or later.

To start Python in interactive mode:

  1. Start the shell interface:
    user@host> start shell
  2. Enter the python or python3 command without any parameters:
    [vrf:none] user@host:~$ python3
Note

The Python interpreter is designated with the prompt >>> at the beginning of a line or ... to indicate the continuation of a line.