can I get number of edges connected to a vertex
Boundary edges


  I essentially want to put a fence up around the edge of my object


IMO Simplest here to select edges that are boundaries, ie are connected to only one face. 

import bpy
import bmesh

ob = bpy.context.edit_object

me = ob.data
bm = bmesh.from_edit_mesh(me)

for e in bm.edges:
    e.select = e.is_boundary

bmesh.update_edit_mesh(me)


The vertex selection is implied by the edges.  .. which is why I could have used 

e.select_set(e.is_boundary)



  BMEdge.select_set(select):
  
  Set the selection. This is different from the select attribute
  because it updates the selection state of associated geometry.


Although in this case I'm of the belief that the verts of an edge are selected with the edge. So

verts = set(v for e in boundary_edges for v in e.verts)


will be same as selected verts.

v for v in bm.verts if v.select


Using the bmesh to extrude those edges.

Rather than selecting the edges, can instead feed them directly into bmesh operators. For the example below the vertices created as a result of extruding boundary edges are fed into transform operator, and moved up one in Z.


Result on 10 x 10 default grid

Notice newly created geometry added with bmesh is unselected by default.  Run both these scripts below in edit mode.

import bpy
import bmesh
from bmesh.types import BMVert
from mathutils import Matrix

ob = bpy.context.edit_object

me = ob.data
bm = bmesh.from_edit_mesh(me)
bmesh.ops.transform(
    bm,
    verts = [
            e for e in 
                bmesh.ops.extrude_edge_only(
                    bm,
                    edges=[e for e in bm.edges if e.is_boundary],
            )["geom"] 
            if isinstance(e, BMVert)
            ],
    matrix=Matrix.Translation((0, 0, 1)),
    )

bmesh.update_edit_mesh(me)