bpy.ops.object.lamp_add not found I am trying to run some old script example which states
# Add a sun lamp above the grid.
bpy.ops.object.lamp_add(type='SUN', radius=1.0, location=(0.0, 0.0, extents * 0.667))

and it says
AttributeError: Calling operator &quot;bpy.ops.object.lamp_add&quot; error, could not be found
Error: Python script failed, check the message in the system console

How to do the same in modern Blender 2.91.0? How to find replacements for old constructs systematically?
Recommended way is to use low level API calls anyway. Create a new data block, create an object, link the data block and add the object to the collection in context:
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)