try something like this, but I can think of some cases it won’t work
import bpy
scn = bpy.context.scene
sel = bpy.context.selected_objects
for ob in sel:
scn.objects.active = ob
bpy.ops.nla.bake(frame_start=1, frame_end=250, step=1, only_selected=True, clear_consraints=False, bake_types={'OBJECT'})
all bake parameters are defaults and not really needed unless you change something
see also there is a typo in operator: ‘clear_consraints’ should be ‘clear_constraints’ I guess…