I've just completed a similar project. Here's what I had:
#allows reading csv files
#currentstep is a csvfile with directory ie "C:\myfile.csv"
with open(currentstep) as csvfile:
csvreader = csv.reader(csvfile, delimiter=',')
#skip header row
#for each row, set x,y,z coordinates
for row in csvreader:
vert = ( x,y,z )
#append vertice to list of vertices
vertsclone = list(verts)
INDEX ARRAY edge from a to b
averts = 
bverts = 
loops through vertices and connects them according to rule (rule = X & Y are equal)
currentvert = vertsclone.pop()
for vert in vertsclone:
#check if x and y are equal; if so, add one vertex to averts, the other to b vertices
if currentvert == vert and currentvert == vert:
take list averts and list bverts and create edges by linking them together in indexed list (ie vertex 1 links to vertex 8)
edges = list(zip(averts,bverts))
mesh = bpy.data.meshes.new("csv_input")
object = bpy.data.objects.new("csv_input",mesh)
create mesh data from python csv
#Verts are (x,y,z) Edges are 2-dimension lists of indices, ie (1,2); faces are n-dimension lists of vertices ie (1,2,3,4)
You can modify the above at the Create Mesh step with whatever your rule for create the edges. In your case, you'll likely just create a set of vertices, and connect them as you go in a square pattern.
All you need to remember is that an edge is defined by a list of vertex indices.
So with mesh.from_pydata(verts,edges,faces) you can import any type of mesh data. If you just add vertices, it'll only create those. If you only add vertex and edges, you'll only get that. If you do vertex and faces, edges will be generated for themselves.
mesh data for mesh.from_pydata
verts = [(1.3,3.2,4.2),(3.3,3.4,2.1),(3.3,3.8,3.6)]
edges = [(1,2),(2,3)]
faces = [(1,2,3)]