Skip to content

Node API

Marcus Klemm edited this page Aug 9, 2018 · 17 revisions

class graphit.GraphitNode

Working with Graph Nodes (a.k.a. Vertices).

Public API

__init__(session, data)

Creates a new GraphitNode object from data.

Parameters:
  • session: An instance of graphit.GraphitSession
  • data: A dict (or dict-like) object with the node's attributes as key–value–pairs. Needs to contain at least ogit/_type or ogit/_id!
Exceptions:

None

from_graph(session, ogit_id) (@classmethod)

Loads the vertex with the respective ogit/_id from the HIRO Graph and creates a new GraphitNode object with that data.

Parameters:
  • session: An instance of graphit.GraphitSession
  • ogit_id: A str containing the ogit/_id of an existing node in the HIRO Graph.
Exceptions:

create(owner=None)

Create the corresponding vertex in the HIRO Graph. If the node data includes an ogit/_owner attribute (or the owner parameter is used) and that owner does not exist in the HIRO Graph, yet, it will be created as well, as ogit/Organization.

Parameters:
  • owner: Override the ogit/_owner attribute.
Exceptions:

connect(ogit_type, other_node, reverse=False)

Create an Edge of type ogit_type from another instance of GraphitNode to this node.

Parameters:
  • reverse: Reverse the direction of the Edge, it will be directed from this node to the other node.
Exceptions:

update()

Update the node in the HIRO Graph.

Parameters:

None.

Exceptions:

push(replace=True, owner=None)

Update or create the node in the HIRO Graph. If replace is true

Parameters:
  • replace: bool, if True, the existing node will be replaced by the new data, meaning: all attributes that are in the Vertex in the HIRO Graph but not in the GraphitNode, will be deleted.
  • owner: Override the ogit/_owner attribute.
Exceptions:

pull()

Update the GraphitNode instance with the latest data from the HIRO Graph.

Parameters:

None.

Exceptions:

delete()

Delete the corresponding Vertex in the HIRO Graph.

Parameters:

None.

Exceptions:

get_attr(attr)

Get the value of the attribute attr, if it exists, None otherwise.

Parameters:
  • attr: A str containing the name of the attribute to get the value of.
Exceptions:

None.

set_attr(attr, value)

Set the value of the attribute attr to value and update the Vertex in the HIRO Graph.

Parameters:
  • attr: A str containing the name of the attribute to set.
  • value: A str containing the value the attribute should be set to.
Exceptions:

del_attr(attr)

Remove the attribute attr from the GraphitNode and update the Vertex in the HIRO Graph.

Parameters:
  • attr: A str containing the name of the attribute to delete.
Exceptions:

json(pretty_print=False)

Get a str containing the JSON representation of the GraphitNode.

Parameters:
  • pretty_print: Insert line breaks and indentation.
Exceptions:
  • ValueError If you set an attribute to a non–JSON–serializable value and call json() afterwards.

class graphit.Attachment

Subclass of graphit.GraphitNode to handle binary Attachments. Supports all methods of GraphitNode plus these additional ones:

Public API

get_content()

Get the binary content of the attachment, returns bytes.

Exceptions:

put_content(content)

Set the binary content of the attachment.

Parameters:
  • content: The raw binary content to upload as bytes.
Exceptions:

class graphit.Timeseries

Subclass of graphit.GraphitNode to handle Timeseries. Supports all methods of GraphitNode plus these additional ones:

Public API

get_values(start=None, end=None)

Get the values of a Timeseries. Returns a generator which will yield the actual results.

Parameters:
  • start: A timestamp in ms (int), only values from that point in time on will be included.
  • end: A timestamp in ms (int), only values before that point in time on will be included.
Exceptions:

put_values(values, size=None)

Add values to a Timeseries.

Parameters:
  • values: A list of dicts containing timeseries entries:
    [
      {
        'timestamp': <TIMESTAMP1>,
        'value': "<VALUE1>"
      }, 
      {
        'timestamp': <TIMESTAMP2>,
        'value': "<VALUE2>"
      }
    ]
    
  • size: An int or None. In case of an int, the list of values is split into chunks of size and each chunk is written to the graph in a separate request.
Exceptions: