The resource
module provides getrusage
which can give you the information you need, at least for Unix-like platforms.
Note that CPU usage as a percentage is always measured over a time interval. Essentially, it is the amount of time taken by your program doing something divided by the interval time.
For example, if your application takes 2 seconds of CPU time over a 5 second period, then it can be said to be using 40% of the CPU.
Note that this calculation, as simple as it seems, can get tricky when using a multiprocessor system. If your application uses 7 seconds of CPU time in 5 seconds of wall clock time on a two-processor system, do you say it is uses 140% or 70% CPU?
Update: As gimel mentions, the os.times
function also provides this information in a platform-independent way. The above calculation notes still apply, of course.