Finding things with the python console.
The scene has a world. context.scene.world
. When nodes are being used the object will have a node tree. world.node_tree
The tree has nodes. Consult the manual or the many questions / answers re nodes for more info.
Note: The properties space has a world member of context context.world
other spaces may not
Here is a simple example using the python console. C is a convenience variable C = bpy.context
>>> C.scene.world
bpy.data.worlds['World']
>>> C.scene.world.node_tree
bpy.data.node_groups['Shader Nodetree']
Here I've used autocomplete CtrlSpace to expand available options
>>> C.scene.world.node_tree.nodes['
Background']
Environment Texture']
World Output']
>>> C.scene.world.node_tree.nodes['Environment Texture'].image
bpy.data.images['Untitled']
See that the environment node has an associated image. Since I've simply added a blank untitled image it has no filepath. A loaded image will.
>>> env_img = C.scene.world.node_tree.nodes['Environment Texture'].image
>>> env_img.file
_format
path
path_from_user(
path_raw
>>> env_img.filepath
''
Adding an environment node, given you have a path to the image path
>>> world = C.scene.world
>>> world.use_nodes = True
>>> enode = C.scene.world.node_tree.nodes.new("ShaderNodeTexEnvironment")
>>> enode.image = bpy.data.images.load(path)
Related:
How to set a background using the cycles render engine with the API