Running a script every frame automatically

I have a script that I want to run automatically for each frame rendered. This includes each motion blur pass.

Is this possible?

Thanks!

EDIT – SOLVED:

The bpy.app.handlers.frame_change_pre.append() function is what I was looking for.

Example of my usage:

import bpy

def RunPerFrame(scene):
    <PER FRAME STUFF IN HERE>
    
bpy.app.handlers.frame_change_pre.append(RunPerFrame)

Thanks for posting your solution too.