new_contents: #!/usr/bin/env python
  # -*- encoding: utf-8 -*-
  
  # Copyright (c) 2002-2018 "Neo Technology,"
  # Network Engine for Objects in Lund AB [http://neotechnology.com]
  #
  # This file is part of Neo4j.
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #     http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  # tag:pass-bookmarks-import[]
  from neo4j.v1 import GraphDatabase
  # end::pass-bookmarks-import[]
  
  
  # tag::pass-bookmarks[]
  class BookmarksExample(object):
  
      def __init__(self, uri, user, password):
          self._driver = GraphDatabase.driver(uri, auth=(user, password))
  
      def close(self):
          self._driver.close()
  
      # Create a person node.
      @classmethod
      def create_person(cls, tx, name):
          tx.run("CREATE (:Person {name: $name})", name=name)
  
      # Create an employment relationship to a pre-existing company node.
      # This relies on the person first having been created.
      @classmethod
      def employ(cls, tx, person_name, company_name):
          tx.run("MATCH (person:Person {name: $person_name}) "
                 "MATCH (company:Company {name: $company_name}) "
                 "CREATE (person)-[:WORKS_FOR]->(company)",
                 person_name=person_name, company_name=company_name)
  
      # Create a friendship between two people.
      @classmethod
      def create_friendship(cls, tx, name_a, name_b):
          tx.run("MATCH (a:Person {name: $name_a}) "
                 "MATCH (b:Person {name: $name_b}) "
                 "MERGE (a)-[:KNOWS]->(b)",
                 name_a=name_a, name_b=name_b)
  
      # Match and display all friendships.
      @classmethod
      def print_friendships(cls, tx):
          result = tx.run("MATCH (a)-[:KNOWS]->(b) RETURN a.name, b.name")
          for record in result:
              print("{} knows {}".format(record["a.name"] ,record["b.name"]))
  
      def main(self):
          saved_bookmarks = []  # To collect the session bookmarks
  
          # Create the first person and employment relationship.
          with self._driver.session() as session_a:
              session_a.write_transaction(self.create_person, "Alice")
              session_a.write_transaction(self.employ, "Alice", "Wayne Enterprises")
              saved_bookmarks.append(session_a.last_bookmark())
  
          # Create the second person and employment relationship.
          with self._driver.session() as session_b:
              session_b.write_transaction(self.create_person, "Bob")
              session_b.write_transaction(self.employ, "Bob", "LexCorp")
              saved_bookmarks.append(session_b.last_bookmark())
  
          # Create a friendship between the two people created above.
          with self._driver.session(bookmarks=saved_bookmarks) as session_c:
              session_c.write_transaction(self.create_friendship, "Alice", "Bob")
              session_c.read_transaction(self.print_friendships)
  
  # end::pass-bookmarks[]
  
subject: Create bookmarks_example.py