Using a custom shape as bevel object

I discover blender and python API for blender. I would like to create celtics works with blender using python (for cnc works). I found a way to create a sine curve and use a Bezier circle as the profile to extrude it, but what I would like is to use a rectangular shape.

Here is where I am: And here is what I would like to have (I modified the profile manually): Do you have any advices for me : Bezier vs NURBE, how to add a rectangular shape as bevel shape ...

Here is my code:

import bpy
import math
from bpy import context, data, ops

R = 1 # bevel radius

curve = bpy.data.curves.new('sinepath', type='CURVE')
curve.dimensions = '3D'
curve.resolution_u = 1
spline = curve.splines.new('NURBS')

for x in range(0, 1440):
if ((x+90)//180)%2 == 1:
z = 0.5 * abs(math.sin(float(math.radians(x -90))))
else:
z = -0.5 * abs(math.sin(float(math.radians(x -90))))
# Add first point for start of Nurbs (needs extra point)
if x == 0:
spline.points[0].co = (x/(2*math.pi), y, z, 1)

spline.points[-1].co = (x/(2*math.pi), y,z,1)
print ("x: " + str(x) + " y: " + str(y) + " z: " + str(z))
spline.points[-1].co = (x/(2*math.pi), y, 0, 1)

curveObject = bpy.data.objects.new('sinepath', curve)

cross_section = bpy.context.active_object
curveObject.data.bevel_object = cross_section
curveObject.data.use_fill_caps = True
curveObject.data.bevel_mode = 'OBJECT'

curve2 = bpy.data.curves.new('sinepath', type='CURVE')
curve2.dimensions = '3D'
curve2.resolution_u = 1
spline2 = curve.splines.new('NURBS')

for x in range(0, 1440):
if ((x+90)//180)%2 == 1:
z = -0.5 * abs(math.sin(float(math.radians(x -90))))
else:
z = 0.5 * abs(math.sin(float(math.radians(x -90))))
# Add first point for start of Nurbs (needs extra point)
if x == 0:
spline2.points[0].co = (x/(2*math.pi), y, z, 1)

spline2.points[-1].co = (x/(2*math.pi), y,z,1)
print ("x: " + str(x) + " y: " + str(y) + " z: " + str(z))
spline2.points[-1].co = (x/(2*math.pi), y, 0, 1)

curveObject = bpy.data.objects.new('sinepath', curve)

curveObject.data.bevel_object = cross_section
curveObject.data.use_fill_caps = True
curveObject.data.bevel_mode = 'OBJECT'


bpy.ops.object.convert(target='CURVE', keep_original= False)