Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bruth/graphlib
Graph API and serializer for the JSON Graph Spec
https://github.com/bruth/graphlib
Last synced: about 1 month ago
JSON representation
Graph API and serializer for the JSON Graph Spec
- Host: GitHub
- URL: https://github.com/bruth/graphlib
- Owner: bruth
- License: bsd-2-clause
- Archived: true
- Created: 2014-01-05T15:29:09.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-06-22T09:24:54.000Z (about 10 years ago)
- Last Synced: 2024-07-05T15:31:23.431Z (3 months ago)
- Language: Python
- Homepage:
- Size: 248 KB
- Stars: 8
- Watchers: 5
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Graph Library
[![Build Status](https://travis-ci.org/bruth/graphlib.png?branch=master)](https://travis-ci.org/bruth/graphlib) [![Coverage Status](https://coveralls.io/repos/bruth/graphlib/badge.png)](https://coveralls.io/r/bruth/graphlib)
Graph API, serializer, and loader that conforms to the [JSON Graph Spec](https://github.com/bruth/json-graph-spec).
## Install
```
pip install graphlib
```## Usage
### Create
The object API makes it simple to create nodes and relationships between them.
```python
from graphlib import Nodecity = Node({'location': 'Philadelphia'})
jane = Node({'name': 'Jane'})
john = Node({'name': 'John'})
bob = Node({'name': 'Bob'})city.relate([jane, john, bob], 'LIVES_IN')
jane.relate(john, 'MARRIED_TO')
john.relate(bob, 'FRIENDS_WITH')
```### Serialize
Serializes the object reprsentations into dicts and lists which can be encoded as JSON or loaded into a graph database.
```python
from graphlib import serializedata = serialize(city)
```### Load
Takes the serialized data and loads it into a database. This example loads it into Neo4j.
```python
from graphlib import neo4jneo4j.load(data)
```## CLI
The Neo4j module can be used directly via the command line:
```
python -m 'graphlib.neo4j' [path/to/file.json] [--load] [uri]
```By default, `stdin` will be read which should be valid JSON that will be parsed and converted into Cypher statements and printed to stdout. If a path supplied, the file will be read instead of stdin. If the `--load` flag is present, the statements will be executed on the Neo4j server at the default URI unless a custom URI is provided.