Skip to main content

File IO routines for reading and writing OpenCypher files

Project description

grand-cypher-io

File IO routines for reading and writing OpenCypher files.


Why?

  • To enable the use of OpenCypher files as a standard graph interchange format.
  • To simplify reading and writing in-memory Python graphs to a Neo4j or Neptune database.
  • To serialize and deserialize graphs for long-term (e.g., archival) immutable storage.

Compatibilities

  • All routines that expect a graph can be run with Grand Graph.nx objects.
  • You can mock most of a Neo4j database, using this repository for IO and in conjunction with Grand-Cypher for query execution.
  • Designed for use with AWS Neptune

Usage

Export a graph to OpenCypher-readable files

from grand_cypher_io import graph_to_opencypher_buffers
# `graph` is nx.DiGraph or compatible
vert_buffer, edge_buffer = graph_to_opencypher_buffers(graph)
with open('vertices.csv', 'w') as f:
    f.write(vert_buffer.read())
with open('edges.csv', 'w') as f:
    f.write(edge_buffer.read())

Import a graph from OpenCypher-readable files

from grand_cypher_io import opencypher_buffers_to_graph
with open('vertices.csv', 'r') as f:
    vert_buffer = io.StringIO(f.read())
with open('edges.csv', 'r') as f:
    edge_buffer = io.StringIO(f.read())
graph = opencypher_buffers_to_graph(vert_buffer, edge_buffer)

Usage Considerations

Edge addition implies vertices

When adding an edge to a graph, the vertices of the edge are also added to the graph. This is counter to the behavior of Neo4j imports, but compatible with the Grand graph library assumptions, and greatly reduces the inner-loop complexity of the import process.

Because these implicit vertices have no properties, they are easy to detect and filter out of the graph after importing, if desired.

This behavior also means that it is possible to create a full structural graph from a set of edges alone, without any vertices.

The __labels__ magic attribute

Following the Grand-Cypher convention, the __labels__ attribute is used to store the labels of a node. This is an iterable of strings. The __labels__ attribute is not required, but if it is present, it will be used to populate the labels attribute of the node for the purposes of writing to an OpenCypher file.

Likewise, the __labels__ attribute is used to populate the labels attribute of a node when reading from an OpenCypher file.

Made with 💙 at JHU APL

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grand_cypher_io-0.1.0.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

grand_cypher_io-0.1.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file grand_cypher_io-0.1.0.tar.gz.

File metadata

  • Download URL: grand_cypher_io-0.1.0.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.0 CPython/3.11.3 Darwin/22.6.0

File hashes

Hashes for grand_cypher_io-0.1.0.tar.gz
Algorithm Hash digest
SHA256 19363cbf8b13934699a8f36f3c2f1c1f45b11b3a0cc6970d050633d25b719eae
MD5 79777c4190d177e86b676550bbde020f
BLAKE2b-256 a593498a08587b3b5642e120e1679d82bea8ccd593c9d0303fd4b29e9d762075

See more details on using hashes here.

File details

Details for the file grand_cypher_io-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: grand_cypher_io-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.0 CPython/3.11.3 Darwin/22.6.0

File hashes

Hashes for grand_cypher_io-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0aad13a0112b44c647d2fab8275a85f1e06ecb462bc04ae77057cdf1518f6c05
MD5 6f9256d6a9df5b7cc891832722e57166
BLAKE2b-256 c7891ea1281c5163da871cdd8cd993d9d11b2d925c4c375361320f2fd5b05cdb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page