py2neo.pep249 – Python DB API 2.0 Compatibility

This module provides an implementation of the Python Database API v2.0 (as specified in PEP 249) for Neo4j. The classes here are thin wrappers over the regular py2neo functionality, so will provide a very similar behaviour and experience to the rest of the library.

To get started, create a Connection object using the connect() function:

>>> from py2neo.pep249 import connect
>>> con = connect()

The arguments accepted by this function are identical to those accepted by the Graph class in the core API. Therefore, a URI and any combination of individual settings may be specified.

The Connection object represents a single client-server connection and can maintain a single transaction at any point in time. Transactions are implicitly created through using a method like Cursor.execute() or can be explicitly created using the Connection.begin() method.

Module attributes and functions

py2neo.pep249.apilevel = '2.0'

This module supports version 2.0 of the DB API.

py2neo.pep249.threadsafety = 0

This module is not guaranteed to be thread-safe.

py2neo.pep249.paramstyle = 'cypher'

This module uses the Cypher query language parameter notation. Note that this is not a standard setting according to PEP 249.

py2neo.pep249.connect(profile=None, **settings)[source]

Constructor for creating a connection to the database.

Connection objects

class py2neo.pep249.Connection(profile=None, **settings)[source]

PEP249-compliant connection to a Neo4j server.

in_transaction

True if a transaction is active, False otherwise.

cursor()[source]

Construct a new Cursor object for this connection.

execute(query, parameters=None)[source]

Execute a query on this connection.

executemany(query, seq_of_parameters)[source]

Execute a query on this connection once for each parameter set.

begin()[source]

Begin a transaction.

Raises:
commit()[source]

Commit any pending transaction to the database.

Raises:
rollback()[source]

Rollback any pending transaction.

Raises:
close()[source]

Close the connection immediately.

The connection will be unusable from this point forward; a ProgrammingError exception will be raised if any operation is attempted with the connection. The same applies to all cursor objects trying to use the connection. Note that closing a connection without committing the changes first will cause an implicit rollback to be performed.

Cursor objects

class py2neo.pep249.Cursor(connection)[source]

PEP249-compliant cursor attached to a Neo4j server.

arraysize = 1
connection

Connection to which this cursor is bound.

description

Field details, each represented as a 7-tuple.

rowcount

Number of rows affected by the last query executed.

summary

Dictionary of summary information relating to the last query executed.

execute(query, parameters=None)[source]

Execute a query.

Raises:
executemany(query, seq_of_parameters)[source]

Execute query multiple times with different parameter sets.

Raises:
fetchone()[source]

Fetch the next record, if available.

Returns:

record tuple or None

Raises:
fetchmany(size=None)[source]

Fetch up to size records.

Parameters:

size

Returns:

list of record tuples

Raises:
fetchall()[source]

Fetch all remaining records.

Returns:

list of record tuples

Raises:
close()[source]

Close the cursor immediately.

Exceptions

exception py2neo.pep249.Warning[source]

Exception raised for important warnings like data truncations while inserting, etc.

exception py2neo.pep249.Error[source]

Exception that is the base class of all other error exceptions. You can use this to catch all errors with one single except statement. Warnings are not considered errors and thus should not use this class as base.

exception py2neo.pep249.InterfaceError[source]

Exception raised for errors that are related to the database interface rather than the database itself.

exception py2neo.pep249.DatabaseError[source]

Exception raised for errors that are related to the database.

exception py2neo.pep249.DataError[source]

Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range, etc.

exception py2neo.pep249.OperationalError[source]

Exception raised for errors that are related to the database’s operation and not necessarily under the control of the programmer, e.g. an unexpected disconnect occurs, the data source name is not found, a transaction could not be processed, a memory allocation error occurred during processing, etc.

exception py2neo.pep249.IntegrityError[source]

Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails.

exception py2neo.pep249.InternalError[source]

Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore, the transaction is out of sync, etc.

exception py2neo.pep249.ProgrammingError[source]

Exception raised for programming errors, e.g. table not found or already exists, syntax error in the SQL statement, wrong number of parameters specified, etc.

exception py2neo.pep249.NotSupportedError[source]

Exception raised in case a method or database API was used which is not supported by the database, e.g. requesting a .rollback() on a connection that does not support transaction or has transactions turned off.