Extension: Geoff

Maintained by: Nigel Small <nigel@py2neo.org>

Geoff is a text-based interchange format for Neo4j graph data that should be instantly readable to anyone familiar with Cypher, on which its syntax is based. For more information on the format itself, see here.

The Geoff extension for py2neo consists of a writer and a loader API. A command line tool is also provided for easy access to the load functionality. The loader itself requires a server plugin to be installed called load2neo.

Writer

class py2neo.ext.geoff.GeoffWriter(file=None, **kwargs)[source]

Writer for Geoff data. This can be used to write to any file-like object, such as standard output:

>>> from py2neo import Node
>>> from py2neo.ext.geoff import GeoffWriter
>>> import sys
>>> writer = GeoffWriter(sys.stdout)
>>> writer.write(Node("Person", name="Alice"))
(139895901379856:Person {"name":"Alice"})
write(obj)[source]

Write any entity, value or collection.

write_identifier(identifier)[source]

Write an identifier.

write_list(collection)[source]

Write a list.

write_map(mapping)[source]

Write a map.

write_node(name, labels=None, properties=None, unique_label=None, unique_key=None)[source]

Write a node.

write_path(path)[source]

Write a py2neo.Path.

write_rel(type_, properties=None, unique=False)[source]

Write a forward relationship (excluding nodes).

write_rev(type_, properties=None, unique=False)[source]

Write a reverse relationship (excluding nodes).

write_subgraph(subgraph)[source]

Write a py2neo.Subgraph.

write_value(value)[source]

Write a value.

Loader

class py2neo.ext.geoff.GeoffLoader(graph, path='/load2neo/')[source]

A wrapper for the load2neo unmanaged extension.

load(string)[source]

Load Geoff data from a string.

load2neo_version

The version of server extension currently installed.

load_xml(string)[source]

Load XML data by first converting to Geoff format.

class py2neo.ext.geoff.NodeDictionary(graph, data)[source]

A set of nodes returned from a successful Geoff load operation. Each node is keyed by the identifier used in the original Geoff data.

get_ref(key)[source]

Get the node reference string for the node identified by the given key.

items()[source]

Fetch a list of all key-node pairs, each returned as a 2-tuple.

keys()[source]

Fetch a list of all node keys.

values()[source]

Fetch a list of all nodes.

Command Line

A command line tool, geoff is installed as part of this extension. This gives access to the GeoffLoader class and can be used as follows:

$ geoff load '(alice:Person {"name":"Alice"})<-[:KNOWS]->(bob:Person {"name":"Bob"})'
alice node/1
bob   node/2

Instead of providing data inline, a file name can be specified instead using the -f option:

$ geoff load -f abba.geoff
abba     node/1648
agnetha  node/1649
benny    node/1655
björn    node/1650
frida    node/1653
waterloo node/1654

XML files can also be passed using the -x option. These will be converted to Geoff before loading:

$ geoff load -x -f abba.xml
abba     node/1668
agnetha  node/1669
benny    node/1670
björn    node/1652
frida    node/1664
waterloo node/1665