Is there a low level alternative for bpy.ops.object.origin_set()
Set the object location to the target location and translate the mesh vertices in the reverse direction (the negated vector of the difference between start location and target location of the origin = start minus target).

Note that Mesh.transform() is not supported in Edit Mode, you need to use a wrapped BMesh instead.

If you use blender 2.79 change bpy.context.scene.cursor.location to bpy.context.scene.cursor_location

import bpy
import bmesh
from mathutils import Matrix

ob = bpy.context.object
cursor_world_loc = bpy.context.scene.cursor.location
cursor_local_loc = ob.matrix_world.inverted() @ cursor_world_loc

mat = Matrix.Translation(-cursor_local_loc)

me = ob.data
if me.is_editmode:
    bm = bmesh.from_edit_mesh(me)
    bm.transform(mat)
    bmesh.update_edit_mesh(me, False, False)
else:
    me.transform(mat)

me.update()

ob.matrix_world.translation = cursor_world_loc