How to make object A a parent of object B via Blender's Python API? I have two objects each of them hold in a variable. Now I want to parent them so object A is the parent of object B. How can I do this using Blender's Python API? I know there is a parent_set operator in Blender but I don't know how to set up the selection in the scene via Python so I just have to call 

bpy.ops.object.parent_set(...)




It looks like there is a parent attribute on objects which I can use like

b.parent = a


How can I use that?
Avoid all the dancing around using bpy.ops and that setting selection and active. Most of those bpy.ops commands are meant to be called by the UI once a user clicks a ' parent to x ' button , etc. 

You are on the right path by using the .parent  attribute. All you really need are the names or references to the objects and you can parent much, much simpler.

import bpy

objects = bpy.data.objects
a = objects['Cube']
b = objects['Cube.001']
b.parent = a


There are times using a bpy.ops is a reasonable solution, but in this case the lower level solution of using b.parent = a is functionally equivalent and fewer lines of code. 

Edit

In the comments of this answer we discuss how to decide when to use a member of bpy.ops, but CoDEmanX has a fine clarification here