How to select all keyframes between two markers with Python
I would iterate through all the keyframes and check which frame they're on. That's the first number in the x.co vector. Then check that against start/end variables which you would get from markers (didn't include this code). If the frame is between start/end deselect, if outside of that then select it.

import bpy

obj = bpy.context.object             #active object
action = obj.animation_data.action   #current action

start = 20 #first marker variable
end = 80 #second marker variable

for i in action.fcurves:
    for x in i.keyframe_points:
        if x.co[0] &gt; start and x.co[0] &lt; end: #check greater than/less than marker frames
            x.select_control_point=False #deselect if in between markers
        else:
            x.select_control_point=True #select if outside of markers