Controling compositor by python
A simple code example:

# switch on nodes and get reference
bpy.context.scene.use_nodes = True
tree = bpy.context.scene.node_tree

# clear default nodes
for node in tree.nodes:
    tree.nodes.remove(node)

# create input image node
image_node = tree.nodes.new(type='CompositorNodeImage')
image_node.image = bpy.data.images['YOUR_IMAGE_NAME']
image_node.location = 0,0

# create output node
comp_node = tree.nodes.new('CompositorNodeComposite')   
comp_node.location = 400,0

# link nodes
links = tree.links
link = links.new(image_node.outputs[0], comp_node.inputs[0])


Here are node types you can create:
Nodes subclasses API

If you need anything more let me know.