import bpy
curvedata = bpy.data.curves.new("my curve", type='CURVE')
curvedata.dimensions = '3D'
polyline = curvedata.splines.new('BEZIER')
polyline.bezier_points.add(2) # 制御点数ー1個
polyline.bezier_points[0].co = 0,0,0
polyline.bezier_points[0].handle_left = -1,0,0
polyline.bezier_points[0].handle_right = 1,0,0
polyline.bezier_points[1].co = 2,0,1
polyline.bezier_points[1].handle_left = 1,0,1
polyline.bezier_points[1].handle_right = 3,0,1
polyline.bezier_points[2].co = 4,0,0
polyline.bezier_points[2].handle_left = 3,0,0
polyline.bezier_points[2].handle_right = 5,0,0
obj = bpy.data.objects.new("my bezier", curvedata)
# 新しいCollrectionを作成
newCol = bpy.data.collections.new('Collection 1')
# 現在のシーンにコレクションをリンク
bpy.context.scene.collection.children.link(newCol)
# コレクションにオブジェクトをリンク
newCol.objects.link(obj)