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.
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.
Package/Module |
Description |
Support |
Support |
||
---|---|---|---|---|---|
2.7 |
3.x |
2.7 |
3.x |
||
|
Determines the path to the appropriate platform-specific directories for application-specific user data. |
Y |
Y |
Y |
Y |
|
Library for parsing and serializing Abstract Syntax Notation One (ASN.1) structures. |
Y |
Y |
Y |
Y |
|
Python package that enables you to write classes without writing all the boilerplate code. |
– |
– |
– |
Y |
|
Python expression of finite-state machines. |
– |
– |
– |
Y |
|
Library for password hashing and storage. |
– |
– |
– |
Y |
|
C Foreign Function Interface for Python, which enables Python applications to interact with C code. |
Y |
Y |
Y |
Y |
|
Universal character encoding detector for Python 2 and 3. |
Y |
Y |
Y |
Y |
|
Library that provides symbolic constant support. |
– |
– |
– |
Y |
|
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 |
|
Provides cryptographic recipes and primitives in Python. |
Y |
Y |
Y |
Y |
|
Provides an interface for asynchronously executing callables. Python 3 includes this package as part of the standard library. |
Y |
Y |
Y |
Y |
|
Provides an implementation of ECDSA cryptography, which can be used to create key pairs, sign messages, and verify signatures. |
Y |
Y |
Y |
Y |
|
Python 3 includes this functionality as part of the standard library. |
Y |
Y |
Y |
Y |
|
New version of Twisted’s native RPC protocol. |
– |
– |
– |
Y |
|
Python 2 and Python 3 compatibility library. |
– |
– |
– |
Y |
|
Provides support for working with protocol buffers (protobuf). |
Y |
Y |
Y |
Y |
|
Python gRPC tools. |
Y |
Y |
Y |
Y |
|
Pure-Python implementation of immutable URLs. |
– |
– |
– |
Y |
|
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 |
|
Library for versioning Python projects. |
– |
– |
– |
Y |
|
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 |
|
Fast, secure, designer-friendly templating language for Python. For more information about Jinja2, see http://jinja.pocoo.org/docs/dev/. |
Y |
Y |
Y |
Y |
|
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 |
|
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 |
|
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 |
|
Provides the ability to escape and format an XML, HTML, or XHTML markup safe string. |
Y |
Y |
Y |
Y |
|
Facilitates client scripting and application development through the NETCONF protocol. For more information about |
Y |
Y |
Y |
Y |
|
Network address manipulation library that enables processing of Layer 2 and Layer 3 network addresses. |
Y |
Y |
Y |
Y |
|
Core utilities for Python packages. |
Y |
Y |
Y |
Y |
|
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 |
|
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:
|
Y |
Y |
Y |
Y |
|
Provides APIs for finding and managing Python package and version dependencies and accessing bundled files and resources. |
Y |
Y |
Y |
Y |
|
Library for retrieving information on running processes and system utilization (CPU, memory, disks, and processes). Note:
|
Y |
Y |
Y |
Y |
|
Extensible YANG validator and converter that enables the processing, validation, and conversion of YANG modules. Junos OS adds support for |
Y |
Y |
Y |
– |
|
Python implementation of Abstract Syntax Notation One (ASN.1) types and BER/CER/DER codecs (X.208). |
Y |
Y |
Y |
Y |
|
Collection of ASN.1 data structures expressed as Python classes. |
– |
– |
– |
Y |
|
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 |
|
Python binding to the Networking and Cryptography library (NaCl). |
– |
– |
– |
Y |
|
Python wrapper module around a subset of the OpenSSL library. |
– |
– |
– |
Y |
|
Provides an alternative approach to creating and executing simple grammars. |
Y |
Y |
Y |
Y |
|
Provides extensions to the datetime module. |
– |
– |
– |
Y |
|
Library that enables sending HTTP/1.1 requests using Python. |
Y |
Y |
Y |
Y |
|
Implementation of the SCP protocol for Paramiko that uses Paramiko transport to send and receive files via the SCP protocol. |
Y |
Y |
Y |
Y |
|
Module in the pySerial package that encapsulates the access for serial ports. |
Y |
Y |
Y |
Y |
|
Service identify verification for pyOpenSSL and cryptography. |
– |
– |
– |
Y |
|
Library designed to facilitate packaging Python projects. |
– |
Y |
– |
Y |
|
Python 2 and Python 3 compatibility library. |
Y |
Y |
Y |
Y |
|
Provides Python bindings for the Apache Thrift framework.
|
Y |
– |
– |
– |
|
Object-oriented state machine implementation. |
– |
– |
– |
Y |
|
Event-based framework for internet applications. |
– |
– |
– |
Y |
|
HTTP client for Python. |
Y |
Y |
Y |
Y |
|
Module in the PyYAML package that is used to serialize and deserialize data in YAML format. |
Y |
Y |
Y |
Y |
|
YAML loader and dumper for PyYAML that uses
|
– |
– |
– |
Y |
|
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.
Resource |
URL |
---|---|
Scapy website |
|
Scapy official documentation |
|
Scapy GitHub repository |
https://github.com/secdev/scapy |
Juniper Scapy GitHub repository and documentation |