How to create a Light with the Python API in Blender 2.92 I want to automatically create a point light source, but I can't get my blender script to work.
Im using the latest blender version 2.92.
After loading the default scene and loading my my obj model, I first delete the original light and then create a new light source:
# remove default light    
bpy.ops.object.select_by_type(type='LIGHT')
bpy.ops.object.delete(use_global=False)

# Create new light
lamp_data = bpy.data.lights.new(name=&quot;Lamp&quot;, type='POINT')
lamp_data.energy = 1000
lamp_object = bpy.data.objects.new(name=&quot;Lamp&quot;, object_data=lamp_data)
bpy.context.collection.objects.link(lamp_object)
lamp_object.location = (0, 0, 2)

In the Cycles viewport I can see that the light is illuminating my object, but when I render with F12 my object is just black, see the screenshot 
What am I missing here?
Recommended way is to use low level API calls. Create a new light data block using BlendDataLights.new(), create a new object using ObjectData.new(), link the light data block and add the object to the collection in context using CollectionObjects.link(object):
import bpy

# Create light datablock
light_data = bpy.data.lights.new(name=&quot;my-light-data&quot;, type='POINT')
light_data.energy = 100

# Create new object, pass the light data 
light_object = bpy.data.objects.new(name=&quot;my-light&quot;, object_data=light_data)

# Link object to collection in context
bpy.context.collection.objects.link(light_object)

# Change light position
light_object.location = (0, 0, 3)