Show Menu
Cheatography

GraphSpace Python Client Cheat Sheet by

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

Import Statements

from graphs­pac­e_p­yth­on.a­pi.client import GraphSpace
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_­nod­e('a')
..., label='A', ...)
Label to display
..., popup=­'html text', ...)
Popup text
G.add_­edg­e('a', 'b')
..., direct­ed=­True, ...)
Directed edge
..., popup=­'html text', ...)
Popup text
G.set_­nam­e('My Sample Graph')
G.set_­tag­s([­'sa­mple'])

Add Node Style

G.add_­nod­e_s­tyl­e('a', shape=­'el­lipse')
..., 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_no­de_­style
command.

Add Edge Style

G.add_­edg­e_s­tyl­e('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_ed­ge_­style
command.

Post Graph to GraphSpace

gs = GraphS­pac­e('­uname', 'psswd')
graph = gs.pos­t_g­raph(G)
Post (new) graph to GraphSpace
graph = gs.upd­ate­_gr­aph(G)
Update (existing) graph to GraphSpace
gs.del­ete­_gr­aph­(gr­aph­=graph)
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.pub­lis­h_g­rap­h(g­rap­h=g­raph)
Make graph public
gs.unp­ubl­ish­_gr­aph­(gr­aph­=graph)
Make graph private

Groups

mygroup = GSGrou­p(n­ame='My group', descri­pti­on=­'sample group')
group = gs.pos­t_g­rou­p(m­ygroup)
Add group
group = gs.get­_gr­oup­(gr­oup­_na­me='My group')
Fetch group
gs.sha­re_­gra­ph(­gra­ph=­graph, group_­nam­e='My group')
Share graph with group
gs.uns­har­e_g­rap­h(g­rap­h=g­raph, group_­nam­e='My group')
Remove graph from group

Layouts

L = GSLayout()
L.set_­nod­e_p­osi­tio­n('a', y=38.5, x=67.3)
Set x and y coords
L.add_­nod­e_s­tyle()
,
L.add_­edg­e_s­tyle()
Add styles in layout
L.set_­nam­e('My Sample Layout')
Layout name
L.set_­is_­sha­red(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.
 

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