python-3.xneo4jneo4j-driver

How to create a new DB or connect to existing one


I pulled and run neo4j docker:

sudo docker run -p7474:7474 -p7687:7687 -e NEO4J_AUTH=neo4j/s3cr3t neo4j

From python I can connect to it with:

scheme = "neo4j"
host_name = "localhost"
port = 7687
url = "{scheme}://{host_name}:{port}".format(scheme=scheme, host_name=host_name, port=port)
user = "neo4j"
password = "s3cr3t"
driver = GraphDatabase.driver(url, auth=(user, password))

But it seems that there is no API to choose the DB name I want to work with ?


Solution

  • To connect to a specific database, you can pass the database's name as the value of the database keyword argument when you create the Session used for your transactions.

    For example, to create a Session for the database named "foo":

    ...
    driver = GraphDatabase.driver(uri, auth=(user, password))
    session = driver.session(database="foo")
    ...