How to completely remove all loaded data from Blender?
2.79 or newer

Note, to avoid having to remove this extra data, you can start a new file with blank scene, objects..., eg:

bpy.ops.wm.read_factory_settings(use_empty=True)

Or...

bpy.ops.wm.read_homefile(use_empty=True)

Old Answer (useful for partially clearing)

This can be done by running 'Reset Factory Settings' operator (then clear the data).

The advantage with doing this is we only need to clear the default Cube, Camera &amp; Lamp. Since 'Reset Factory Settings' will clear everything else each time (images, packed data, curves.. etc).

import bpy

def reset_blend():
    bpy.ops.wm.read_factory_settings()

    for scene in bpy.data.scenes:
        for obj in scene.objects:
            scene.objects.unlink(obj)

    # only worry about data in the startup scene
    for bpy_data_iter in (
            bpy.data.objects,
            bpy.data.meshes,
            bpy.data.lamps,
            bpy.data.cameras,
    ):
        for id_data in bpy_data_iter:
            bpy_data_iter.remove(id_data)

reset_blend()


If you wanted to you could skip calling bpy.ops.wm.read_factory_settings(), but theres a possibility some other data was loaded (curves or lattice for eg) that you don't know about. The clearing function could be extended to test for all possible data, but loading factory settings is an easier way to ensure you didn't miss some.