Permalink
Browse files

Added code examples to documentation

  • Loading branch information...
1 parent b654fc6 commit 8fe84251bbf4fa6027c7a2cb31f95fae66ce5020 @escalant3 committed Jul 26, 2011
Showing with 166 additions and 12 deletions.
  1. +83 −6 README.rst
  2. +83 −6 README.txt
View
89 README.rst
@@ -29,7 +29,7 @@ The easiest way to get pyblueprints installed in your virtualenv is by:
Usage
-----
-This version of pybluerprints allows you to connect to graph databases by a Rexster Instance or through the neo4j-rest-client API. Therefore a Neo4j database can be accessed with both options.
+This version of pybluerprints allows you to connect to graph databases by a Rexster Instance or through the neo4j-rest-client API. Therefore a Neo4j database can be accessed with both options, although the Neo4j transactional mode is only available through the later.
The Rexster instance also provides connection to the following databases:
- TinkerGraph
@@ -42,7 +42,7 @@ Rexster
"""""""
Connecting to a Rexster instance
->>> from pyblueprints import RexsterServer, RexsterGraph
+>>> from pyblueprints import RexsterServer, RexsterGraph, RexsterIndexableGraph
>>> #Connecting to server
>>> HOST = 'http://localhost:8182'
>>> server = RexsterServer(HOST)
@@ -60,11 +60,88 @@ neo4j-rest-client
Creating a graph object through the neo4j-rest-client API
>>> from pyblueprints.neo4j import Neo4jGraph
->>> g = Neo4jGraph('http://localhost:7474/db/data')
+>>> graph = Neo4jGraph('http://localhost:7474/db/data')
Creating an indexable graph object through the neo4j-rest-client API
>>> from pyblueprints.neo4j import Neo4jIndexableGraph
->>> g = Neo4jIndexableGraph('http://localhost:7474/db/data')
-
-
+>>> graph = Neo4jIndexableGraph('http://localhost:7474/db/data')
+
+The available classes are:
+ - Neo4jGraph
+ - Neo4jIndexableGraph
+ - Neo4jTransactionalGraph
+ - Neo4jTransactionalIndexableGraph
+
+
+code examples
+"""""""""""""
+
+Add/Remove Vertex
+'''''''''''''''''
+>>> vertex = graph.addVertex()
+>>> graph.removeVertex(vertex)
+
+Add/Remove Edge
+'''''''''''''''
+>>> v1 = graph.addVertex()
+>>> v2 = graph.addVertex()
+>>> newEdge = graph.addEdge(v1, v2, 'myLabel')
+>>> graph.removeEdge(newEdge)
+
+Vertex Methods
+''''''''''''''
+>>> graph= Neo4jGraph(HOST)
+>>> v1 = graph.addVertex()
+>>> v2 = graph.addVertex()
+>>> newEdge = graph.addEdge(v1, v2, 'myLabel')
+>>> vertex = graph.getVertex(_id)
+>>> # get methods return a generator function
+>>> edge = list(vertex.getBothEdges())[0]
+>>> edge = list(vertex.getOutEdges())[0]
+>>> edges = list(vertex.getInEdges())
+
+Vertex/Edges properties
+'''''''''''''''''''''''
+>>> vertex_id = vertex.getId()
+>>> vertex.setProperty('name', 'paquito')
+>>> print vertex.getPropertyKeys()
+>>> print vertex.getProperty('name')
+>>> vertex.removeProperty('name')
+
+Edge Methods
+''''''''''''
+>>> outVertex = edge.getOutVertex()
+>>> inVertex = edge.getInVertex()
+>>> print getLabel()
+
+Add/Remove Manual Index
+'''''''''''''''''''''''
+>>> index = graph.createManualIndex('myManualIndex', 'vertex')
+>>> graph.dropIndex('myManualIndex', 'vertex')
+
+Index Methods
+'''''''''''''
+>>> index = graph.getIndex('myManualIndex', 'vertex')
+>>> vertex = graph.addVertex()
+>>> index.put('key1', 'value1', vertex)
+>>> print index.count('key1', 'value1')
+>>> print index.getIndexName()
+>>> print index.getIndexClass()
+>>> print index.getIndexType()
+>>> # get returns a generator function
+>>> vertex2 = list(index.get('key1', 'value1'))[0]
+>>> index.remove('key1', 'value1', vertex)
+
+Transactional Methods
+'''''''''''''''''''''
+>>> graph= Neo4jTransactionalGraph(HOST)
+>>> graph.startTransaction()
+>>> v = graph.addVertex()
+# Stoping calls the commit
+>>> graph.stopTransaction()
+>>> vertexId = v.getId()
+>>> v = graph.getVertex(vertexId)
+>>> graph.startTransaction()
+>>> v.setProperty('p1', 'v1')
+>>> graph.stopTransaction()
View
89 README.txt
@@ -16,18 +16,18 @@ This is an experimental version only permitting partial functionality to:
- Rexster infrastructure, supporting every database supported by Rexster (https://github.com/tinkerpop/rexster/)
- Neo4j database providing abstraction over the neo4j-rest-client API.
+Please keep in mind to backup your data before trying this library.
Installation
------------
The easiest way to get pyblueprints installed in your virtualenv is by:
pip install pyblueprints
-
Usage
-----
-This version of pybluerprints allows you to connect to graph databases by a Rexster Instance or through the neo4j-rest-client API. Therefore a Neo4j database can be accessed with both options.
+This version of pybluerprints allows you to connect to graph databases by a Rexster Instance or through the neo4j-rest-client API. Therefore a Neo4j database can be accessed with both options, although the Neo4j transactional mode is only available through the later.
The Rexster instance also provides connection to the following databases:
- TinkerGraph
@@ -58,11 +58,88 @@ neo4j-rest-client
Creating a graph object through the neo4j-rest-client API
>>> from pyblueprints.neo4j import Neo4jGraph
->>> g = Neo4jGraph('http://localhost:7474/db/data')
+>>> graph = Neo4jGraph('http://localhost:7474/db/data')
Creating an indexable graph object through the neo4j-rest-client API
>>> from pyblueprints.neo4j import Neo4jIndexableGraph
->>> g = Neo4jIndexableGraph('http://localhost:7474/db/data')
-
-lease keep in mind to backup your data before trying this library.
+>>> graph = Neo4jIndexableGraph('http://localhost:7474/db/data')
+
+The available classes are:
+ - Neo4jGraph
+ - Neo4jIndexableGraph
+ - Neo4jTransactionalGraph
+ - Neo4jTransactionalIndexableGraph
+
+
+code examples
+"""""""""""""
+
+Add/Remove Vertex
+'''''''''''''''''
+>>> vertex = graph.addVertex()
+>>> graph.removeVertex(vertex)
+
+Add/Remove Edge
+'''''''''''''''
+>>> v1 = graph.addVertex()
+>>> v2 = graph.addVertex()
+>>> newEdge = graph.addEdge(v1, v2, 'myLabel')
+>>> graph.removeEdge(newEdge)
+
+Vertex Methods
+''''''''''''''
+>>> graph= Neo4jGraph(HOST)
+>>> v1 = graph.addVertex()
+>>> v2 = graph.addVertex()
+>>> newEdge = graph.addEdge(v1, v2, 'myLabel')
+>>> vertex = graph.getVertex(_id)
+>>> # get methods return a generator function
+>>> edge = list(vertex.getBothEdges())[0]
+>>> edge = list(vertex.getOutEdges())[0]
+>>> edges = list(vertex.getInEdges())
+
+Vertex/Edges properties
+'''''''''''''''''''''''
+>>> vertex_id = vertex.getId()
+>>> vertex.setProperty('name', 'paquito')
+>>> print vertex.getPropertyKeys()
+>>> print vertex.getProperty('name')
+>>> vertex.removeProperty('name')
+
+Edge Methods
+''''''''''''
+>>> outVertex = edge.getOutVertex()
+>>> inVertex = edge.getInVertex()
+>>> print getLabel()
+
+Add/Remove Manual Index
+'''''''''''''''''''''''
+>>> index = graph.createManualIndex('myManualIndex', 'vertex')
+>>> graph.dropIndex('myManualIndex', 'vertex')
+
+Index Methods
+'''''''''''''
+>>> index = graph.getIndex('myManualIndex', 'vertex')
+>>> vertex = graph.addVertex()
+>>> index.put('key1', 'value1', vertex)
+>>> print index.count('key1', 'value1')
+>>> print index.getIndexName()
+>>> print index.getIndexClass()
+>>> print index.getIndexType()
+>>> # get returns a generator function
+>>> vertex2 = list(index.get('key1', 'value1'))[0]
+>>> index.remove('key1', 'value1', vertex)
+
+Transactional Methods
+'''''''''''''''''''''
+>>> graph= Neo4jTransactionalGraph(HOST)
+>>> graph.startTransaction()
+>>> v = graph.addVertex()
+# Stoping calls the commit
+>>> graph.stopTransaction()
+>>> vertexId = v.getId()
+>>> v = graph.getVertex(vertexId)
+>>> graph.startTransaction()
+>>> v.setProperty('p1', 'v1')
+>>> graph.stopTransaction()

0 comments on commit 8fe8425

Please sign in to comment.