Using a custom shape as bevel object
Found a solution here:
Possible to add a plane using vertices via Python?
just add this line:
bpy.ops.object.convert(target='CURVE', keep_original= False)
return myobject