I can find a lot of examples about tools for creating a sky using the User Interface (https://docs.blender.org/manual/en/latest/render/shader_nodes/textures/sky.html), but the same cannot be said for the Python API. The only examples I found use the obsolete


Which does not exist anymore. Does anyone know how this can be replicated from Python?

  • $\begingroup$ I think so… I messed with material nodes a bit, so it shouldn’t be to different for the world. Try bpy.data.worlds[0].node_tree.nodes… $\endgroup$
    – TheLabCat
    May 19, 2021 at 1:52

1 Answer 1


Try this:

import bpy

sky_texture = bpy.context.scene.world.node_tree.nodes.new("ShaderNodeTexSky")
bg = bpy.context.scene.world.node_tree.nodes["Background"]
bpy.context.scene.world.node_tree.links.new(bg.inputs["Color"], sky_texture.outputs["Color"])

You can then tweak the options like this:

sky_texture.sky_type = 'HOSEK_WILKIE' # or 'PREETHAM'
sky_texture.turbidity = 2.0
sky_texture.ground_albedo = 0.4
sky_texture.sun_direction = mathutils.Vector((1.0, 0.0, 1.0))  # add `import mathutils` at the beginning of the script 
  • $\begingroup$ It works, thanks! $\endgroup$ May 19, 2021 at 8:15
  • $\begingroup$ Glad I could help! $\endgroup$ May 20, 2021 at 1:23

You must log in to answer this question.

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