Python Fundamentals
SECTION
  • Introduction
  • Ansible and ACI
  • Dev/Ops
  • Cisco ACI API
  • Python Basics
  • ReST w/ Python Requests
  • Javascript
  • Web Application
  • Finished
  • References

For this section we are going to work in a different virtual environment than the one Ansible setup we previously created. This is very common practice amongst Python users. You might have a virtual environment that you setup specifically with one Ansible version, one Python version that you know works. You can then reference this base software version combination going forward, giving you confidence that you can use a base code of software going forward without having to update/fix.

Step 1 - Close All Open Ansible Tabs

To avoid confusion please close all the open file tabs you have open in the editor

Step 2 - Create new virtual environment in Python3

For this portion of the lab you are going to create a different Python virtual environment that is separate from the work that was done for Ansible.


pyenv virtualenv 3.10.13 requests


cd ~/ltrdcn-3225/requests

Setup local pyenv as we did before.


pyenv local requests

With the environment active, any Python packages are now install in the virtual environment directory that was specified in ~/envs and don't affect the system or any other application. This is very important as you could be developing various applications and you don't want to break another application by upgrading a requirement unnecesarily.

Step 3 - Upgrade PIP

You have to do this for every virtual environment that you build as the software and libraries in each is unique to that environment.


pip install --upgrade pip

Step 4 - Install wheel


pip install wheel

Step 5 - Install requests

The request library makes it possible to easily have Python make requests to a REST interface.


pip install requests

Step 6 - Install ptable

Ptable will help us with showing structured data from the ACI fabric in a way that is easier to read for humans.


pip install ptable

Step 7 - Install Pretty Print & Rich

Pprint will also help us with showing structured data from the ACI fabric in a way that is easier to read for humans.


pip install pprintpp rich