I recently dived into Python Blender scripting, while reading the Blender API some Python script got me stuck, I couldn't understand it, I can make it work though, here is the code from Blender API,

# Create new object with our light datablock.
light_object = bpy.data.objects.new(name="New Light", object_data=light_data)

The line bpy.data.objects.new(), Why 'data' can be chained after bpy? I'm sure 'bpy' is the module name, is '.data' and '.object' a method returning 'self' or is it a class name?

The menu said the 'bpy.data' is type of 'bpy.types.BlendData', I can not wrap my head around for this Python syntax, can you shed some light on what type of each section of the code really is so I can use the right term to search the syntax

  • 3
    $\begingroup$ Hello, a small heads-up : If you want to maximize your chances to get some help here you either need to take a crash course on Python, or define more clearly what you intend to do with your scripting. Cheers $\endgroup$
    – Gorgious
    Mar 18, 2021 at 19:36

1 Answer 1


Although I don't understand what you're doing, I know that the approach you're doing throws an error. If you go to the default scripting widow, at the bottom left it shows all the API calls you have done so if you shift+a>light>point, it will show

bpy.ops.object.light_add(type='POINT', radius=1, align='WORLD', location=(0, 0, 0))

And sure enough, if we run it it will create a light.

  • 1
    $\begingroup$ If the line light_data = bpy.data.lights.new("Foo", 'POINT') is run before hand code in Q creates a point light $\endgroup$
    – batFINGER
    Mar 19, 2021 at 17:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .