Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Overview of Python Modules on Junos Devices

The Python interpreter is included as part of the Junos operating system (Junos OS). Junos OS and Junos OS Evolved include many Python modules, packages, and libraries that can be used in Python applications including commit, event, op, and SNMP automation scripts; Juniper Extension Toolkit (JET) applications; and YANG action and translation scripts. Usage of a specific module depends on the permissions of the user who is executing it.

Python Module Upgrades

Table 1 outlines the general updates and affected platforms for each set of module upgrades in a specific release. To determine the initial release in which a certain platform supports a specific version of Python (2.7 or 3) for a given type of script, consult the Feature Explorer tool.

Table 1: Python Module Upgrades

Release

Description of Changes

Supported Platforms

Junos OS Release 18.1R1

Module upgrades for Python 2.7

MX240, MX480, MX960, and vMX routers

Junos OS Release 19.2R1

Module upgrades for Python 2.7

MX Series routers and QFX Series switches

Junos OS Release 19.4R1

Module upgrades for Python 2.7

Module additions for Python 3.x (commit, event, op, and SNMP scripts only)

ACX Series, MX Series, and PTX Series routers

EX Series and QFX Series switches

SRX Series Services Gateways

Junos OS Release 20.2R1

Module additions for Python 3.x

ACX Series, MX Series, and PTX Series routers

EX Series and QFX Series switches

SRX Series Services Gateways

Junos OS Evolved Release 21.2R1

Module additions for Python 3.x

PTX Series Routers

Installed Python Modules, Packages, and Libraries

Table 2 outlines the Python modules, packages, and libraries that are available in Junos OS and Junos OS Evolved for Python 2.7 and Python 3.

Table 2: Python Modules in Junos OS and Junos OS Evolved

Package/Module

Description

Support
on
Junos OS

Support
on
Junos OS
Evolved

2.7

3.x

2.7

3.x

appdirs

Determines the path to the appropriate platform-specific directories for application-specific user data.

Y

Y

Y

Y

asn1crypto

Library for parsing and serializing Abstract Syntax Notation One (ASN.1) structures.

Y

Y

Y

Y

attrs

Python package that enables you to write classes without writing all the boilerplate code.

Y

Automat

Python expression of finite-state machines.

Y

bcrypt

Library for password hashing and storage.

Y

cffi

C Foreign Function Interface for Python, which enables Python applications to interact with C code.

Y

Y

Y

Y

chardet

Universal character encoding detector for Python 2 and 3.

Y

Y

Y

Y

constantly

Library that provides symbolic constant support.

Y

Crypto

Collection of Python modules in the PyCrypto package that implement cryptographic algorithms and protocols. The modules provide various secure hash and encryption functions.

Y

Y

Y

Y

cryptography

Provides cryptographic recipes and primitives in Python.

Y

Y

Y

Y

concurrent.futures

Provides an interface for asynchronously executing callables.

Python 3 includes this package as part of the standard library.

Y

Y

Y

Y

ecdsa

Provides an implementation of ECDSA cryptography, which can be used to create key pairs, sign messages, and verify signatures.

Y

Y

Y

Y

enum

enum34 package, which provides support for enumerations.

Python 3 includes this functionality as part of the standard library.

Y

Y

Y

Y

foolscap

New version of Twisted’s native RPC protocol.

Y

future

Python 2 and Python 3 compatibility library.

Y

google.protobuf

Provides support for working with protocol buffers (protobuf).

Y

Y

Y

Y

grpcio

Python gRPC tools.

Y

Y

Y

Y

hyperlink

Pure-Python implementation of immutable URLs.

Y

idna

Provides support for the Internationalized Domain Names in Applications (IDNA) protocol, as defined in RFC 5891, Internationalized Domain Names in Applications (IDNA): Protocol.

Y

Y

Y

Y

incremental

Library for versioning Python projects.

Y

ipaddress

Provides capabilities to create, manipulate, and operate on IPv4 and IPv6 addresses.

Python 3 includes this module as part of the standard library.

Note:

Devices running Junos OS with upgraded FreeBSD support using IPv6 in Python scripts starting in Junos OS Release 19.3R1.

Y

Y

Y

Y

jinja2

Fast, secure, designer-friendly templating language for Python.

For more information about Jinja2, see http://jinja.pocoo.org/docs/dev/.

Y

Y

Y

Y

jnpr.junos (Junos PyEZ or junos-eznc)

Microframework for Python that enables you to automate devices running Junos OS. Junos PyEZ is designed to provide the capabilities that a user would have on the Junos OS command-line interface (CLI) in an environment built for automation tasks.

For more information, see Junos PyEZ.

Y

Y

Y

Y

jxmlease

Python module for converting XML to Python data structures and converting Python data structures to XML.

For more information, see https://jxmlease.readthedocs.io/.

Y

Y

Y

Y

lxml

XML processing library that combines the speed and XML feature completeness of the C libraries libxml2 and libxslt with the simplicity of a native Python API.

For more information, see http://lxml.de.

Y

Y

Y

Y

MarkupSafe

Provides the ability to escape and format an XML, HTML, or XHTML markup safe string.

Y

Y

Y

Y

ncclient

Facilitates client scripting and application development through the NETCONF protocol.

For more information about ncclient, including documentation for the external APIs, see http://ncclient.grnet.gr/.

Y

Y

Y

Y

netaddr

Network address manipulation library that enables processing of Layer 2 and Layer 3 network addresses.

Y

Y

Y

Y

packaging

Core utilities for Python packages.

Y

Y

Y

Y

paho.mqtt

Serves as a client class that enables applications to connect to a Message Queue Telemetry Transport (MQTT) broker to publish messages and to subscribe to topics and receive published messages.

Y

Y

Y

Y

paramiko

SSH2 protocol library that provides the ability to make SSH2 protocol-based connections. This module supports all major ciphers and hash methods for both client and server modes.

Note:

paramiko version 2.1.2 is only supported on devices running Junos OS with upgraded FreeBSD.

Y

Y

Y

Y

pkg_resources

Provides APIs for finding and managing Python package and version dependencies and accessing bundled files and resources.

Y

Y

Y

Y

psutil

Library for retrieving information on running processes and system utilization (CPU, memory, disks, and processes).

Note:

psutil is only supported on devices running Junos OS Evolved and devices running Junos OS with upgraded FreeBSD. Devices running Junos OS with upgraded FreeBSD only support a subset of psutil functions. For more information, see How to Use the psutil Module to Retrieve Process and System Information on Devices Running Junos OS

Y

Y

Y

Y

pyang

Extensible YANG validator and converter that enables the processing, validation, and conversion of YANG modules.

Junos OS adds support for pyang in Python 3 and removes support for pyang in Python 2.7 starting in Junos OS Release 20.2R1.

Y

Y

Y

pyasn1

Python implementation of Abstract Syntax Notation One (ASN.1) types and BER/CER/DER codecs (X.208).

Y

Y

Y

Y

pyasn1-modules

Collection of ASN.1 data structures expressed as Python classes.

Y

pycparser

Parser for the C language written in pure Python. The module can be integrated into applications that need to parse C source code.

Y

Y

Y

Y

PyNaCl

Python binding to the Networking and Cryptography library (NaCl).

Y

PyOpenSSL

Python wrapper module around a subset of the OpenSSL library.

Y

pyparsing

Provides an alternative approach to creating and executing simple grammars.

Y

Y

Y

Y

python-dateutil

Provides extensions to the datetime module.

Y

requests

Library that enables sending HTTP/1.1 requests using Python.

Y

Y

Y

Y

scp

Implementation of the SCP protocol for Paramiko that uses Paramiko transport to send and receive files via the SCP protocol.

Y

Y

Y

Y

serial

Module in the pySerial package that encapsulates the access for serial ports.

Y

Y

Y

Y

service-identity

Service identify verification for pyOpenSSL and cryptography.

Y

setuptools

Library designed to facilitate packaging Python projects.

Y

Y

six

Python 2 and Python 3 compatibility library.

Y

Y

Y

Y

thrift

Provides Python bindings for the Apache Thrift framework.

thrift is only supported for Python 2.7 and only on devices running Junos OS Release 19.3 and earlier.

Y

transitions

Object-oriented state machine implementation.

Y

twisted

Event-based framework for internet applications.

Y

urllib3

HTTP client for Python.

Y

Y

Y

Y

yaml

Module in the PyYAML package that is used to serialize and deserialize data in YAML format.

Y

Y

Y

Y

yamlordereddictloader

YAML loader and dumper for PyYAML that uses OrderedDict objects to retain the mapping order when loading or dumping a file.

Y

zope.interface

Package that enables you to specify interfaces for Python.

Y

Additional Python Libraries

Certain devices running Junos OS support a limited version of the Scapy Python library. Scapy is an interactive packet manipulation library that enables you to create, send, receive, and dissect network packets. Junos devices support a limited set of modified Scapy APIs.

On Junos OS, you can use Scapy to create, send, and receive IP packets, TCP segments, or UDP datagrams. Thus, Scapy can help gather information or troubleshoot issues in your network. For example, you can calculate the round-trip time to a specific host

Table 3 provides links to various Scapy resources. To use Scapy on supported Junos devices, you must install it as a JET application. See the Juniper README for installation options and instructions, information about supported Scapy functions, and usage examples.

Table 3: Scapy Resources

Resource

URL

Scapy website

https://scapy.net

Scapy official documentation

https://scapy.readthedocs.io/en/latest

Scapy GitHub repository

https://github.com/secdev/scapy

Juniper Scapy GitHub repository and documentation

https://github.com/Juniper/scapy

https://github.com/Juniper/scapy/blob/master/README.md