triangulate mesh in python
You could use the bmesh.ops.triangulate
See TextEditor &gt; Templates &gt; Python &gt; Bmesh simple edit mode for some of the boilerplate.
For any mesh in object mode.
# This example assumes we have a mesh in object mode.

import bpy
import bmesh

def triangulate_object(obj):
    me = obj.data
    # Get a BMesh representation
    bm = bmesh.new()
    bm.from_mesh(me)

    bmesh.ops.triangulate(bm, faces=bm.faces[:])
    # V2.79 : bmesh.ops.triangulate(bm, faces=bm.faces[:], quad_method=0, ngon_method=0)

    # Finish up, write the bmesh back to the mesh
    bm.to_mesh(me)
    bm.free()

# Get the active object (could be any mesh object)
triangulate_object(bpy.context.active_object)

For any mesh in edit mode.
# This example assumes we have a mesh object in edit-mode

import bpy
import bmesh

def triangulate_edit_object(obj):
    me = obj.data
    # Get a BMesh representation
    bm = bmesh.from_edit_mesh(me)

    bmesh.ops.triangulate(bm, faces=bm.faces[:])
    # V2.79 : bmesh.ops.triangulate(bm, faces=bm.faces[:], quad_method=0, ngon_method=0)

    # Show the updates in the viewport
    # and recalculate n-gon tessellation.
    bmesh.update_edit_mesh(me, True)

# Get the edit mesh
triangulate_edit_object(bpy.context.edit_object)