The documentation set for this product strives to use bias-free language. For the purposes of this documentation set, bias-free is defined as language that does not imply discrimination based on age, disability, gender, racial identity, ethnic identity, sexual orientation, socioeconomic status, and intersectionality. Exceptions may be present in the documentation due to language that is hardcoded in the user interfaces of the product software, language used based on RFP documentation, or language that is used by a referenced third-party product. Learn more about how Cisco is using Inclusive Language.
This chapter provides an overview and installation information needed to use the Python application programming interface (API) support on Cisco Nexus 3000 Series switches.
Python is an easy-to-learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.
The Python interpreter and the extensive standard library are freely available in source or binary form for all major platforms from the Python website:
The same site also distributes and points to many free third-party Python modules, programs and tools, and additional documentation.
The Cisco Nexus 3000 Series switches support all the features available in Python v2.7.2.
The Python scripting capability on the Cisco Nexus 3000 Series switches allows you to perform the following tasks:
The Python interpreter is available by default in the Cisco NX-OS software.You can invoke Python by entering the python command, and you can write scripts to access Cisco NX-OS APIs by importing the cisco.py module using the import cisco command.
You can install the third-party pure Python package by copying mypkg.tgz on your server. Perform the following steps to extract and install the third-party package:
Note You will be able to install the third-party packages using the easy_install command in future releases.
This section describes how to write and execute Python scripts by passing parameters and includes the following topics:
You can enter the Python shell by using the python command without any parameters.
You can execute a Python script by using the python filename [arg1, arg2, arg3, ...] command.
Embedded Event Manager (EEM) supports invocation of Python scripts based on events. Syslog for events can be passed to a Python script by using the variable $ command.
The following example shows EEM invoking a python script for an IF_DOWN event.
Every time you make a change to the configuration script, ensure that you recalculate the MD5 checksum. The following example shows the script to be run in a bash shell to recalculate the MD5 checksum: