graphspace_python.api.endpoint package

Submodules

graphspace_python.api.endpoint.graphs module

class graphspace_python.api.endpoint.graphs.Graphs(client)[source]

Bases: object

Graphs endpoint class.

Provides methods for graph related operations such as saving, fetching, updating and deleting graphs on GraphSpace.

delete_graph(graph_name=None, graph_id=None, graph=None)[source]

Delete a graph from GraphSpace provided the graph_name, graph_id or the graph object itself.

Parameters:
  • graph_name (str, optional) – Name of the graph to be deleted. Defaults to None.
  • graph_id (int, optional) – ID of the graph to be deleted. Defaults to None.
  • graph (GSGraph or Graph, optional) – Object having graph details, such as name, graph_json, style_json, is_public, tags. Defaults to None.
Returns:

Success/Error Message from GraphSpace.

Return type:

str

Raises:
  • Exception – If both ‘graph_name’ and ‘graph_id’ are None and graph object has no ‘name’ or ‘id’ attribute; or if graph doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Deleting a graph by name:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Deleting a graph
>>> graphspace.delete_graph(graph_name='My Sample Graph')
u'Successfully deleted graph with id=65930'

Deleting a graph by id:

>>> graphspace.delete_graph(graph_id=65930)
u'Successfully deleted graph with id=65930'

Deleting a graph by passing graph object itself as param:

>>> graph = graphspace.get_graph(graph_name='My Sample Graph')
>>> graphspace.delete_graph(graph=graph)
u'Successfully deleted graph with id=65930'

Note

Refer to the tutorial for more about deleting graphs.

get_graph(graph_name=None, graph_id=None, owner_email=None)[source]

Get a graph with the given graph_name or graph_id.

Parameters:
  • graph_name (str, optional) – Name of the graph to be fetched. Defaults to None.
  • graph_id (int, optional) – ID of the graph to be fetched. Defaults to None.
  • owner_email (str, optional) – Email of the owner of the graph. Defaults to None.
Returns:

Graph object, if graph with the given ‘graph_name’ or ‘graph_id’ exists; otherwise None.

Return type:

Graph or None

Raises:
  • Exception – If both ‘graph_name’ and ‘graph_id’ are None.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Getting a graph by name:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Fetching a graph
>>> graph = graphspace.get_graph(graph_name='My Sample Graph')
>>> graph.get_name()
u'My Sample Graph'

Getting a graph by id:

>>> graph = graphspace.get_graph(graph_id=65930)
>>> graph.get_name()
u'My Sample Graph'

Note

Refer to the tutorial for more about fetching graphs.

get_my_graphs(tags=None, limit=20, offset=0)[source]

Get graphs created by the requesting user.

Parameters:
  • tags (List[str], optional) – Search for graphs with the given given list of tag names. In order to search for graphs with given tag as a substring, wrap the name of the tag with percentage symbol. For example, %xyz% will search for all graphs with ‘xyz’ in their tag names. Defaults to None.
  • offset (int, optional) – Offset the list of returned entities by this number. Defaults to 0.
  • limit (int, optional) – Number of entities to return. Defaults to 20.
Returns:

List of graphs owned by the requesting user.

Return type:

List[Graph]

Raises:

GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Getting your graphs:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Fetching my graphs
>>> graphs = graphspace.get_my_graphs(limit=5)
>>> graphs[0].get_name()
u'test'

Getting your graphs by tags:

>>> graphs = graphspace.get_my_graphs(tags=['Kegg-networks'], limit=5)
>>> graphs[0].get_name()
u'KEGG-Wnt-signaling-pathway'
get_public_graphs(tags=None, limit=20, offset=0)[source]

Get public graphs.

Parameters:
  • tags (List[str], optional) – Search for graphs with the given given list of tag names. In order to search for graphs with given tag as a substring, wrap the name of the tag with percentage symbol. For example, %xyz% will search for all graphs with ‘xyz’ in their tag names. Defaults to None.
  • offset (int, optional) – Offset the list of returned entities by this number. Defaults to 0.
  • limit (int, optional) – Number of entities to return. Defaults to 20.
Returns:

List of public graphs.

Return type:

List[Graph]

Raises:

GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Getting public graphs:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Fetching public graphs
>>> graphs = graphspace.get_public_graphs(limit=5)
>>> graphs[0].get_name()
u'Wnt-Pathway-Reconstruction'

Getting public graphs by tags:

>>> graphs = graphspace.get_public_graphs(tags=['Kegg-networks'], limit=5)
>>> graphs[0].get_name()
u'KEGG-Wnt-signaling-pathway-with-ranks'
get_shared_graphs(tags=None, limit=20, offset=0)[source]

Get graphs shared with the groups where requesting user is a member.

Parameters:
  • tags (List[str], optional) – Search for graphs with the given given list of tag names. In order to search for graphs with given tag as a substring, wrap the name of the tag with percentage symbol. For example, %xyz% will search for all graphs with ‘xyz’ in their tag names. Defaults to None.
  • offset (int, optional) – Offset the list of returned entities by this number. Defaults to 0.
  • limit (int, optional) – Number of entities to return. Defaults to 20.
Returns:

List of shared graphs.

Return type:

List[Graph]

Raises:

GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Getting shared graphs:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Fetching shared graphs
>>> graphs = graphspace.get_shared_graphs(limit=5)
>>> graphs[0].get_name()
u'KEGG-Wnt-signaling-pathway'

Getting shared graphs by tags:

>>> graphs = graphspace.get_shared_graphs(tags=['Kegg-networks'], limit=5)
>>> graphs[0].get_name()
u'KEGG-Wnt-signaling-pathway'
post_graph(graph)[source]

Posts NetworkX graph to the requesting users account on GraphSpace.

Parameters:graph (GSGraph or Graph) – Object having graph details, such as name, graph_json, style_json, is_public, tags.
Returns:Saved graph on GraphSpace.
Return type:Graph
Raises:GraphSpaceError – If error response is received from the GraphSpace API.

Example

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Creating a graph
>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> G.set_name('My Sample Graph')
>>> G.set_tags(['sample'])
>>> G.add_node('a', popup='sample node popup text', label='A')
>>> G.add_node('b', popup='sample node popup text', label='B')
>>> G.add_edge('a', 'b', directed=True, popup='sample edge popup')
>>> G.add_edge_style('a', 'b', directed=True, edge_style='dotted')
>>> # Saving graph on GraphSpace
>>> graphspace.post_graph(G)

Note

Refer to the tutorial for more about posting graphs.

publish_graph(graph_name=None, graph_id=None, graph=None)[source]

Makes a graph publicly viewable.

Parameters:
  • graph_name (str, optional) – Name of the graph. Defaults to None.
  • graph_id (int, optional) – ID of the graph. Defaults to None.
  • graph (GSGraph or Graph, optional) – Object having graph details, such as name, graph_json, style_json, is_public, tags. Defaults to None.
Returns:

Updated graph on GraphSpace.

Return type:

Graph

Raises:
  • Exception – If both ‘graph_name’ and ‘graph_id’ are None and graph object has no ‘name’ or ‘id’ attribute; or if graph doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Make graph public by name:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Publishing the graph
>>> graph = graphspace.publish_graph(graph_name='My Sample Graph')
>>> graph.get_is_public()
1

Make graph public by id:

>>> graph = graphspace.publish_graph(graph_id=65930)
>>> graph.get_is_public()
1

Make graph public by passing graph object itself as param:

>>> graph = graphspace.get_graph(graph_name='My Sample Graph')
>>> graphspace.publish_graph(graph=graph)

Note

Refer to the tutorial for more about making a graph public.

set_default_graph_layout(graph_name=None, graph_id=None, graph=None, layout_name=None, layout_id=None, layout=None)[source]

Set a default layout (provided the layout_name, layout_id or layout object) for a graph with given graph_name, graph_id or graph object itself.

Parameters:
  • graph_name (str, optional) – Name of the graph. Defaults to None.
  • graph_id (int, optional) – ID of the graph. Defaults to None.
  • graph (GSGraph or Graph, optional) – Object having graph details, such as name, graph_json, style_json, is_public, tags. Defaults to None.
  • layout_name (str, optional) – Name of the layout. Defaults to None.
  • layout_id (int, optional) – ID of the layout. Defaults to None.
  • layout (GSLayout or Layout) – Object having layout details, such as name, is_shared, style_json, positions_json.
Returns:

Updated graph on GraphSpace.

Return type:

Graph

Raises:
  • Exception – If both ‘layout_name’ and ‘layout_id’ are None and layout object has no ‘name’ or ‘id’ attribute; or if both ‘graph_name’ and ‘graph_id’ are None and neither graph object has ‘name’ or ‘id’ attribute nor layout object has ‘graph_id’ attribute; or if graph or layout doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Setting a default layout when graph name is known:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Setting default layout for the graph
>>> graph = graphspace.set_default_graph_layout(graph_name='My Sample Graph', layout_id=1087)
>>> graph.default_layout_id
1087

Setting a default layout when graph id is known:

>>> graph = graphspace.set_default_graph_layout(graph_id=65930, layout_id=1087)
>>> graph.default_layout_id
1087

Setting a default layout when graph object is passed as param:

>>> graph = graphspace.get_graph(graph_name='My Sample Graph')
>>> graph = graphspace.set_default_graph_layout(graph=graph, layout_id=1087)
>>> graph.default_layout_id
1087

Setting a default layout by passing layout name:

>>> graph = graphspace.set_default_graph_layout(graph_id=65930, layout_name='My Sample Layout')
>>> graph.default_layout_id
1087

Setting a default layout by only passing layout object as param:

>>> layout = graphspace.get_graph_layout(graph_id=65930, layout_name='My Sample Layout')
>>> graph = graphspace.set_default_graph_layout(layout=layout)
>>> graph.default_layout_id
1087

Note

Refer to the tutorial for more about setting default graph layout.

unpublish_graph(graph_name=None, graph_id=None, graph=None)[source]

Makes a graph privately viewable.

Parameters:
  • graph_name (str, optional) – Name of the graph. Defaults to None.
  • graph_id (int, optional) – ID of the graph. Defaults to None.
  • graph (GSGraph or Graph, optional) – Object having graph details, such as name, graph_json, style_json, is_public, tags. Defaults to None.
Returns:

Updated graph on GraphSpace.

Return type:

Graph

Raises:
  • Exception – If both ‘graph_name’ and ‘graph_id’ are None and graph object has no ‘name’ or ‘id’ attribute; or if graph doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Make graph private by name:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Unpublishing the graph
>>> graph = graphspace.unpublish_graph(graph_name='My Sample Graph')
>>> graph.get_is_public()
0

Make graph private by id:

>>> graph = graphspace.unpublish_graph(graph_id=65930)
>>> graph.get_is_public()
0

Make graph private by passing graph object itself as param:

>>> graph = graphspace.get_graph(graph_name='My Sample Graph')
>>> graphspace.unpublish_graph(graph=graph)

Note

Refer to the tutorial for more about making a graph private.

unset_default_graph_layout(graph_name=None, graph_id=None, graph=None)[source]

Unsets the current default layout of a graph provided the graph_name, graph_id or graph object itself.

Parameters:
  • graph_name (str, optional) – Name of the graph. Defaults to None.
  • graph_id (int, optional) – ID of the graph. Defaults to None.
  • graph (GSGraph or Graph, optional) – Object having graph details, such as name, graph_json, style_json, is_public, tags. Defaults to None.
Returns:

Updated graph on GraphSpace.

Return type:

Graph

Raises:
  • Exception – If both ‘graph_name’ and ‘graph_id’ are None and graph object has no ‘name’ or ‘id’ attribute; or if graph doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Unset default graph layout by graph name:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Unset the default graph layout
>>> graph = graphspace.unset_default_graph_layout(graph_name='My Sample Graph')
>>> assert graph.default_layout_id is None

Unset default graph layout by graph id:

>>> graph = graphspace.unset_default_graph_layout(graph_id=65930)

Unset default graph layout by graph object:

>>> graph = graphspace.get_graph(graph_name='My Sample Graph')
>>> graph = graphspace.unset_default_graph_layout(graph=graph)

Note

Refer to the tutorial for more about unsetting a default graph layout.

update_graph(graph, graph_name=None, graph_id=None, owner_email=None)[source]

Update a graph on GraphSpace with the provided graph object. If graph_name or graph_id is also provided then the update will be performed for that graph having the given name or id.

Parameters:
  • graph (GSGraph or Graph) – Object having graph details, such as name, graph_json, style_json, is_public, tags.
  • graph_name (str, optional) – Name of the graph to be updated. Defaults to None.
  • graph_id (int, optional) – ID of the graph to be updated. Defaults to None.
  • owner_email (str, optional) – Email of owner of the graph. Defaults to None.
Returns:

Updated graph on GraphSpace.

Return type:

Graph

Raises:
  • Exception – If both ‘graph_name’ and ‘graph_id’ are None and graph object has no ‘name’ or ‘id’ attribute; or if graph doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Updating a graph by creating a new graph and replacing the existing graph:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Creating the new graph
>>> G = GSGraph()
>>> G.add_node('a', popup='sample node popup text', label='A updated')
>>> G.add_node('b', popup='sample node popup text', label='B updated')
>>> G.add_edge('a', 'b', directed=True, popup='sample edge popup')
>>> G.add_edge_style('a', 'b', directed=True, edge_style='dotted')
>>> G.set_name('My Sample Graph')
>>> G.set_is_public(1)
>>> # Updating to replace the existing graph
>>> graphspace.update_graph(G)

Another way of updating a graph by fetching and editing the existing graph:

>>> # Fetching the graph
>>> graph = graphspace.get_graph(graph_name='My Sample Graph')
>>> # Modifying the fetched graph
>>> graph.add_node('z', popup='sample node popup text', label='Z')
>>> graph.add_node_style('z', shape='ellipse', color='green', width=90, height=90)
>>> graph.add_edge('a', 'z', directed=True, popup='sample edge popup')
>>> graph.set_is_public(1)
>>> # Updating graph
>>> graphspace.update_graph(graph)

If you also provide ‘graph_name’ or ‘graph_id’ as param then the update will be performed for that graph having the given name or id:

>>> graphspace.update_graph(G, graph_id=65930)

Note

Refer to the tutorial for more about updating graphs.

graphspace_python.api.endpoint.groups module

class graphspace_python.api.endpoint.groups.Groups(client)[source]

Bases: object

Groups endpoint class.

Provides methods for group related operations such as saving, fetching, updating, deleting groups on GraphSpace.

Also provides methods for group member and group graph related operations such as fetching all members or graphs of the group, adding or deleting new member or graph to the group.

add_group_member(member_email, group_name=None, group_id=None, group=None)[source]

Add a member to a group provided the group_name, group_id or the group object itself.

Parameters:
  • member_email (str) – Email of the member to be added to the group.
  • group_name (str, optional) – Name of the group. Defaults to None.
  • group_id (int, optional) – ID of the group. Defaults to None.
  • group (GSGroup or Group, optional) – Object having group details, such as name, description. Defaults to None.
Returns:

Dict containing ‘group_id’ and ‘user_id’ of the added member.

Return type:

dict

Raises:
  • Exception – If both ‘group_name’ and ‘group_id’ are None and group object has no ‘name’ or ‘id’ attribute; or if group doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Adding a member to a group when group name is known:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Adding a member to group
>>> graphspace.add_group_member(member_email='user2@example.com', group_name='My Sample Group')
{u'group_id': u'198', u'user_id': 2}

Adding a member to a group when group id is known:

>>> graphspace.add_group_member(member_email='user2@example.com', group_id=198)
{u'group_id': u'198', u'user_id': 2}

Adding a member to a group by passing group object itself as param:

>>> group = graphspace.get_group(group_name='My Sample Group')
>>> graphspace.add_group_member(member_email='user2@example.com', group=group)
{u'group_id': u'198', u'user_id': 2}

Note

Refer to the tutorial for more about adding group members.

delete_group(group_name=None, group_id=None, group=None)[source]

Delete a group from GraphSpace provided the group_name, group_id or the group object itself, where the requesting user is the owner.

Parameters:
  • group_name (str, optional) – Name of the group to be deleted. Defaults to None.
  • group_id (int, optional) – ID of the group to be deleted. Defaults to None.
  • group (GSGroup or Group, optional) – Object having group details, such as name, description. Defaults to None.
Returns:

Success/Error Message from GraphSpace.

Return type:

str

Raises:
  • Exception – If both ‘group_name’ and ‘group_id’ are None and group object has no ‘name’ or ‘id’ attribute; or if group doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Deleting a group by name:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Deleting a group
>>> graphspace.delete_group(group_name='My Sample Group')
u'Successfully deleted group with id=198'

Deleting a group by id:

>>> graphspace.delete_group(group_id=198)
u'Successfully deleted group with id=198'

Deleting a group by passing group object itself as param:

>>> group = graphspace.get_group(group_name='My Sample Group')
>>> graphspace.delete_group(group=group)
u'Successfully deleted group with id=198'

Note

Refer to the tutorial for more about deleting groups.

delete_group_member(member_id=None, member=None, group_name=None, group_id=None, group=None)[source]

Delete a member with given member_id or member object from a group provided the group_name, group_id or the group object itself.

Parameters:
  • member_id (int, optional) – ID of the member to be deleted from the group. Defaults to None.
  • member (Member, optional) – Object having member details, such as id, email. Defaults to None.
  • group_name (str, optional) – Name of the group. Defaults to None.
  • group_id (int, optional) – ID of the group. Defaults to None.
  • group (GSGroup or Group, optional) – Object having group details, such as name, description. Defaults to None.
Returns:

Success/Error Message from GraphSpace.

Return type:

str

Raises:
  • Exception – If both ‘group_name’ and ‘group_id’ are None and group object has no ‘name’ or ‘id’ attribute; or if ‘member_id’ is None and member object has no ‘id’ attribute; or if group doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Deleting a member from a group when group name is known:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Deleting a member from group
>>> graphspace.delete_group_member(member_id=2, group_name='My Sample Group')
u'Successfully deleted member with id=2 from group with id=198'

Deleting a member from a group when group id is known:

>>> graphspace.delete_group_member(member_id=2, group_id=198)
u'Successfully deleted member with id=2 from group with id=198'

Deleting a member from a group by passing group object itself as param:

>>> group = graphspace.get_group(group_name='My Sample Group')
>>> graphspace.delete_group_member(member_id=2, group=group)
u'Successfully deleted member with id=2 from group with id=198'

Deleting a member from a group by passing member object as param:

>>> members = graphspace.get_group_members(group_name='My Sample Group')
>>> graphspace.delete_group_member(member=members[0], group_name='My Sample Group')
u'Successfully deleted member with id=2 from group with id=198'

Note

Refer to the tutorial for more about deleting group members.

get_all_groups(limit=20, offset=0)[source]

Get groups where the requesting user is a member.

Parameters:
  • offset (int, optional) – Offset the list of returned entities by this number. Defaults to 0.
  • limit (int, optional) – Number of entities to return. Defaults to 20.
Returns:

List of groups where the requesting user is a member.

Return type:

List[Group]

Raises:

GraphSpaceError – If error response is received from the GraphSpace API.

Example

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Fetching all groups
>>> groups = graphspace.get_all_groups(limit=5)
>>> groups[0].get_name()
u'Test Group'
get_group(group_name=None, group_id=None)[source]

Get a group with the given group_name or group_id, where the requesting user is a member.

Parameters:
  • group_name (str, optional) – Name of the group to be fetched. Defaults to None.
  • group_id (int, optional) – ID of the group to be fetched. Defaults to None.
Returns:

Group object, if group with the given ‘group_name’ or ‘group_id’ exists; otherwise None.

Return type:

Group or None

Raises:
  • Exception – If both ‘group_name’ and ‘group_id’ are None.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Getting a group by name:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Fetching a group
>>> group = graphspace.get_group(group_name='My Sample Group')
>>> group.get_name()
u'My Sample Group'

Getting a group by id:

>>> group = graphspace.get_group(group_id=198)
>>> group.get_name()
u'My Sample Graph'

Note

Refer to the tutorial for more about fetching groups.

get_group_graphs(group_name=None, group_id=None, group=None)[source]

Get graphs shared with a group provided the group_name, group_id or the group object itself.

Parameters:
  • group_name (str, optional) – Name of the group. Defaults to None.
  • group_id (int, optional) – ID of the group. Defaults to None.
  • group (GSGroup or Group, optional) – Object having group details, such as name, description. Defaults to None.
Returns:

List of graphs belonging to the group.

Return type:

List[Graph]

Raises:
  • Exception – If both ‘group_name’ and ‘group_id’ are None and group object has no ‘name’ or ‘id’ attribute; or if group doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Getting graphs of a group when group name is known:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Fetching group graphs
>>> graphs = graphspace.get_group_graphs(group_name='My Sample Group')
>>> graphs[0].get_name()
u'My Sample Graph'

Getting graphs of a group when group id is known:

>>> graphs = graphspace.get_group_graphs(group_id=198)
>>> graphs[0].get_name()
u'My Sample Graph'

Getting graphs of a group by passing group object itself as param:

>>> group = graphspace.get_group(group_name='My Sample Group')
>>> graphs = graphspace.get_group_graphs(group=group)
>>> graphs[0].get_name()
u'My Sample Graph'

Note

Refer to the tutorial for more about fetching graphs of a group.

get_group_members(group_name=None, group_id=None, group=None)[source]

Get members of a group provided the group_name, group_id or the group object itself.

Parameters:
  • group_name (str, optional) – Name of the group. Defaults to None.
  • group_id (int, optional) – ID of the group. Defaults to None.
  • group (GSGroup or Group, optional) – Object having group details, such as name, description. Defaults to None.
Returns:

List of members belonging to the group.

Return type:

List[Member]

Raises:
  • Exception – If both ‘group_name’ and ‘group_id’ are None and group object has no ‘name’ or ‘id’ attribute; or if group doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Getting members of a group when group name is known:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Fetching group members
>>> members = graphspace.get_group_members(group_name='My Sample Group')
>>> members[0].email
u'user1@example.com'

Getting members of a group when group id is known:

>>> members = graphspace.get_group_members(group_id=198)
>>> members[0].email
u'user1@example.com'

Getting members of a group by passing group object itself as param:

>>> group = graphspace.get_group(group_name='My Sample Group')
>>> members = graphspace.get_group_members(group=group)
>>> members[0].email
u'user1@example.com'

Note

Refer to the tutorial for more about fetching group members.

get_my_groups(limit=20, offset=0)[source]

Get groups created by the requesting user.

Parameters:
  • offset (int, optional) – Offset the list of returned entities by this number. Defaults to 0.
  • limit (int, optional) – Number of entities to return. Defaults to 20.
Returns:

List of groups owned by the requesting user.

Return type:

List[Group]

Raises:

GraphSpaceError – If error response is received from the GraphSpace API.

Example

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Fetching my groups
>>> groups = graphspace.get_my_groups(limit=5)
>>> groups[0].get_name()
u'Test Group'
post_group(group)[source]

Create a group for the requesting user.

Parameters:group (GSGroup or Group) – Object having group details, such as name, description.
Returns:Saved group on GraphSpace.
Return type:Group
Raises:GraphSpaceError – If error response is received from the GraphSpace API.

Example

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Creating a group
>>> from graphspace_python.graphs.classes.gsgroup import GSGroup
>>> group = GSGroup(name='My Sample Group', description='sample group')
>>> # Saving group on GraphSpace
>>> graphspace.post_graph(group)

Note

Refer to the tutorial for more about posting groups.

share_graph(graph_name=None, graph_id=None, graph=None, group_name=None, group_id=None, group=None)[source]
Share a graph with a group by providing any of graph_name, graph_id or graph object
along with any of group_name, group_id or group object.
Parameters:
  • graph_name (str, optional) – Name of the graph. Defaults to None.
  • graph_id (int, optional) – ID of the graph. Defaults to None.
  • graph (GSGraph or Graph, optional) – Object having graph details, such as name, graph_json, style_json, is_public, tags. Defaults to None.
  • group_name (str, optional) – Name of the group. Defaults to None.
  • group_id (int, optional) – ID of the group. Defaults to None.
  • group (GSGroup or Group, optional) – Object having group details, such as name, description. Defaults to None.
Returns:

Dict containing ‘group_id’, ‘graph_id’, ‘created_at’, ‘updated_at’ details of the shared graph.

Return type:

dict

Raises:
  • Exception – If both ‘group_name’ and ‘group_id’ are None and group object has no ‘name’ or ‘id’ attribute; or if both ‘graph_name’ and ‘graph_id’ are None and graph object has no ‘name’ or ‘id’ attribute; or if the group or graph doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Sharing a graph with a group when group name is known:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Sharing a graph with a group
>>> graphspace.share_graph(graph_id=65390, group_name='My Sample Group')
{u'created_at': u'2017-07-20T18:40:36.267052', u'group_id': u'198', u'graph_id':
65390, u'updated_at': u'2017-07-20T18:40:36.267052'}

Sharing a graph with a group when group id is known:

>>> graphspace.share_graph(graph_id=65390, group_id=198)
{u'created_at': u'2017-07-20T18:40:36.267052', u'group_id': u'198', u'graph_id':
65390, u'updated_at': u'2017-07-20T18:40:36.267052'}

Sharing a graph with a group by passing group object itself as param:

>>> group = graphspace.get_group(group_name='My Sample Group')
>>> graphspace.share_graph(graph_id=65390, group=group)
{u'created_at': u'2017-07-20T18:40:36.267052', u'group_id': u'198', u'graph_id':
65390, u'updated_at': u'2017-07-20T18:40:36.267052'}

Sharing a graph with a group by providing graph name:

>>> graphspace.share_graph(graph_name='My Sample Graph', group_id=198)
{u'created_at': u'2017-07-20T18:40:36.267052', u'group_id': u'198', u'graph_id':
65390, u'updated_at': u'2017-07-20T18:40:36.267052'}

Sharing a graph with a group by providing graph object:

>>> graph = graphspace.get_graph(graph_name='My Sample Graph')
>>> graphspace.share_graph(graph=graph, group_id=198)
{u'created_at': u'2017-07-20T18:40:36.267052', u'group_id': u'198', u'graph_id':
65390, u'updated_at': u'2017-07-20T18:40:36.267052'}

Note

Refer to the tutorial for more about adding graph to a group.

unshare_graph(graph_name=None, graph_id=None, graph=None, group_name=None, group_id=None, group=None)[source]
Unshare a graph with a group by providing any of graph_name, graph_id or graph object
along with any of group_name, group_id or group object.
Parameters:
  • graph_name (str, optional) – Name of the graph. Defaults to None.
  • graph_id (int, optional) – ID of the graph. Defaults to None.
  • graph (GSGraph or Graph, optional) – Object having graph details, such as name, graph_json, style_json, is_public, tags. Defaults to None.
  • group_name (str, optional) – Name of the group. Defaults to None.
  • group_id (int, optional) – ID of the group. Defaults to None.
  • group (GSGroup or Group, optional) – Object having group details, such as name, description. Defaults to None.
Returns:

Success/Error Message from GraphSpace.

Return type:

str

Raises:
  • Exception – If both ‘group_name’ and ‘group_id’ are None and group object has no ‘name’ or ‘id’ attribute; or if both ‘graph_name’ and ‘graph_id’ are None and graph object has no ‘name’ or ‘id’ attribute; or if the group or graph doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Unshare a graph with a group when group name is known:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Unsharing a graph with a group
>>> graphspace.unshare_graph(graph_id=65390, group_name='My Sample Group')
u'Successfully deleted graph with id=65390 from group with id=198'

Unshare a graph with a group when group id is known:

>>> graphspace.unshare_graph(graph_id=65390, group_id=198)
u'Successfully deleted graph with id=65390 from group with id=198'

Unshare a graph with a group by passing group object itself as param:

>>> group = graphspace.get_group(group_name='My Sample Group')
>>> graphspace.unshare_graph(graph_id=65390, group=group)
u'Successfully deleted graph with id=65390 from group with id=198'

Unshare a graph with a group by providing graph name:

>>> graphspace.unshare_graph(graph_name='My Sample Graph', group_id=198)
u'Successfully deleted graph with id=65390 from group with id=198'

Unshare a graph with a group by providing graph object:

>>> graph = graphspace.get_graph(graph_name='My Sample Graph')
>>> graphspace.unshare_graph(graph=graph, group_id=198)
u'Successfully deleted graph with id=65390 from group with id=198'

Note

Refer to the tutorial for more about deleting graph from a group.

update_group(group, group_name=None, group_id=None)[source]

Update a group on GraphSpace with the provided group object. If group_name or group_id is also provided then the update will be performed for that group having the given name or id.

Parameters:
  • group (GSGroup or Group) – Object having group details, such as name, description.
  • group_name (str, optional) – Name of the group to be updated. Defaults to None.
  • group_id (int, optional) – ID of the group to be updated. Defaults to None.
Returns:

Updated group on GraphSpace.

Return type:

Group

Raises:
  • Exception – If both ‘group_name’ and ‘group_id’ are None and group object has no ‘name’ or ‘id’ attribute; or if group doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Updating a group by creating a new group and replacing the existing group:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Creating the new group
>>> group = GSGroup(name='My Sample Group', description='updated sample group')
>>> # Updating to replace the existing group
>>> group = graphspace.update_group(group)
>>> group.get_description()
u'updated sample group'

Another way of updating a group by fetching and editing the existing group:

>>> # Fetching the group
>>> group = graphspace.get_group(group_name='My Sample Group')
>>> # Modifying the fetched group
>>> group.set_description('updated sample group')
>>> # Updating group
>>> group = graphspace.update_group(group)
>>> group.get_description()
u'updated sample group'

If you also provide ‘group_name’ or ‘group_id’ as param then the update will be performed for that group having the given name or id:

>>> graphspace.update_group(group, group_id=198)

Note

Refer to the tutorial for more about updating groups.

graphspace_python.api.endpoint.layouts module

class graphspace_python.api.endpoint.layouts.Layouts(client)[source]

Bases: object

Layouts endpoint class.

Provides methods for layout related operations such as saving, fetching, updating and deleting layouts on GraphSpace.

delete_graph_layout(layout_name=None, layout_id=None, layout=None, graph_name=None, graph_id=None, graph=None)[source]

Delete a layout with given layout_name, layout_id or layout object itself from the graph with the given graph_name, graph_id or the graph object.

Parameters:
  • layout_name (str, optional) – Name of the layout to be deleted. Defaults to None.
  • layout_id (int, optional) – ID of the layout to be deleted. Defaults to None.
  • layout (GSLayout or Layout) – Object having layout details, such as name, is_shared, style_json, positions_json.
  • graph_name (str, optional) – Name of the graph. Defaults to None.
  • graph_id (int, optional) – ID of the graph. Defaults to None.
  • graph (GSGraph or Graph, optional) – Object having graph details, such as name, graph_json, style_json, is_public, tags. Defaults to None.
Returns:

Success/Error Message from GraphSpace.

Return type:

str

Raises:
  • Exception – If both ‘layout_name’ and ‘layout_id’ are None and layout object has no ‘name’ or ‘id’ attribute; or if both ‘graph_name’ and ‘graph_id’ are None and neither graph object has ‘name’ or ‘id’ attribute nor layout object has ‘graph_id’ attribute; or if graph or layout doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Deleting a layout by layout name:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Deleting a layout
>>> graphspace.delete_graph_layout(layout_name='My Sample Layout', graph_id=65390)
u'Successfully deleted layout with id=1087'

Deleting a layout by layout id:

>>> graphspace.delete_graph_layout(layout_id=1087, graph_id=65930)
u'Successfully deleted layout with id=1087'

Deleting a layout by passing layout object as param:

>>> layout = graphspace.get_graph_layout(layout_name='My Sample Layout', graph_id=65390)
>>> graphspace.delete_graph_layout(layout=layout)
u'Successfully deleted layout with id=1087'

Deleting a layout by passing graph name instead of id:

>>> graphspace.delete_graph_layout(layout_id=1087, graph_name='My Sample Graph')
u'Successfully deleted layout with id=1087'

Deleting a layout by passing graph object as param:

>>> graph = graphspace.get_graph(graph_name='My Sample Graph')
>>> graphspace.delete_graph_layout(layout_id=1087, graph=graph)
u'Successfully deleted layout with id=1087'

Note

Refer to the tutorial for more about deleting layouts.

get_graph_layout(layout_name=None, layout_id=None, graph_name=None, graph_id=None, graph=None, owner_email=None)[source]

Get a layout with given layout_id or layout_name for the graph with given graph_id, graph_name or graph object.

Parameters:
  • layout_name (str, optional) – Name of the layout to be fetched. Defaults to None.
  • layout_id (int, optional) – ID of the layout to be fetched. Defaults to None.
  • graph_name (str, optional) – Name of the graph. Defaults to None.
  • graph_id (int, optional) – ID of the graph. Defaults to None.
  • graph (GSGraph or Graph, optional) – Object having graph details, such as name, graph_json, style_json, is_public, tags. Defaults to None.
  • owner_email (str, optional) – Email of owner of layout. Defaults to None.
Returns:

Layout object, if layout with the given ‘layout_name’ or ‘layout_id’ exists; otherwise None.

Return type:

Layout or None

Raises:
  • Exception – If both ‘layout_name’ and ‘layout_id’ are None; or if both ‘graph_name’ and ‘graph_id’ are None and graph object has no ‘name’ or ‘id’ attribute; or if graph doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Getting a layout by name:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Fetching a layout
>>> layout = graphspace.get_graph_layout(layout_name='My Sample Layout', graph_id=65390)
>>> layout.get_name()
u'My Sample Layout'

Getting a layout by id:

>>> layout = graphspace.get_graph_layout(layout_id=1087, graph_id=65390)
>>> layout.get_name()
u'My Sample Layout'

Getting a layout by providing graph name:

>>> layout = graphspace.get_graph_layout(layout_id=1087, graph_name='My Sample Graph')
>>> layout.get_name()
u'My Sample Layout'

Getting a layout by providing graph object as param:

>>> graph = graphspace.get_graph(graph_name='My Sample Graph')
>>> layout = graphspace.get_graph_layout(layout_id=1087, graph=graph)
>>> layout.get_name()
u'My Sample Layout'

Note

Refer to the tutorial for more about fetching layouts.

get_my_graph_layouts(graph_name=None, graph_id=None, graph=None, limit=20, offset=0)[source]

Get layouts created by the requesting user for the graph with given graph_name, graph_id or graph object.

Parameters:
  • graph_name (str, optional) – Name of the graph. Defaults to None.
  • graph_id (int, optional) – ID of the graph. Defaults to None.
  • graph (GSGraph or Graph, optional) – Object having graph details, such as name, graph_json, style_json, is_public, tags. Defaults to None.
  • offset (int, optional) – Offset the list of returned entities by this number. Defaults to 0.
  • limit (int, optional) – Number of entities to return. Defaults to 20.
Returns:

List of layouts owned by the requesting user.

Return type:

List[Layout]

Raises:
  • Exception – If both ‘graph_name’ and ‘graph_id’ are None and graph object has no ‘name’ or ‘id’ attribute; or if graph doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Getting your graph layouts by graph id:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Fetching my graph layouts
>>> layouts = graphspace.get_my_graph_layouts(graph_id=65390, limit=5)
>>> layouts[0].get_name()
u'My Sample Layout'

Getting your graph layouts by graph name:

>>> layouts = graphspace.get_my_graph_layouts(graph_name='My Sample Graph', limit=5)

Getting your graph layouts by graph object itself:

>>> graph = graphspace.get_graph(graph_name='My Sample Graph')
>>> layouts = graphspace.get_my_graph_layouts(graph=graph, limit=5)
get_shared_graph_layouts(graph_name=None, graph_id=None, graph=None, limit=20, offset=0)[source]

Get layouts shared with the requesting user for the graph with given graph_name, graph_id or graph object.

Parameters:
  • graph_name (str, optional) – Name of the graph. Defaults to None.
  • graph_id (int, optional) – ID of the graph. Defaults to None.
  • graph (GSGraph or Graph, optional) – Object having graph details, such as name, graph_json, style_json, is_public, tags. Defaults to None.
  • offset (int, optional) – Offset the list of returned entities by this number. Defaults to 0.
  • limit (int, optional) – Number of entities to return. Defaults to 20.
Returns:

List of layouts shared with the requesting user.

Return type:

List[Layout]

Raises:
  • Exception – If both ‘graph_name’ and ‘graph_id’ are None and graph object has no ‘name’ or ‘id’ attribute; or if graph doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Getting shared graph layouts by graph id:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Fetching shared graph layouts
>>> layouts = graphspace.get_shared_graph_layouts(graph_id=65390, limit=5)
>>> layouts[0].get_name()
u'My Sample Layout'

Getting shared graph layouts by graph name:

>>> layouts = graphspace.get_shared_graph_layouts(graph_name='My Sample Graph', limit=5)

Getting shared graph layouts by graph object itself:

>>> graph = graphspace.get_graph(graph_name='My Sample Graph')
>>> layouts = graphspace.get_shared_graph_layouts(graph=graph, limit=5)
post_graph_layout(layout, graph_name=None, graph_id=None, graph=None)[source]

Create a layout for a graph provided the graph_name, graph_id or the graph object itself.

Parameters:
  • layout (GSLayout or Layout) – Object having layout details, such as name, is_shared, style_json, positions_json.
  • graph_name (str, optional) – Name of the graph. Defaults to None.
  • graph_id (int, optional) – ID of the graph. Defaults to None.
  • graph (GSGraph or Graph, optional) – Object having graph details, such as name, graph_json, style_json, is_public, tags. Defaults to None.
Returns:

Saved layout on GraphSpace.

Return type:

Layout

Raises:
  • Exception – If both ‘graph_name’ and ‘graph_id’ are None and graph object has no ‘name’ or ‘id’ attribute; or if graph doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Saving a layout when graph id is known:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Creating a layout
>>> from graphspace_python.graphs.classes.gslayout import GSLayout
>>> L = GSLayout()
>>> L.set_node_position('a', y=38.5, x=67.3)
>>> L.add_node_style('a', shape='ellipse', color='green', width=60, height=60)
>>> L.set_name('My Sample Layout')
>>> L.set_is_shared(1)
>>> # Saving layout on GraphSpace
>>> graphspace.post_graph_layout(L, graph_id=65390)

Saving a layout when graph name is known:

>>> graphspace.post_graph_layout(L, graph_name='My Sample Graph')

Saving a layout by passing graph object itself as param:

>>> graph = graphspace.get_graph(graph_name='My Sample Graph')
>>> graphspace.post_graph_layout(L, graph=graph)

Note

Refer to the tutorial for more about posting layouts.

update_graph_layout(layout, layout_name=None, layout_id=None, graph_name=None, graph_id=None, graph=None, owner_email=None)[source]

Update a layout with given layout_id or layout_name for a graph with the given graph_name, graph_id or the graph object itself.

Parameters:
  • layout (GSLayout or Layout) – Object having layout details, such as name, is_shared, style_json, positions_json.
  • layout_name (str, optional) – Name of the layout to be updated. Defaults to None.
  • layout_id (int, optional) – ID of the layout to be updated. Defaults to None.
  • graph_name (str, optional) – Name of the graph. Defaults to None.
  • graph_id (int, optional) – ID of the graph. Defaults to None.
  • graph (GSGraph or Graph, optional) – Object having graph details, such as name, graph_json, style_json, is_public, tags. Defaults to None.
  • owner_email (str, optional) – Email of owner of layout. Defaults to None.
Returns:

Updated layout on GraphSpace.

Return type:

Layout

Raises:
  • Exception – If both ‘layout_name’ and ‘layout_id’ are None and layout object has no ‘name’ or ‘id’ attribute; or if both ‘graph_name’ and ‘graph_id’ are None and neither graph object has ‘name’ or ‘id’ attribute nor layout object has ‘graph_id’ attribute; or if graph or layout doesnot exist.
  • GraphSpaceError – If error response is received from the GraphSpace API.

Examples

Updating a layout by creating a new layout and replacing the existing layout:

>>> # Connecting to GraphSpace
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
>>> # Creating the new layout
>>> L = GSLayout()
>>> L.set_node_position('a', y=102, x=238.1)
>>> L.add_node_style('a', shape='octagon', color='green', width=60, height=60)
>>> L.set_name('My Sample Layout')
>>> L.set_is_shared(1)
>>> # Updating to replace the existing layout
>>> graphspace.update_graph_layout(L, graph_id=65390)

Another way of updating a layout by fetching and editing the existing layout:

>>> # Fetching the layout
>>> layout = graphspace.get_graph_layout(name='My Sample Layout')
>>> # Modifying the fetched layout
>>> layout.set_node_position('a', y=30, x=211)
>>> layout.add_node_style('a', shape='roundrectangle', color='green', width=45, height=45)
>>> layout.set_is_shared(0)
>>> # Updating layout
>>> graphspace.update_graph_layout(layout)

If you also provide ‘layout_name’ or ‘layout_id’ as param then the update will be performed for that layout having the given name or id:

>>> graphspace.update_graph_layout(L, layout_id=1087, graph_id=65390)

Note

Refer to the tutorial for more about updating layouts.

Module contents