Name | grand-cypher-io JSON |
Version |
0.1.0
JSON |
| download |
home_page | |
Summary | File IO routines for reading and writing OpenCypher files |
upload_time | 2023-10-17 19:45:14 |
maintainer | |
docs_url | None |
author | Jordan Matelsky |
requires_python | >=3.10,<3.13 |
license | Apache 2.0 |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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](https://github.com/aplbrain/grand) `Graph.nx` objects.
- You can mock most of a Neo4j database, using this repository for IO and in conjunction with [Grand-Cypher](https://github.com/aplbrain/grand-cypher) for query execution.
- Designed for use with [AWS Neptune](https://docs.aws.amazon.com/neptune/latest/userguide/bulk-load-tutorial-format-opencypher.html)
## Usage
### Export a graph to OpenCypher-readable files
```python
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
```python
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](https://github.com/aplbrain/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](https://github.com/aplbrain/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.
<p align='center'><small>Made with 💙 at <a href='http://www.jhuapl.edu/'><img alt='JHU APL' align='center' src='https://user-images.githubusercontent.com/693511/62956859-a967ca00-bdc1-11e9-998e-3888e8a24e86.png' height='42px'></a></small></p>
Raw data
{
"_id": null,
"home_page": "",
"name": "grand-cypher-io",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10,<3.13",
"maintainer_email": "",
"keywords": "",
"author": "Jordan Matelsky",
"author_email": "opensource@matelsky.com",
"download_url": "https://files.pythonhosted.org/packages/a5/93/498a08587b3b5642e120e1679d82bea8ccd593c9d0303fd4b29e9d762075/grand_cypher_io-0.1.0.tar.gz",
"platform": null,
"description": "# grand-cypher-io\n\nFile IO routines for reading and writing OpenCypher files.\n\n---\n\n## Why?\n\n- To enable the use of OpenCypher files as a standard graph interchange format.\n- To simplify reading and writing in-memory Python graphs to a Neo4j or Neptune database.\n- To serialize and deserialize graphs for long-term (e.g., archival) immutable storage.\n\n## Compatibilities\n\n- All routines that expect a graph can be run with [Grand](https://github.com/aplbrain/grand) `Graph.nx` objects.\n- You can mock most of a Neo4j database, using this repository for IO and in conjunction with [Grand-Cypher](https://github.com/aplbrain/grand-cypher) for query execution.\n- Designed for use with [AWS Neptune](https://docs.aws.amazon.com/neptune/latest/userguide/bulk-load-tutorial-format-opencypher.html)\n\n## Usage\n\n### Export a graph to OpenCypher-readable files\n\n```python\nfrom grand_cypher_io import graph_to_opencypher_buffers\n# `graph` is nx.DiGraph or compatible\nvert_buffer, edge_buffer = graph_to_opencypher_buffers(graph)\nwith open('vertices.csv', 'w') as f:\n f.write(vert_buffer.read())\nwith open('edges.csv', 'w') as f:\n f.write(edge_buffer.read())\n```\n\n### Import a graph from OpenCypher-readable files\n\n```python\nfrom grand_cypher_io import opencypher_buffers_to_graph\nwith open('vertices.csv', 'r') as f:\n vert_buffer = io.StringIO(f.read())\nwith open('edges.csv', 'r') as f:\n edge_buffer = io.StringIO(f.read())\ngraph = opencypher_buffers_to_graph(vert_buffer, edge_buffer)\n```\n\n## Usage Considerations\n\n### Edge addition implies vertices\n\nWhen 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](https://github.com/aplbrain/grand) graph library assumptions, and greatly reduces the inner-loop complexity of the import process.\n\nBecause these implicit vertices have no properties, they are easy to detect and filter out of the graph after importing, if desired.\n\nThis behavior also means that it is possible to create a full structural graph from a set of edges alone, without any vertices.\n\n### The `__labels__` magic attribute\n\nFollowing the [Grand-Cypher](https://github.com/aplbrain/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.\n\nLikewise, the `__labels__` attribute is used to populate the `labels` attribute of a node when reading from an OpenCypher file.\n\n<p align='center'><small>Made with \ud83d\udc99 at <a href='http://www.jhuapl.edu/'><img alt='JHU APL' align='center' src='https://user-images.githubusercontent.com/693511/62956859-a967ca00-bdc1-11e9-998e-3888e8a24e86.png' height='42px'></a></small></p>\n",
"bugtrack_url": null,
"license": "Apache 2.0",
"summary": "File IO routines for reading and writing OpenCypher files",
"version": "0.1.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c7891ea1281c5163da871cdd8cd993d9d11b2d925c4c375361320f2fd5b05cdb",
"md5": "6f9256d6a9df5b7cc891832722e57166",
"sha256": "0aad13a0112b44c647d2fab8275a85f1e06ecb462bc04ae77057cdf1518f6c05"
},
"downloads": -1,
"filename": "grand_cypher_io-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6f9256d6a9df5b7cc891832722e57166",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10,<3.13",
"size": 12490,
"upload_time": "2023-10-17T19:45:12",
"upload_time_iso_8601": "2023-10-17T19:45:12.317513Z",
"url": "https://files.pythonhosted.org/packages/c7/89/1ea1281c5163da871cdd8cd993d9d11b2d925c4c375361320f2fd5b05cdb/grand_cypher_io-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a593498a08587b3b5642e120e1679d82bea8ccd593c9d0303fd4b29e9d762075",
"md5": "79777c4190d177e86b676550bbde020f",
"sha256": "19363cbf8b13934699a8f36f3c2f1c1f45b11b3a0cc6970d050633d25b719eae"
},
"downloads": -1,
"filename": "grand_cypher_io-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "79777c4190d177e86b676550bbde020f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10,<3.13",
"size": 12437,
"upload_time": "2023-10-17T19:45:14",
"upload_time_iso_8601": "2023-10-17T19:45:14.106982Z",
"url": "https://files.pythonhosted.org/packages/a5/93/498a08587b3b5642e120e1679d82bea8ccd593c9d0303fd4b29e9d762075/grand_cypher_io-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-17 19:45:14",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "grand-cypher-io"
}