Show Menu

GraphSpace Python Client Cheat Sheet by

You need to have a username and password on GraphSpace: https://graphspace.org/
python     graph     visualization

Import Statements

from graphs­pac­e_p­yth­on.a­pi.client import GraphS­pace
from graphs­pac­e_p­yth­on.g­ra­phs.cl­ass­es.g­sgraph import GSGraph
from graphs­pac­e_p­yth­on.g­ra­phs.cl­ass­es.g­sgroup import GSGroup
from graphs­pac­e_p­yth­on.g­ra­phs.cl­ass­es.g­sl­ayout import GSLayout

Create a Graph

G = GSGraph()
G.add­_no­de(­'a')
..., label='A', ...)
Label to display
..., popup=­'html text', ...)
Popup text
G.add­_ed­ge('a', 'b')
..., direct­ed=­True, ...)
Directed edge
..., popup=­'html text', ...)
Popup text
G.set­_na­me('My Sample Graph')
G.set­_ta­gs(­['s­amp­le'])

Add Node Style

G.add­_no­de_­sty­le('a', shape=­'el­lip­se')
..., color=­'blue', ...)
Node color
..., color=­'#A­152B8', ...)
..., bubble­='b­lue', ...)
Bubble style
..., height=40, width=20, ...)
Custom size
..., style=­'da­shed', ...)
..., border­_co­lor­='red', ...)
Border color
..., border­_wi­dth=2, ...)
Border width
Arguments should be combined into one add_n­ode­_style command.

Add Edge Style

G.add­_ed­ge_­sty­le('a', 'b', edge_s­tyl­e='­dot­ted')
..., direct­ed=­True, ...)
Directed edge
..., color=­'#F­F5733', ...)
..., arrow_­sha­pe=­'tee', ...)
..., width=4, ...)
Edge width
..., color=­'ma­genta', ...)
Edge color
..., arrow_­fil­l='­hol­low', ...)
..., width=4, ...)
Edge width
Arguments should be combined into one add_e­dge­_style command.

Post Graph to GraphSpace

gs = GraphS­pac­e('­uname', 'psswd')
graph = gs.pos­t_g­rap­h(G)
Post (new) graph to GraphSpace
graph = gs.upd­ate­_gr­aph(G)
Update (existing) graph to GraphSpace
gs.de­let­e_g­rap­h(g­rap­h=g­raph)
Delete graph from GraphSpace
 

Update Graph if it Exists, Otherwise Post it

def post(G, gs):
  try:
    graph = gs.update_graph(G)
  except:
    graph = gs.post_graph(G)
  return graph

Fetch Posted Graph

graph = gs.get­­_g­r­a­ph­­(gr­­ap­h­_­na­­me='My Sample Graph')
graph = gs.get­­_g­r­a­ph­­(gr­­ap­h­_­id=­12345)
Fetch by graph id
graph.name
Name of graph
graph.id
ID of graph

Make Graph Public

gs.pu­bli­sh_­gra­ph(­gra­ph=­graph)
Make graph public
gs.un­pub­lis­h_g­rap­h(g­rap­h=g­raph)
Make graph private

Groups

mygroup = GSGrou­p(n­ame='My group', descri­pti­on=­'sample group')
group = gs.pos­t_g­rou­p(m­ygr­oup)
Add group
group = gs.get­_gr­oup­(gr­oup­_na­me='My group')
Fetch group
gs.sh­are­_gr­aph­(gr­aph­=graph, group_­nam­e='My group')
Share graph with group
gs.un­sha­re_­gra­ph(­gra­ph=­graph, group_­nam­e='My group')
Remove graph from group

Layouts

L = GSLayo­ut()
L.set­_no­de_­pos­iti­on('a', y=38.5, x=67.3)
Set x and y coords
L.add­_no­de_­sty­le(­)L.a­dd­_ed­ge_­sty­le()
Add styles in layout
L.set­_na­me('My Sample Layout')
Layout name
L.set­_is­_sh­are­d(1)
Visible to members who can see graph
layout = graphs­pac­e.p­ost­_gr­aph­_la­yout(L, graph=­graph)
Post (new) layout
layout = graphs­pac­e.g­et_­gra­ph_­lay­out­(la­you­t_n­ame='My Sample Layout', graph=­graph)
Fetch layout
layout1 = graphs­pac­e.u­pda­te_­gra­ph_­lay­out­(la­yout)
Update (existing) layout
Graphs usually have manual­ly-­det­ermined layouts from GraphS­pace, which are saved through the user interface.

Download the GraphSpace Python Client Cheat Sheet

2 Pages
//media.cheatography.com/storage/thumb/annaritz_graphspace-python-client.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets