python-igraph manual

For using igraph from Python

   Home       Trees       Indices       Help   
Package igraph :: Package remote :: Module gephi :: Class GephiGraphStreamer
[hide private]

Class GephiGraphStreamer

source code

object --+
         |
        GephiGraphStreamer

Class that produces JSON event objects that stream an igraph graph to Gephi using the Gephi Graph Streaming API.

The Gephi graph streaming format is a simple JSON-based format that can be used to post mutations to a graph (i.e. node and edge additions, removals and updates) to a remote component. For instance, one can open up Gephi (http://www.gephi.org}), install the Gephi graph streaming plugin and then send a graph from igraph straight into the Gephi window by using GephiGraphStreamer with the appropriate URL where Gephi is listening.

Example:

>>> from cStringIO import StringIO
>>> from igraph import Graph
>>> buf = StringIO()
>>> streamer = GephiGraphStreamer()
>>> graph = Graph.Formula("A --> B, B --> C")
>>> streamer.post(graph, buf)
>>> print buf.getvalue()         # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
{"an": {"igraph:...:v:0": {"name": "A"}}}
{"an": {"igraph:...:v:1": {"name": "B"}}}
{"an": {"igraph:...:v:2": {"name": "C"}}}
{"ae": {"igraph:...:e:0:1": {...}}}
{"ae": {"igraph:...:e:1:2": {...}}}
<BLANKLINE>
Instance Methods [hide private]
 
__init__(self, encoder=None)
Constructs a Gephi graph streamer that will post graphs to a given file-like object or a Gephi connection.
source code
 
iterjsonobj(self, graph)
Iterates over the JSON objects that build up the graph using the Gephi graph streaming API. The objects returned from this function are Python objects; they must be formatted with json.dumps before sending them to the destination.
source code
 
post(self, graph, destination, encoder=None)
Posts the given graph to the destination of the streamer using the given JSON encoder. When encoder is None, it falls back to the default JSON encoder of the streamer in the encoder property.
source code
 
send_event(self, event, destination, encoder=None, flush=True)
Sends a single JSON event to the given destination using the given JSON encoder. When encoder is None, it falls back to the default JSON encoder of the streamer in the encoder property.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, encoder=None)
(Constructor)

source code 

Constructs a Gephi graph streamer that will post graphs to a given file-like object or a Gephi connection.

encoder must either be None or an instance of json.JSONEncoder and it must contain the JSON encoder to be used when posting JSON objects.

Overrides: object.__init__

post(self, graph, destination, encoder=None)

source code 

Posts the given graph to the destination of the streamer using the given JSON encoder. When encoder is None, it falls back to the default JSON encoder of the streamer in the encoder property.

destination must be a file-like object or an instance of GephiConnection.

send_event(self, event, destination, encoder=None, flush=True)

source code 

Sends a single JSON event to the given destination using the given JSON encoder. When encoder is None, it falls back to the default JSON encoder of the streamer in the encoder property.

destination must be a file-like object or an instance of GephiConnection.

The method flushes the destination after sending the event. If you want to avoid this (e.g., because you are sending many events), set flush to False.


   Home       Trees       Indices       Help