Skip to content

Instantly share code, notes, and snippets.

@dnck
Created October 24, 2019 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnck/0259f27715be40544f134cdee377176d to your computer and use it in GitHub Desktop.
Save dnck/0259f27715be40544f134cdee377176d to your computer and use it in GitHub Desktop.
A tutorial for gephistreamer
# coding: utf-8
# # Basic import
from gephistreamer import graph
from gephistreamer import streamer
# # Creating a streamer
# We use a websocket to connect the client to the server.
# The websocket defaults are localhost:8080 and workspace1. The server should be running in a Workspace with the name, "helix". So, make sure you change the workspace name according to your needs.
# Everything that is done here in Python can also be acheived through curl commands, but that is a bit slower.
stream = streamer.Streamer(streamer.GephiWS(hostname="localhost", port=8080, workspace="helix"))
# # Create a node with some custom properties and add it to the graph
node0 = graph.Node("0",size=50)
node0.color_hex(255, 0, 0)
stream.add_node(node0)
node1 = graph.Node("1",size=50)
node1.color_hex(0, 255, 0)
stream.add_node(node1)
# # Add a directed edge between the two nodes
edge_01 = graph.Edge(node0, node1, directed=True)
stream.add_edge(edge_01)
# # Update properties
# If a node already exists, then we can update its properties:
node0 = graph.Node("1",size=50)
node0.color_hex(0, 0, 255)
stream.change_node(node0)
# However, if a node already exists, then we can't update properties by attempting to add it again with different properties:
node0 = graph.Node("1",size=50)
node0.color_hex(0, 255, 0)
stream.add_node(node0)
# If you have a list of nodes, you can add them all in one go:
node_list = [graph.Node(str(i),size=50) for i in range(3, 100)]
stream.add_node(*node_list)
# This works for other methods as well:
node_list = [graph.Node(str(i), red=0, green=1, blue=0, size=50) for i in range(3, 100)]
stream.change_node(*node_list)
node_list = [graph.Node(str(i), red=0, green=1, blue=0, size=50) for i in range(3, 100)]
stream.delete_node(*node_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment