Is there a way to get the location of the starting position of a curve?
Well, I don't know how good of a solution this is, but as suggested by @batFINGER this worked for me.

if parent.type == 'CURVE':
    if parent.data.splines[0].type == 'BEZIER':
        curve = Matrix.Translation(parent.data.splines[0].bezier_points[0].co)
    else:    
        curve = Matrix.Translation(parent.data.splines[0].points[0].co)

    mat = parent.matrix_world @ curve

matdupe = obj.matrix_world.copy()

obj.parent = None
obj.matrix_world = matdupe
obj.parent = parent

if parent.type == 'CURVE':
    obj.matrix_basis = mat.inverted() @ obj.matrix_basis
else:
    obj.matrix_parent_inverse = parent.matrix_world.inverted()