python_psynth
This is the official python package for generating graphs in Psymphonic Psynth
psynth.psynth.Graph Class Reference

The Graph is a structured collection of Node, Link, LinkType, and Detail objects. More...

Public Member Functions

def __init__ (self, name, filename, url, username, key)
 This is the constructor for the Graph class. More...
 
def queue (self, query, callback)
 All queries should be processed through this function to ensure that they process in order. More...
 
def prep (self, query)
 Turns a query dictionary into a valid URL. More...
 
def add_detail
 This adds a Detail to the Graph. More...
 
def add_link
 This adds a Link to the Graph. More...
 
def add_link_type
 Adds a LinkType to the Graph. More...
 
def add_node
 Adds a Node to the Graph. More...
 
def detail (self, uid)
 Returns a Detail by its UID. More...
 
def detail_list (self)
 Returns a list of Detail objects in the Graph. More...
 
def details (self)
 Returns a dictionary of Detail objects keyed by uid. More...
 
def draw
 Calculates a layout for the Graph and returns new positions for all Node and Detail objects. More...
 
def height (self)
 Returns the height of the Graph. More...
 
def link (self, uid)
 Returns a Link by uid. More...
 
def link_list (self)
 Returns a list of Link objects in the Graph. More...
 
def links (self)
 Returns a uid-keyed dictionary of Link objects in the Graph. More...
 
def link_type (self, name)
 Returns a LinkType object by name. More...
 
def link_types (self)
 Returns a name-keyed dictionary of LinkType objects. More...
 
def max_x (self)
 Returns the maximum x value of all Node objects in the Graph. More...
 
def max_y (self)
 Returns the maximum y value of all Node objects in the Graph. More...
 
def min_x (self)
 Returns the minimum x value of all Node objects in the Graph. More...
 
def min_y (self)
 Returns the minimum y value of all Node objects in the Graph. More...
 
def node (self, uid)
 Returns a Node by uid. More...
 
def node_list (self)
 Returns a list of all Node objects in the Graph. More...
 
def nodes (self)
 Returns a uid-keyed dictionary of Node objects. More...
 
def publish
 Creates a perma-link for a public viewer of the graph. More...
 
def remove_detail
 Removes a Detail from the Graph. More...
 
def remove_link
 Removes a Link from the Graph. More...
 
def remove_node
 Removes a Node from the Graph. More...
 
def width (self)
 Returns the width of the Graph. More...
 

Public Attributes

 name
 str :: The display name of the Graph. More...
 
 filename
 str :: The global unique filename of the Graph. More...
 
 url
 str :: The base URL for your psynth server. More...
 
 username
 str :: Your Psynth username. More...
 
 key
 str :: Your Psynth API Key. More...
 

Detailed Description

The Graph is a structured collection of Node, Link, LinkType, and Detail objects.

Most actions are performed through the Graph class.

Constructor & Destructor Documentation

def psynth.psynth.Graph.__init__ (   self,
  name,
  filename,
  url,
  username,
  key 
)

This is the constructor for the Graph class.

It should not be accessed directly, but instead through the create_graph and load_graph functions.

Parameters
namestr :: The displayed name of a Graph.
filenamestr :: A global unique filename of a Graph.
urlstr :: The base URL of your Psynth server. e.g. https://psynth.psymphonic.com/
usernamestr :: Your Psynth username
keystr :: Your Psynth API key.
1 g = load_graph(
2  filename='myfile.gt',
3  url='https://psynth.psymphonic.com/',
4  username='me@company.com',
5  key='myapikey'
6 )
1 g = create_graph(
2  name='my graph',
3  url='https://psynth.psymphonic.com/',
4  username='me@company.com',
5  key='myapikey'
6 )

Member Function Documentation

def psynth.psynth.Graph.add_detail (   self,
  detail,
  callback = None,
  update = True 
)

This adds a Detail to the Graph.

It is easier to add Detail objects directly to Node and Link objects.

Parameters
detailDetail :: A Detail object to add to the Graph.
callbackfunction :: A function to perform on the response of the query.
updatebool :: Whether or not to immediately enqueue the query.
1 g.add_detail(my_detail, callback=my_function)
def psynth.psynth.Graph.add_link (   self,
  link,
  callback = None,
  update = True 
)

This adds a Link to the Graph.

Parameters
linkLink :: A Link to add to the Graph.
callbackfunction :: A function to perform on the response to the query.
updatebool :: Whether or not to immediately enqueue the query.
1 g.add_link(my_link, callback=my_function)
def psynth.psynth.Graph.add_link_type (   self,
  link_type,
  callback = None,
  update = True 
)

Adds a LinkType to the Graph.

Must be added before Link objects of that type can be created.

Parameters
link_typeLinkType :: A LinkType to add to the Graph
callbackfunction :: A function to perform on the response to the query.
updatebool :: Whether or not to immediately enqueue the query.
1 g.add_link_type(my_link_type, callback=my_function)
def psynth.psynth.Graph.add_node (   self,
  node,
  callback = None,
  update = True 
)

Adds a Node to the Graph.

Parameters
nodeNode :: The Node to add to the Graph.
callbackfunction :: An optional function to handle the server's response to the query.
updateWhether or not to immediately enqueue the query.
1 g.add_node(my_node, callback=my_function)
def psynth.psynth.Graph.detail (   self,
  uid 
)

Returns a Detail by its UID.

Parameters
uidstr :: The uid of the Detail to return.
Returns
detail: Detail ::
1 my_detail = g.detail(unique_id)
def psynth.psynth.Graph.detail_list (   self)

Returns a list of Detail objects in the Graph.

Returns
details: list :: A list of Detail objects.
1 for d in g.detail_list():
2  print d.content
def psynth.psynth.Graph.details (   self)

Returns a dictionary of Detail objects keyed by uid.

Returns
details: dict :: A uid-keyed dictionary of Detail objects.
1 for d in g.details():
2  print g.details()[d].anchor().name
def psynth.psynth.Graph.draw (   self,
  callback = None 
)

Calculates a layout for the Graph and returns new positions for all Node and Detail objects.

Parameters
callbackfunction :: An optional function to handle the server's response to the query.
1 for i in range(0, 100):
2  n = Node(name='Node '+str(i))
3  g.add_node(n)
4 g.draw()
def psynth.psynth.Graph.height (   self)

Returns the height of the Graph.

Returns
height: float ::
1 h = g.height()
def psynth.psynth.Graph.link (   self,
  uid 
)

Returns a Link by uid.

Parameters
uidstr :: The uid of the Link to return.
Returns
link: Link ::
1 my_link = g.link(unique_id)
def psynth.psynth.Graph.link_list (   self)

Returns a list of Link objects in the Graph.

Returns
links: list :: A list of Link objects.
1 for link in g.link_list():
2  print link.name
def psynth.psynth.Graph.link_type (   self,
  name 
)

Returns a LinkType object by name.

Parameters
namestr :: The name of the LinkType to return.
Returns
link_type: LinkType ::
1 lt = g.link_type('Money')
def psynth.psynth.Graph.link_types (   self)

Returns a name-keyed dictionary of LinkType objects.

Returns
link_types: dict :: A name-keyed dictionary of LinkType objects.
1 for lt in g.link_types():
2  print len(g.link_types[lt].links())
def psynth.psynth.Graph.links (   self)

Returns a uid-keyed dictionary of Link objects in the Graph.

Returns
links: dict :: A uid-keyed dictionary of Link objects.
1 for uid in g.links():
2  print g.links()[uid].name
def psynth.psynth.Graph.max_x (   self)

Returns the maximum x value of all Node objects in the Graph.

Returns
x: float ::
1 n = Node(x=g.max_x()+50)
2 g.add_node(n)
def psynth.psynth.Graph.max_y (   self)

Returns the maximum y value of all Node objects in the Graph.

Returns
y: float ::
1 n = Node(y=g.max_y()-50)
2 g.add_node(n)
def psynth.psynth.Graph.min_x (   self)

Returns the minimum x value of all Node objects in the Graph.

Returns
x: float ::
1 n = Node(x=g.min_x()+50)
2 g.add_node(n)
def psynth.psynth.Graph.min_y (   self)

Returns the minimum y value of all Node objects in the Graph.

Returns
y: float ::
1 n = Node(x=g.min_y()+50)
2 g.add_node(n)
def psynth.psynth.Graph.node (   self,
  uid 
)

Returns a Node by uid.

Parameters
uidstr :: The uid of the Node to be returned.
Returns
node: Node ::
1 n = g.node(unique_id)
def psynth.psynth.Graph.node_list (   self)

Returns a list of all Node objects in the Graph.

Returns
nodes: list :: A list of Node objects.
1 for n in g.node_list():
2  print n.name
def psynth.psynth.Graph.nodes (   self)

Returns a uid-keyed dictionary of Node objects.

Returns
nodes: dict :: A uid-keyed dictionary of Node objects.
1 for n in g.nodes():
2  print g.nodes()[n].name
def psynth.psynth.Graph.prep (   self,
  query 
)

Turns a query dictionary into a valid URL.

Mostly used internally.

Parameters
querydict :: A query dictionary.
Returns
url: str :: A valid URL
1 c = requests.get(g.prep(query))
2 print c.json()
def psynth.psynth.Graph.publish (   self,
  callback = None 
)

Creates a perma-link for a public viewer of the graph.

Parameters
callbackfunction :: An optional function to handle the server's response to the query.
1 g.draw()
2 g.publish()
def psynth.psynth.Graph.queue (   self,
  query,
  callback 
)

All queries should be processed through this function to ensure that they process in order.

Mostly used internally.

Parameters
querydict :: A dictionary object that contains query parameters.
callbackfunction :: A function that should be performed on the response from the query.
1 def point_handler(r):
2  print r
3 g.queue({'query': 'drawgraph'}, point_handler)
def psynth.psynth.Graph.remove_detail (   self,
  detail,
  callback = None,
  update = True 
)

Removes a Detail from the Graph.

Parameters
detailDetail :: The Detail to remove.
callbackfunction :: An optional function to handle the server's response to the query.
updatebool :: Whether or not to immediately enqueue the query.
1 g.remove_detail(my_detail, callback=my_function)
def psynth.psynth.Graph.remove_link (   self,
  link,
  callback = None,
  update = True 
)

Removes a Link from the Graph.

Parameters
linkLink The Link to remove.
callbackfunction :: An optional function to handle the server's response to the query.
updatebool :: Whether or not to immediately enqueue the query.
1 g.remove_link(my_link, callback=my_function)
def psynth.psynth.Graph.remove_node (   self,
  node,
  callback = None,
  update = True 
)

Removes a Node from the Graph.

Parameters
nodeNode :: The Node to remove.
callbackfunction :: An optional function to handle the server's response to the query.
updatebool :: Whether or not to immediately enqueue the query.
1 g.remove_node(my_node, callback=my_function)
def psynth.psynth.Graph.width (   self)

Returns the width of the Graph.

Returns
width: float ::
1 print g.width()

Member Data Documentation

psynth.psynth.Graph.filename

str :: The global unique filename of the Graph.

psynth.psynth.Graph.key

str :: Your Psynth API Key.

psynth.psynth.Graph.name

str :: The display name of the Graph.

psynth.psynth.Graph.url

str :: The base URL for your psynth server.

e.g. "https://psynth.psymphonic.com/"

psynth.psynth.Graph.username

str :: Your Psynth username.


The documentation for this class was generated from the following file: