Show Menu

GraphSpace Python Client Cheat Sheet by

You need to have a username and password on GraphSpace:

Import Statements

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

Create a Graph

G = GSGraph()
..., 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')

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­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):
    graph = gs.update_graph(G)
    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
Name of graph
ID of graph

Make Graph Public

Make graph public
Make graph private


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­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


L = GSLayo­ut()
L.set­_no­de_­pos­iti­on('a', y=38.5, x=67.3)
Set x and y coords
Add styles in layout
L.set­_na­me('My Sample Layout')
Layout name
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.

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi


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