How can I set a parent of an object in the BGE using python?
Simple:

import bge

cont = bge.logic.getCurrentController()
own = cont.owner
scene = own.scene

objA = scene.objects["objA"]
objB = scene.objects["objB"]

objB.setParent(objA)


setParent(parent, compound=True, ghost=True)

Sets this object’s parent. Control the shape status with the optional
compound and ghost parameters. In that case you can control if it should be ghost or not.


parent (KX_GameObject) – new parent object.
compound (boolean) – whether the shape should be added to the parent compound shape.


True: the object shape should be added to the parent compound shape.
False: the object should keep its individual shape.

ghost (boolean) – whether the object should be ghost while parented.


True: if the object should be made ghost while parented.
False: if the object should be solid while parented.



Source: Blender 2.79 API Documentation, bge.types.KX_GameObject section