How to get a new mesh with modifiers applied using Blender Python API?
The option to apply modifiers is common for exporters included with Blender, so you can check how they do it.

Typically you can use the Object.to_mesh function, which returns a new mesh. You can manipulate it without distructively editing the user's data.

import bpy

# --- setup variables ---
context = bpy.context
scene = context.scene

# assume we have an object with geometry, nurbs, metaball, curves... _not_ a lamp
obj = context.object

# --- get a mesh from the object ---
apply_modifiers = True
settings = 'PREVIEW'
mesh = obj.to_mesh(scene, apply_modifiers, settings)

# ... do something with the mesh ...


It's important to remove the mesh, unless you have explicitly assigned it to an object. Otherwise it will be stored in Blender until the file is saved and loaded again.

# optionally remove it
bpy.data.meshes.remove(mesh)