Skip to content

Commit

Permalink
Merge pull request #112 from neo4j/1.1-apidocs
Browse files Browse the repository at this point in the history
Updated API docs
  • Loading branch information
nigelsmall authored Dec 14, 2016
2 parents 696f4ef + fdae3e4 commit 2c99079
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 144 deletions.
75 changes: 33 additions & 42 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,66 +1,57 @@
============================
****************************
Neo4j Bolt Driver for Python
============================
****************************


Installation
============

To install the latest stable version, use:

.. code:: bash
pip install neo4j-driver
For the most up-to-date version (possibly unstable), use:

.. code:: bash
pip install git+https://github.com/neo4j/neo4j-python-driver.git#egg=neo4j-driver
The Official Neo4j Driver for Python supports Neo4j 3.0 and above and Python versions 2.7, 3.4 and 3.5.


Example Usage
Quick Example
=============

.. code:: python
.. code-block:: python
from neo4j.v1 import GraphDatabase, basic_auth
driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j", "password"))
uri = "bolt://localhost:7687"
auth_token = basic_auth("neo4j", "password")
driver = GraphDatabase.driver(uri, auth=auth_token)
with driver.session() as session:
def print_friends_of(name):
with driver.session() as session:
with session.begin_transaction() as tx:
for record in tx.run("MATCH (a:Person)-[:KNOWS]->(f) "
"WHERE a.name = {name} "
"RETURN f.name", name=name):
print(record["f.name"])
with session.begin_transaction() as write_tx:
write_tx.run("CREATE (a:Person {name:{name},age:{age}})", name="Alice", age=33)
write_tx.run("CREATE (a:Person {name:{name},age:{age}})", name="Bob", age=44)
print_friends_of("Alice")
with session.begin_transaction() as read_tx:
result = read_tx.run("MATCH (a:Person) RETURN a.name AS name, a.age AS age")
for record in result:
print("%s is %d years old" % (record["name"], record["age"]))
driver.close()
Command Line
Installation
============

To install the latest stable version, use:

.. code:: bash
python -m neo4j "CREATE (a:Person {name:'Alice'}) RETURN a, labels(a), a.name"
pip install neo4j-driver
For the most up-to-date version (possibly unstable), use:

.. code:: bash
Documentation
=============
pip install git+https://github.com/neo4j/neo4j-python-driver.git#egg=neo4j-driver
For more information such as manual, driver API documentations, changelogs, please find them in the wiki of this repo.
* `Driver Wiki`_
Other Information
=================

* `Neo4j Manual`_
* `Neo4j Refcard`_
* `Sample Project Using Driver`_
* `Neo4j Quick Reference Card`_
* `Example Project`_
* `Driver Wiki`_ (includes change logs)

.. _`Sample Project Using Driver`: https://github.com/neo4j-examples/movies-python-bolt
.. _`Driver Wiki`: https://github.com/neo4j/neo4j-python-driver/wiki
.. _`Neo4j Manual`: https://neo4j.com/docs/
.. _`Neo4j Refcard`: https://neo4j.com/docs/cypher-refcard/current/
.. _`Neo4j Quick Reference Card`: https://neo4j.com/docs/cypher-refcard/current/
.. _`Example Project`: https://github.com/neo4j-examples/movies-python-bolt
.. _`Driver Wiki`: https://github.com/neo4j/neo4j-python-driver/wiki
46 changes: 46 additions & 0 deletions docs/source/driver.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
**************
Driver Objects
**************

A `Driver` object holds the detail of a Neo4j database including server URIs, credentials and other configuration.
It also manages a pool of connections which are used to power :class:`.Session` instances.

The scheme of the URI passed to the `Driver` constructor determines the type of `Driver` object constructed.
Two types are currently available: the :class:`.DirectDriver` and the :class:`.RoutingDriver`.
These are described in more detail below.


.. autoclass:: neo4j.v1.GraphDatabase
:members:

.. autoclass:: neo4j.v1.DirectDriver
:members:
:inherited-members:

.. autoclass:: neo4j.v1.RoutingDriver
:members:
:inherited-members:

.. autoclass:: neo4j.v1.AuthToken
:members:

.. autofunction:: neo4j.v1.basic_auth

.. autofunction:: neo4j.v1.custom_auth


Encryption Settings
-------------------
.. py:attribute:: neo4j.v1.ENCRYPTION_OFF
.. py:attribute:: neo4j.v1.ENCRYPTION_ON
.. py:attribute:: neo4j.v1.ENCRYPTION_DEFAULT
Trust Settings
--------------
.. py:attribute:: neo4j.v1.TRUST_ON_FIRST_USE
.. py:attribute:: neo4j.v1.TRUST_SIGNED_CERTIFICATES
.. py:attribute:: neo4j.v1.TRUST_ALL_CERTIFICATES
.. py:attribute:: neo4j.v1.TRUST_CUSTOM_CA_SIGNED_CERTIFICATES
.. py:attribute:: neo4j.v1.TRUST_SYSTEM_CA_SIGNED_CERTIFICATES
.. py:attribute:: neo4j.v1.TRUST_DEFAULT
119 changes: 43 additions & 76 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -1,101 +1,68 @@
============================
****************************
Neo4j Bolt Driver for Python
============================
****************************

.. toctree::
:maxdepth: 2


Session API
===========

.. autoclass:: neo4j.v1.GraphDatabase
:members:

.. autoclass:: neo4j.v1.Driver
:members:

.. autoclass:: neo4j.v1.Session
:members:

.. autoclass:: neo4j.v1.Transaction
:members:

.. autoclass:: neo4j.v1.Record
:members:

.. autoclass:: neo4j.v1.StatementResult
:members:
The Official Neo4j Driver for Python supports Neo4j 3.0 and above and Python versions 2.7, 3.4 and 3.5.


Encryption Settings
-------------------
.. py:attribute:: neo4j.v1.ENCRYPTION_OFF
.. py:attribute:: neo4j.v1.ENCRYPTION_ON
.. py:attribute:: neo4j.v1.ENCRYPTION_NON_LOCAL
.. py:attribute:: neo4j.v1.ENCRYPTION_DEFAULT
Quick Example
=============

.. code-block:: python
Trust Settings
--------------
.. py:attribute:: neo4j.v1.TRUST_ON_FIRST_USE
.. py:attribute:: neo4j.v1.TRUST_SIGNED_CERTIFICATES
.. py:attribute:: neo4j.v1.TRUST_DEFAULT
Query Summary Details
---------------------

.. autoclass:: neo4j.v1.summary.ResultSummary
:members:

.. autoclass:: neo4j.v1.summary.SummaryCounters
:members:
from neo4j.v1 import GraphDatabase, basic_auth
uri = "bolt://localhost:7687"
auth_token = basic_auth("neo4j", "password")
driver = GraphDatabase.driver(uri, auth=auth_token)
Exceptions
==========
def print_friends_of(name):
with driver.session() as session:
with session.begin_transaction() as tx:
for record in tx.run("MATCH (a:Person)-[:KNOWS]->(f) "
"WHERE a.name = {name} "
"RETURN f.name", name=name):
print(record["f.name"])
.. autoclass:: neo4j.v1.ProtocolError
:members:
print_friends_of("Alice")
.. autoclass:: neo4j.v1.CypherError
:members:
.. autoclass:: neo4j.v1.ResultError
:members:
Installation
============

To install the latest stable version, use:

Example
=======
.. code:: bash
.. code-block:: python
pip install neo4j-driver
from neo4j.v1 import GraphDatabase, basic_auth
For the most up-to-date version (possibly unstable), use:

driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j", "password"))
.. code:: bash
with driver.session() as session:
pip install git+https://github.com/neo4j/neo4j-python-driver.git#egg=neo4j-driver
with session.begin_transaction() as tx:
session.run("MERGE (a:Person {name:'Alice'})")
friends = ["Bob", "Carol", "Dave", "Eve", "Frank"]
with session.begin_transaction() as tx:
for friend in friends:
tx.run("MATCH (a:Person {name:'Alice'}) "
"MERGE (a)-[:KNOWS]->(x:Person {name:{n}})", {"n": friend})
API Documentation
=================

for record in session.run("MATCH (a:Person {name:'Alice'})-[:KNOWS]->(friend) RETURN friend"):
print('Alice says, "hello, %s"' % record["friend"]["name"])
.. toctree::
:maxdepth: 1

driver.close()
driver
session
types


Indices and tables
==================
Other Information
=================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
* `Neo4j Manual`_
* `Neo4j Quick Reference Card`_
* `Example Project`_
* `Driver Wiki`_ (includes change logs)

.. _`Neo4j Manual`: https://neo4j.com/docs/
.. _`Neo4j Quick Reference Card`: https://neo4j.com/docs/cypher-refcard/current/
.. _`Example Project`: https://github.com/neo4j-examples/movies-python-bolt
.. _`Driver Wiki`: https://github.com/neo4j/neo4j-python-driver/wiki
51 changes: 51 additions & 0 deletions docs/source/session.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
***************
Cypher Sessions
***************


.. autoclass:: neo4j.v1.Session
:members:

.. autoclass:: neo4j.v1.Transaction
:members:

.. autoclass:: neo4j.v1.StatementResult
:members:

.. autoclass:: neo4j.v1.Record
:members:


Summary Details
---------------

.. autoclass:: neo4j.v1.summary.ResultSummary
:members:

.. autoclass:: neo4j.v1.summary.SummaryCounters
:members:


Exceptions
----------

.. autoclass:: neo4j.v1.ProtocolError
:members:

.. autoclass:: neo4j.v1.Unauthorized
:members:

.. autoclass:: neo4j.v1.CypherError
:members:

.. autoclass:: neo4j.v1.TransactionError
:members:

.. autoclass:: neo4j.v1.ResultError
:members:

.. autoclass:: neo4j.v1.ServiceUnavailable
:members:

.. autoclass:: neo4j.v1.SessionExpired
:members:
16 changes: 16 additions & 0 deletions docs/source/types.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
***********
Type System
***********


.. autoclass:: neo4j.v1.Node
:members:
:inherited-members:

.. autoclass:: neo4j.v1.Relationship
:members:
:inherited-members:

.. autoclass:: neo4j.v1.Path
:members:
:inherited-members:
5 changes: 2 additions & 3 deletions neo4j/v1/bolt.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
the `session` module provides the main user-facing abstractions.
"""


from __future__ import division

from base64 import b64encode
Expand All @@ -36,13 +35,13 @@
from os.path import dirname, isfile
from select import select
from socket import create_connection, SHUT_RDWR, error as SocketError
from struct import pack as struct_pack, unpack as struct_unpack, unpack_from as struct_unpack_from
from struct import pack as struct_pack, unpack as struct_unpack
from threading import RLock

from .compat.ssl import SSL_AVAILABLE, HAS_SNI, SSLError
from .constants import DEFAULT_USER_AGENT, KNOWN_HOSTS, MAGIC_PREAMBLE, TRUST_DEFAULT, TRUST_ON_FIRST_USE
from .exceptions import ProtocolError, Unauthorized, ServiceUnavailable
from .packstream import Packer, Unpacker
from .ssl_compat import SSL_AVAILABLE, HAS_SNI, SSLError


# Signature bytes for each message type
Expand Down
2 changes: 2 additions & 0 deletions neo4j/v1/ssl_compat.py → neo4j/v1/compat/ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import

try:
from ssl import SSLContext, PROTOCOL_SSLv23, OP_NO_SSLv2, CERT_REQUIRED, HAS_SNI, SSLError
except ImportError:
Expand Down
Loading

0 comments on commit 2c99079

Please sign in to comment.