The Unicorn of Python Libraries

The Unicorn of Python Libraries

One project that I'm starting to use more and more is Rich. In short, Rich is a Python library for:

writing rich text (with colour and style) to the terminal and displaying advanced content such as tables, markdown, and syntax highlighted code.

... and I have to say, it does it very very well! But this is not all, Rich also includes a great feature - inspect(). Quite simply inspect generates a report on any Python object. Great for a quick form of documentation or debug aid!

Here's a quick example that allows you to see all the attributes configured for a Netmiko connectHandler.

$ pip3 install rich

>>> from rich import inspect
>>> inspect(netmiko_connection)
╭─────────────────────────────── <class 'netmiko.cisco.cisco_ios.CiscoIosSSH'> ───────────────────────────────╮
│ Cisco IOS SSH driver.                                                                                       │
│                                                                                                             │
│ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │
│ │ <netmiko.cisco.cisco_ios.CiscoIosSSH object at 0x7f4b90e43ac0>                                          │ │
│ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                             │
│               allow_agent = False                                                                           │
│         allow_auto_change = False                                                                           │
│             alt_host_keys = False                                                                           │
│              alt_key_file = ''                                                                              │
│         ansi_escape_codes = False                                                                           │
│              auth_timeout = None                                                                            │
│            banner_timeout = 15                                                                              │
│               base_prompt = 'ios-001'                                                                       │
│          blocking_timeout = 20                                                                              │
│              conn_timeout = 5                                                                               │
│               device_type = 'cisco_ios'                                                                     │
│                  encoding = 'ascii'                                                                         │
│                  fast_cli = False                                                                           │
│         global_cmd_verify = None                                                                            │
│       global_delay_factor = 1                                                                               │
│                      host = 'lab.packetflow.co.uk'                                                          │
│                 keepalive = 0                                                                               │
│                  key_file = None                                                                            │
│                key_policy = <paramiko.client.AutoAddPolicy object at 0x7f4b80dae610>                        │
│                passphrase = None                                                                            │
│                  password = 'abc'                                                                           │
│                      pkey = None                                                                            │
│                      port = 2101                                                                            │
│                  protocol = 'ssh'                                                                           │
│               remote_conn = None                                                                            │
│           remote_conn_pre = None                                                                            │
│           RESPONSE_RETURN = '\n'                                                                            │
│                    RETURN = '\n'                                                                            │
│                    secret = ''                                                                              │
│           serial_settings = {'port': 'COM1', 'baudrate': 9600, 'bytesize': 8, 'parity': 'N', 'stopbits': 1} │
│               session_log = None                                                                            │
│ session_log_record_writes = False                                                                           │
│           session_timeout = 60                                                                              │
│                      sock = None                                                                            │
│           ssh_config_file = None                                                                            │
│          system_host_keys = False                                                                           │
│             TELNET_RETURN = '\r\n'                                                                          │
│                   timeout = 100                                                                             │
│                  use_keys = False                                                                           │
│                  username = 'lab'                                                                           │
│                   verbose = False                                                                           │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Subscribe to our newsletter and stay updated.

Don't miss anything. Get all the latest posts delivered straight to your inbox.
Great! Check your inbox and click the link to confirm your subscription.
Error! Please enter a valid email address!