1#!/usr/bin/env python
2import psutil
3# gives a single float value
4psutil.cpu_percent()
5# gives an object with many fields
6psutil.virtual_memory()
7# you can convert that object to a dictionary
8dict(psutil.virtual_memory()._asdict())
1# Importing the library
2import psutil
3
4# Calling psutil.cpu_precent() for 4 seconds
5print('The CPU usage is: ', psutil.cpu_percent(4))
6