Skip to content

Commit fdae3e4

Browse files
committed
Updated index/readme
1 parent 2752a17 commit fdae3e4

File tree

4 files changed

+87
-65
lines changed

4 files changed

+87
-65
lines changed

README.rst

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,57 @@
1-
============================
1+
****************************
22
Neo4j Bolt Driver for Python
3-
============================
3+
****************************
44

5-
6-
Installation
7-
============
8-
9-
To install the latest stable version, use:
10-
11-
.. code:: bash
12-
13-
pip install neo4j-driver
14-
15-
For the most up-to-date version (possibly unstable), use:
16-
17-
.. code:: bash
18-
19-
pip install git+https://github.com/neo4j/neo4j-python-driver.git#egg=neo4j-driver
5+
The Official Neo4j Driver for Python supports Neo4j 3.0 and above and Python versions 2.7, 3.4 and 3.5.
206

217

22-
Example Usage
8+
Quick Example
239
=============
2410

25-
.. code:: python
11+
.. code-block:: python
2612
2713
from neo4j.v1 import GraphDatabase, basic_auth
2814
29-
driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j", "password"))
15+
uri = "bolt://localhost:7687"
16+
auth_token = basic_auth("neo4j", "password")
17+
driver = GraphDatabase.driver(uri, auth=auth_token)
3018
31-
with driver.session() as session:
19+
def print_friends_of(name):
20+
with driver.session() as session:
21+
with session.begin_transaction() as tx:
22+
for record in tx.run("MATCH (a:Person)-[:KNOWS]->(f) "
23+
"WHERE a.name = {name} "
24+
"RETURN f.name", name=name):
25+
print(record["f.name"])
3226
33-
with session.begin_transaction() as write_tx:
34-
write_tx.run("CREATE (a:Person {name:{name},age:{age}})", name="Alice", age=33)
35-
write_tx.run("CREATE (a:Person {name:{name},age:{age}})", name="Bob", age=44)
27+
print_friends_of("Alice")
3628
37-
with session.begin_transaction() as read_tx:
38-
result = read_tx.run("MATCH (a:Person) RETURN a.name AS name, a.age AS age")
39-
for record in result:
40-
print("%s is %d years old" % (record["name"], record["age"]))
4129
42-
driver.close()
43-
44-
45-
Command Line
30+
Installation
4631
============
4732

33+
To install the latest stable version, use:
34+
4835
.. code:: bash
4936
50-
python -m neo4j "CREATE (a:Person {name:'Alice'}) RETURN a, labels(a), a.name"
37+
pip install neo4j-driver
38+
39+
For the most up-to-date version (possibly unstable), use:
5140

41+
.. code:: bash
5242
53-
Documentation
54-
=============
43+
pip install git+https://github.com/neo4j/neo4j-python-driver.git#egg=neo4j-driver
5544
56-
For more information such as manual, driver API documentations, changelogs, please find them in the wiki of this repo.
5745
58-
* `Driver Wiki`_
46+
Other Information
47+
=================
48+
5949
* `Neo4j Manual`_
60-
* `Neo4j Refcard`_
61-
* `Sample Project Using Driver`_
50+
* `Neo4j Quick Reference Card`_
51+
* `Example Project`_
52+
* `Driver Wiki`_ (includes change logs)
6253

63-
.. _`Sample Project Using Driver`: https://github.com/neo4j-examples/movies-python-bolt
64-
.. _`Driver Wiki`: https://github.com/neo4j/neo4j-python-driver/wiki
6554
.. _`Neo4j Manual`: https://neo4j.com/docs/
66-
.. _`Neo4j Refcard`: https://neo4j.com/docs/cypher-refcard/current/
55+
.. _`Neo4j Quick Reference Card`: https://neo4j.com/docs/cypher-refcard/current/
56+
.. _`Example Project`: https://github.com/neo4j-examples/movies-python-bolt
57+
.. _`Driver Wiki`: https://github.com/neo4j/neo4j-python-driver/wiki

docs/source/index.rst

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,49 @@
22
Neo4j Bolt Driver for Python
33
****************************
44

5+
The Official Neo4j Driver for Python supports Neo4j 3.0 and above and Python versions 2.7, 3.4 and 3.5.
6+
7+
8+
Quick Example
9+
=============
10+
511
.. code-block:: python
612
713
from neo4j.v1 import GraphDatabase, basic_auth
814
9-
driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j", "password"))
15+
uri = "bolt://localhost:7687"
16+
auth_token = basic_auth("neo4j", "password")
17+
driver = GraphDatabase.driver(uri, auth=auth_token)
18+
19+
def print_friends_of(name):
20+
with driver.session() as session:
21+
with session.begin_transaction() as tx:
22+
for record in tx.run("MATCH (a:Person)-[:KNOWS]->(f) "
23+
"WHERE a.name = {name} "
24+
"RETURN f.name", name=name):
25+
print(record["f.name"])
26+
27+
print_friends_of("Alice")
28+
29+
30+
Installation
31+
============
32+
33+
To install the latest stable version, use:
1034

11-
with driver.session() as session:
35+
.. code:: bash
1236
13-
with session.begin_transaction() as tx:
14-
session.run("MERGE (a:Person {name:'Alice'})")
37+
pip install neo4j-driver
1538
16-
friends = ["Bob", "Carol", "Dave", "Eve", "Frank"]
17-
with session.begin_transaction() as tx:
18-
for friend in friends:
19-
tx.run("MATCH (a:Person {name:'Alice'}) "
20-
"MERGE (a)-[:KNOWS]->(x:Person {name:{n}})", {"n": friend})
39+
For the most up-to-date version (possibly unstable), use:
2140

22-
for record in session.run("MATCH (a:Person {name:'Alice'})-[:KNOWS]->(friend) RETURN friend"):
23-
print('Alice says, "hello, %s"' % record["friend"]["name"])
41+
.. code:: bash
2442
25-
driver.close()
43+
pip install git+https://github.com/neo4j/neo4j-python-driver.git#egg=neo4j-driver
2644
2745
28-
Contents
29-
========
46+
API Documentation
47+
=================
3048

3149
.. toctree::
3250
:maxdepth: 1
@@ -36,10 +54,15 @@ Contents
3654
types
3755

3856

39-
Indices and tables
40-
==================
57+
Other Information
58+
=================
4159

42-
* :ref:`genindex`
43-
* :ref:`modindex`
44-
* :ref:`search`
60+
* `Neo4j Manual`_
61+
* `Neo4j Quick Reference Card`_
62+
* `Example Project`_
63+
* `Driver Wiki`_ (includes change logs)
4564

65+
.. _`Neo4j Manual`: https://neo4j.com/docs/
66+
.. _`Neo4j Quick Reference Card`: https://neo4j.com/docs/cypher-refcard/current/
67+
.. _`Example Project`: https://github.com/neo4j-examples/movies-python-bolt
68+
.. _`Driver Wiki`: https://github.com/neo4j/neo4j-python-driver/wiki

neo4j/v1/session.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ class Driver(object):
162162
def __init__(self, pool):
163163
self.pool = pool
164164

165+
def __del__(self):
166+
self.close()
167+
165168
def __enter__(self):
166169
return self
167170

@@ -179,6 +182,7 @@ def session(self, access_mode=None):
179182
def close(self):
180183
if self.pool:
181184
self.pool.close()
185+
self.pool = None
182186

183187

184188
class DirectDriver(Driver):

test/test_session.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,12 @@ def test_record_repr(self):
354354

355355
class ExplicitTransactionTestCase(ServerTestCase):
356356

357+
def setUp(self):
358+
self.driver = GraphDatabase.driver(BOLT_URI, auth=AUTH_TOKEN)
359+
357360
def test_can_commit_transaction(self):
358-
with GraphDatabase.driver(BOLT_URI, auth=AUTH_TOKEN).session() as session:
361+
362+
with self.driver.session() as session:
359363
tx = session.begin_transaction()
360364

361365
# Create a node
@@ -378,7 +382,7 @@ def test_can_commit_transaction(self):
378382
assert value == "bar"
379383

380384
def test_can_rollback_transaction(self):
381-
with GraphDatabase.driver(BOLT_URI, auth=AUTH_TOKEN).session() as session:
385+
with self.driver.session() as session:
382386
tx = session.begin_transaction()
383387

384388
# Create a node
@@ -399,7 +403,7 @@ def test_can_rollback_transaction(self):
399403
assert len(list(result)) == 0
400404

401405
def test_can_commit_transaction_using_with_block(self):
402-
with GraphDatabase.driver(BOLT_URI, auth=AUTH_TOKEN).session() as session:
406+
with self.driver.session() as session:
403407
with session.begin_transaction() as tx:
404408
# Create a node
405409
result = tx.run("CREATE (a) RETURN id(a)")
@@ -421,7 +425,7 @@ def test_can_commit_transaction_using_with_block(self):
421425
assert value == "bar"
422426

423427
def test_can_rollback_transaction_using_with_block(self):
424-
with GraphDatabase.driver(BOLT_URI, auth=AUTH_TOKEN).session() as session:
428+
with self.driver.session() as session:
425429
with session.begin_transaction() as tx:
426430
# Create a node
427431
result = tx.run("CREATE (a) RETURN id(a)")

0 commit comments

Comments
 (0)