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.
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.
- executemany(query, seq_of_parameters)[source]¶
Execute a query on this connection once for each parameter set.
- begin()[source]¶
Begin a transaction.
- Raises:
ProgrammingError – if the connection is closed
OperationalError – if the connection is broken or if the transaction fails to begin
- commit()[source]¶
Commit any pending transaction to the database.
- Raises:
ProgrammingError – if the connection is closed
OperationalError – if the connection is broken or if the transaction fails to commit
- rollback()[source]¶
Rollback any pending transaction.
- Raises:
ProgrammingError – if the connection is closed
OperationalError – if the connection is broken or if the transaction fails to rollback
- 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:
ProgrammingError – if the cursor or the connection is closed
OperationalError – if the connection is broken
- executemany(query, seq_of_parameters)[source]¶
Execute query multiple times with different parameter sets.
- Raises:
ProgrammingError – if the cursor or the connection is closed
OperationalError – if the connection is broken
- fetchone()[source]¶
Fetch the next record, if available.
- Returns:
record tuple or
None
- Raises:
ProgrammingError – if the cursor or the connection is closed
OperationalError – if the connection is broken
- fetchmany(size=None)[source]¶
Fetch up to size records.
- Parameters:
size –
- Returns:
list of record tuples
- Raises:
ProgrammingError – if the cursor or the connection is closed
OperationalError – if the connection is broken
- fetchall()[source]¶
Fetch all remaining records.
- Returns:
list of record tuples
- Raises:
ProgrammingError – if the cursor or the connection is closed
OperationalError – if the connection is broken
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.