Skip to main content

grand-cypher-io

File IO routines for reading and writing OpenCypher files

PyPI - Version


pip install grand-cypher-io

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

import networkx as nx

from grand_cypher_io import graph_to_opencypher_buffers

# `graph` is an nx.Graph or compatible object.
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

graph = opencypher_buffers_to_graph("vertices.csv", "edges.csv")

Python 3.11 through 3.13 are supported.

Imports create an nx.MultiDiGraph by default so parallel OpenCypher relationships are preserved. Pass to_graph= to populate another NetworkX graph type; importing parallel relationships into a simple graph raises an error rather than discarding data.

Development

The project uses uv for environments, dependency locking, and builds:

uv sync --locked --all-groups
uv run ruff check .
uv run ruff format --check .
uv run pytest
uv build

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. Writers accept either one string or 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.

Readers always store __labels__ as a set of strings. Typed OpenCypher properties are converted to their corresponding Python scalar types.

Made with 💙 at JHU APL

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.2.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grand_cypher_io-0.2.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: grand_cypher_io-0.2.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for grand_cypher_io-0.2.0.tar.gz
Algorithm Hash digest
SHA256 229096b8705d7acd20db51aefba181dc1a3f5048371af5848ada5658cc28e8df
MD5 9533dddb0bb120003add970708b12d95
BLAKE2b-256 7e1252849983a8009ca6706c8a69b440645ef971465a006a527e8c518b71a66e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: grand_cypher_io-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for grand_cypher_io-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9c361b33894ce1ee9d56e7d46cf868256389b18ad6b79ce961be54f95c53466
MD5 0ca90df2a9bbbbb900ece2500d3eac44
BLAKE2b-256 bd6b986bb17239f3b9734a182c8730d632c1c9e937913d2c166c173e7cb2dcdf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page