get system cpu usage in python

You can use the psutil library in Python to get the system CPU usage.

Here's an example code block:

main.py
import psutil

# get CPU usage
cpu_usage = psutil.cpu_percent()

print(f"CPU usage: {cpu_usage}%")
99 chars
7 lines

The psutil.cpu_percent() function returns a float representing the current CPU utilization as a percentage.

related categories

gistlibby LogSnag