Python API

netshape.main

The main netshape module which contains the Netshape graph representation class

class netshape.main.Netshape

The netshape class. Netshape objects maintain the network state through two primary attributes:

self.json_graph

The JSON representation of the graph, which maintains nodes and links as lists of dicts. This is what is eventually written to the data file used for the web UI.

self.json_graph = {'nodes': [], 'links':[]}
self.g
a networkx representation of the network. This is useful for computation of network statistics.
add_node_prop(prop, prop_map)

Adds a node property to the json_graph Positional arguments:

prop

The name of the property to add

prop_map

A mapping from node ID’s to property values

build_visualization(out='dist', title='Network')

Scaffolds the visualization project into a directory named dist

from_edgelist(edgelist, sep=', ', directed=True)

Reads a csv formatted edgelist and adds nodes and edges to the network accordingly. If there is a header, the columns labeled ‘source’, and ‘target’ will be used as node ID’s, and any other columns, edge attributes. Otherwise, the first two columns will be used as node ID’s.

Positional arguments:
edgelist

the file to be opened

Keyword arguments:

sep

the delimiter string in the csv (default: ” , ”)

directed

boolean indicating true if the graph is directed (default: True)

netshape.config

Module for writing netshape-config.py files

class netshape.config.Command

docstring for Command

add_node_prop(name, func, *args, **kwargs)

Adds a property to nodes in the network

Positional arguments: name – the name of the property to be added func – a function which accepts a netshape object as the first

argument, the name of the property as the second, and the command line arguments as the third, as well as any additional arguments, and returns a mapping from node ids to property values
run_pipeline(cl_args)

Executes the pipeline

class netshape.config.Config

docstring for Config

register_command(command_name, help=None, command_args=None)

Registers a subcommand and returns a command object which can

netshape.node_props

netshape.node_props.eigenvector_centrality(ns, name, _)

Computes eigenvector centrality for all nodes

netshape.node_props.modularity_community(ns, name, _)

Community detection