How to hook 2 points of a Bézier on 2 different object? I have a bezier already drawn and positioned, the ends coincide with 2 distinct objects.
Suppose it is cube1 and cube2, the objects are already in the scene, so I would like to link the points of the bezier (2 vertices only) first cube1 and then cube2

import bpy

cube1= bpy.data.objects['Cube1']
cube2= bpy.data.objects['Cube2']
bezier = bpy.data.objects['BezierCurve']


The example is to point out that the objects are already drawn in the correct position of the scene, I don't have to change anything, I just have to connect the bezier to these 2 objects
That can be something like this:

import bpy

cube1= bpy.data.objects['Cube1']
cube2= bpy.data.objects['Cube2']
bezier = bpy.data.objects['BezierCurve']

hook = bezier.modifiers.new( name = "Hook-" + cube1.name, type = 'HOOK' )
hook.object = cube1
hook.vertex_indices_set( [0, 1, 2] )

hook = bezier.modifiers.new( name = "Hook-" + cube2.name, type = 'HOOK' )
hook.object = cube2
hook.vertex_indices_set( [3, 4, 5] )


The tricky part is you have to indicate each element of the control points you want to hook. So the hook vertex indices are triplets.

I don't think you can hook control point handles individually, but that may depend of the curve type or the control points mode and have not tested all possibilities.