<｜begin▁of▁sentence｜>### Instruction:
How can you generate a Gephi graph streaming API event in NetworkX for adding an edge between two nodes with given source, target, and optional directedness and attributes?
### Response:
from networkx.readwrite.json_graph import node_link_data
import json
import networkx as nx

# Create a NetworkX graph
g = nx.Graph()
# Add nodes and edge
g.add_node(1)
g.add_node(2)
g.add_edge(1, 2)

# Generate Gephi Streaming API event for adding an edge
def get_add_edge_event(source, target, directed=False, attributes=None):
    edge_event = {
        'an': {
            source: {'label': 'Node ' + str(source)},
            target: {'label': 'Node ' + str(target)}
        },
        'ae': {
            str(source) + '_' + str(target): {
                'source': source,
                'target': target,
                'directed': directed,
                'attributes': attributes
            }
        }
    }
    return edge_event

# Using the function to create an add edge event
edge_event = get_add_edge_event(1, 2, directed=False)
print(json.dumps(edge_event, indent=2))
<|EOT|>
