Python: Create Polyline and Polyloop
Create a polyline. (btw, imposing pure bmesh requirements on this is probably arbitrary, and using from_pydata is just as good)

import bpy
import bmesh
from mathutils import Vector

scene = bpy.context.scene 
meshes = bpy.data.meshes
objects = bpy.data.objects

# generate polyline 

bm = bmesh.new()
verts = [bm.verts.new((0, 0, z)) for z in range(5)]

for i in range(len(verts)-1):
    bm.edges.new([verts[i], verts[i+1]])

me = meshes.new('placeholder_mesh')
mesh_obj = objects.new('polyline', me)

scene.objects.link(mesh_obj)

bm.to_mesh(me)
bm.free()


Run this on a polyline:

import bpy
import bmesh
from mathutils import Vector

# Get the active mesh
obj = bpy.context.edit_object
me = obj.data

# Get a BMesh representation
bm = bmesh.from_edit_mesh(me)

bmesh.ops.extrude_edge_only(bm, edges=bm.edges[:])
bmesh.ops.translate(bm, vec=Vector((0,1.2,0)), verts=[v for v in bm.verts if v.select])

bmesh.update_edit_mesh(me, True)


See TextEditor -> Templates -> Python -> Simple Bmesh (edit mode) for the templates.



It might just be simpler to construct the polygon loop from scratch using from_pydata. It really depends on the final use-case