How do I add an Fcurve Noise modifier with Python?
Using API methods takes away the need for context

Inserting a keyframe on a node, adds an fcurve to the scene nodetree action.

From the datapath, find the fcurve and add a new modifier of type 'NOISE' and set the appropriate settings.

For example

def execute(self, context):
    sc = context.scene
    tree = sc.node_tree

    gamma_node = tree.nodes.new(type="CompositorNodeGamma")
    gamma_node.inputs[1].default_value = 2
    gamma_node.inputs[1].keyframe_insert("default_value", frame= 30)
    gamma_node.select = True
    # datapath of newly added node
    data_path = f'nodes["{gamma_node.name}"].inputs[1].default_value'
    fcurves = tree.animation_data.action.fcurves
    # find the fcurve (should be there)
    fc = fcurves.find(data_path)
    if fc:
        # add the modifier and set props
        nm = fc.modifiers.new('NOISE')
        nm.strength = 2
        nm.depth = 1

    return {'FINISHED'}


Code assumes using python >= 3.6 with fstrings, else use older string formatting eg

data_path = 'nodes["%s"].inputs[1].default_value' % gamma_node.name



  For future reference, how would I find the Data path?


Two useful methods for this, firstly path_from_id(property)  See how it is similar to keyframe insert.  Some python console test code.  Autocomplete on the opening brace gives a run down

&gt;&gt;&gt; C.scene.node_tree.nodes['Gamma'].inputs[1].path_from_id(
path_from_id(property="")
.. method:: path_from_id(property="")
Returns the data path from the ID to this object (string).
:arg property: Optional property name which can be used if the path is
   to a property of this object.
:type property: string
:return: The path from :class:`bpy.types.bpy_struct.id_data`
   to this struct and property (when given).
:rtype: str


The result

&gt;&gt;&gt; C.scene.node_tree.nodes['Gamma'].inputs[1].path_from_id("default_value")
'nodes["Gamma"].inputs[1].default_value'


The id object the path is referenced from

&gt;&gt;&gt; C.scene.node_tree.nodes['Gamma'].inputs[1].id_data
bpy.data.scenes['Scene'].node_tree

&gt;&gt;&gt; 


Hence the action is on the node tree, and adding the datapath gives us the property keyframed or driven.