How do I subdivide a cube via scripting?
Using BMesh.subdivide_edges(...)



Can use BMesh.subdivide_edges(...) with 3 cuts, and grid fill set to true.

import bpy
import bmesh
context = bpy.context
obj = context.edit_object
me = obj.data
bm = bmesh.from_edit_mesh(me)
bmesh.ops.subdivide_edges(bm,
        edges=bm.edges,
        use_grid_fill=True,
        cuts=3)
me.update()


There is an example in my answer here demonstrating how to use bmesh.ops.subdivide with a different number of cuts on each dimension.