Python driver

This section presents the breaking changes between the Neo4j 1.7 Python driver and 4.x Python driver.

The latest version of the Python driver for Neo4j can be found on the Python driver’s official page.

1.7 Change 4.x

max_retry_time

Renamed configuration

max_transaction_retry_time

access_mode

Renamed configuration and it is now a keyword argument

default_access_mode

neo4j.exceptions.CypherError

Renamed exception

neo4j.exceptions.Neo4jError

neo4j.exceptions.ConnectionExpired

Removed exception

-

transaction.success

Removed flag

-

Result.value(item=0, default=None)

neo4j.Record. helper function has changed parameter name from `item to key.

Result.value(key=0, default=None)

Result.values(*items)

neo4j.Record helper function has changed parameter name from items to keys.

Result.values(*keys)

Result.data(*items)

neo4j.Record helper function has changed parameter name from items to keys.

Result.data(*keys)

neobolt

No longer a dependency

-

neotime

No longer a dependency

-

Is now a dependency

pytz

Transaction.sync()

Removed

Use Result.consume() if the behavior is to exhaust the result object.

Transaction.success

Removed

-

Transaction.close()

Change in behavior, will only perform rollback if no commit has been performed.

Transaction.close()

Session.sync()`

Removed

Use Result.consume() if the behavior is to exhaust the result object.

Session.detach()

Removed

Use Result.consume() if the behavior is to exhaust the result object.

Session.next_bookmarks()

Removed

-

Session.has_transaction()

Removed

-

Session.closed()

Removed

-

Example 1. Example of changes between the 1.7 Python driver and the 4.0 Python driver
Example code for the 4.0 Python driver Example code for the 1.7 Python driver
driver = GraphDatabase.driver(
    uri, auth=(user, password),
    max_transaction_retry_time=120
)
def create_and_return_greeting(tx,
                               message):
    result = tx.run(
        "CREATE (a:Greeting) "
        "SET a.message = $message "
        "RETURN a.message + "
        "', from node ' + id(a)",
        message=message
    )
    return result.single()[0]
with driver.session() as session:
    greeting = session.write_transaction(
        create_and_return_greeting,
        "Hello World"
    )
    print(greeting)
driver = GraphDatabase.driver(
    uri, auth=(user, password),
    max_retry_time=120
)
def create_and_return_greeting(tx,
                               message):
    result = tx.run(
        "CREATE (a:Greeting) "
        "SET a.message = $message "
        "RETURN a.message + "
        "', from node ' + id(a)",
        message=message
    )
    return result.single()[0]
with driver.session() as session:
    greeting = session.write_transaction(
        create_and_return_greeting,
        "Hello World"
    )
    print(greeting)