Layer animation in Blender 2.5 using Python API

To answer my own initial question:

You can use the keyframe_insert-method of the StructRNA you want to animate to insert a keyframe for the current frame. An example:

sphere = bpy.data.objects['Sphere']
scene = bpy.data.scenes[0]

def layer_set(frame, layer):
    # Move to the correct frame
    scene.set_frame(frame)
    # Set the objects visibility in the layer
    sphere.layers[1] = layer
    # Set the current status of the layers property at index 1 as a keyframe
    # for properties that have no index, the 2nd argument can be omitted
    sphere.keyframe_insert("layers", 1)

layer_set(1, False)
layer_set(10, True)
layer_set(20, False)

Test-dr, I am still interested in this ‘Restrict Render ’ property, as it seems to be the proper way to do this kind of animation.