Deselecting all keyframes with Python
Deselect all keyframe points and handles

Helper method to deselect all fcurves and their keyframes and handles of an objects action.

import bpy


def deselect_all_keyframes(ob):
    ob.animation_data_create()
    action = ob.animation_data.action

    if action:
        # deselect all fcurves
        action.fcurves.foreach_set)
                "select",
                (False,) * len(action.fcurves),
                )
        # deselect all keyframes
        for fc in action.fcurves:
            for select in ("select_control_point",
                           "select_left_handle",
                           "select_right_handle",
                               ):
                fc.keyframe_points.foreach_set(
                        select, 
                        [False] * len(fc.keyframe_points)
                        )

# test call on context object                        
deselect_all_keyframes(bpy.context.object)