{"__v":1,"_id":"57d6af7d46dcc30e007dd160","category":{"__v":0,"_id":"57d6ada046dcc30e007dd15e","project":"566c97797831040d003eb3bc","version":"566c97797831040d003eb3bf","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-09-12T13:29:04.136Z","from_sync":false,"order":8,"slug":"drivers-and-languages","title":"Language center"},"parentDoc":null,"project":"566c97797831040d003eb3bc","user":"5716283e40ef9c2000cac92a","version":{"__v":10,"_id":"566c97797831040d003eb3bf","project":"566c97797831040d003eb3bc","createdAt":"2015-12-12T21:54:01.970Z","releaseDate":"2015-12-12T21:54:01.970Z","categories":["566c977a7831040d003eb3c0","5716338cb5af590e00a0ff1d","57163947893cbe0e002d75fc","57163f41b5af590e00a0ff35","57cd74d2873de50e00724a2f","57cd7de8baaee30e0093ecc3","57d6ada046dcc30e007dd15e","57fdc2b31646dc0e0010480a","57fdd8b86c9d141900d87bf1","58767da4d89ef20f003b6f1e"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-09-12T13:37:01.377Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":5,"body":"If Python is your language of choice, the most popular drivers are:\n\n* [Neo4j Python driver](#section-neo4j-bolt-driver-for-python) [official driver]\n* [Py2Neo](##section-py2neo-v3) [community driver]\n* [Neo4j Rest client](#section-neo4j-rest-client) [community driver]\n\nThe easiest way to install the Python drivers for Neo4j is via PyPI (Python Package Index). You’ll find more information and installation instructions here: https://pip.pypa.io/en/latest/installing/\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"We've used test credentials for all the following examples. Please replace them with your real connection parameters.\\n\\nYou'll find all the required information to connect to your database on our admin panel if you navigate to the Connection section. More on connecting to your database [here](doc:connecting-to-your-database)\",\n  \"title\": \"About connection parameters\"\n}\n[/block]\n## Neo4j Bolt driver for Python\n\nThe Neo4j Python driver is the one officially supported by Neo4j and connects to the database using Bolt protocol (HTTP/HTTPS not available).\n\nDriver web page: https://github.com/neo4j/neo4j-python-driver\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"**Bolt protocol is available in 3.0.0 or higher versions of Neo4j.** You can check your Neo4j version if you navigate to the Overview page of your database.\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Attention\",\n  \"body\": \"**GrapheneDB only accepts Bolt connections over TLS (1.1 and 1.2).**\\nBolt over TLS is only available in Python 2.7.9+ and Python 3.3+.\"\n}\n[/block]\nInstalling via Python Package Index (PyPI):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ pip install neo4j-driver\",\n      \"language\": \"shell\",\n      \"name\": \"\"\n    }\n  ]\n}\n[/block]\nSetting up the connection:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"from neo4j.v1 import GraphDatabase, basic_auth\\n\\n\\ndriver = GraphDatabase.driver(\\\"bolt://hobby-geefdaeefcom.dbs.graphenedb.com:24786\\\", auth=basic_auth(\\\"v303\\\", \\\"GtGq5rldxu\\\"))\",\n      \"language\": \"python\"\n    }\n  ]\n}\n[/block]\nYou can test the connection by creating a dummy node:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"session = driver.session()\\n\\n\\nsession.run(\\\"CREATE (n:Person {name:'Bob'})\\\")\\nresult = session.run(\\\"MATCH (n:Person) RETURN n.name AS name\\\")\\nfor record in result:\\n    print(record[\\\"name\\\"])\\nsession.close()\",\n      \"language\": \"python\"\n    }\n  ]\n}\n[/block]\n## Py2Neo v3\n\nPy2neo is a Neo4j community driver. It is a client library and toolkit for working with Neo4j from within Python applications and from the command line.\n\nPy2Neo documentation: http://py2neo.org/v3/\n\nInstalling via Python Package Index (PyPI):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ pip install py2neo\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Attention\",\n  \"body\": \"Since v3 supports Bolt protocol, the Bolt port has to be specified. If not using Bolt, you can specify HTTP/HTTPS instead .\"\n}\n[/block]\nSetting up the **HTTP** or **HTTPS** connection:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"from py2neo import Graph, authenticate\\n\\nauthenticate(\\\"hobby-geefdaeefcom.dbs.graphenedb.com:24789\\\", \\\"v303\\\", \\\"GtGq5rldxu\\\")\\ngraph = Graph(\\\"http://hobby-geefdaeefcom.dbs.graphenedb.com:24789\\\", bolt = False)\",\n      \"language\": \"python\"\n    }\n  ]\n}\n[/block]\nSetting up the **Bolt/TLS** connection:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"from py2neo import Graph\\ngraph = Graph(\\\"bolt://hobby-geefdaeefcom.dbs.graphenedb.com:24786\\\", user=\\\"v303\\\", password=\\\"GtGq5rldxu\\\", bolt=True, secure = True, http_port = 24789, https_port = 24780)\",\n      \"language\": \"python\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Attention\",\n  \"body\": \"Note that either HTTP or HTTPS must be enabled to allow for discovery and for some legacy features to be supported.\"\n}\n[/block]\nYou can test the connection by creating a dummy node:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"graph.run(\\\"CREATE (n:Person {name:'Bob'})\\\")\\nresult = graph.run(\\\"MATCH (n:Person) RETURN n\\\")\\nfor record in result:\\n    print(record)\",\n      \"language\": \"python\"\n    }\n  ]\n}\n[/block]\n## Neo4j Rest Client\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Please note\",\n  \"body\": \"This driver doesn’t support the new binary Bolt protocol.\"\n}\n[/block]\nNeo4j Rest Client is a Neo4j community driver. This driver enables Python programmers already using Neo4j locally through python-embedded, to use the Neo4j REST server. \n\nNeo4j Rest Client documentation page: http://neo4j-rest-client.readthedocs.io/en/latest/\n\nInstalling via Python Package Index (PyPI):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ pip install neo4jrestclient\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nSetting up the connection:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"from neo4jrestclient.client import GraphDatabase\\n\\n\\ngdb = GraphDatabase(“http://hobby-geefdaeefcom.dbs.graphenedb.com:24789/db/data/”, username = “v303”, password = ”GtGq5rldxu”)\",\n      \"language\": \"python\"\n    }\n  ]\n}\n[/block]\nTest the connection by querying the database:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"gdb.query(\\\"CREATE (n:Person {name:'Bob'})\\\")\\nresult = gdb.query(\\\"MATCH (n:Person) RETURN n LIMIT 1\\\")\\nfor record in result:\\n    print(record)\",\n      \"language\": \"python\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"python","type":"basic","title":"Python"}
If Python is your language of choice, the most popular drivers are: * [Neo4j Python driver](#section-neo4j-bolt-driver-for-python) [official driver] * [Py2Neo](##section-py2neo-v3) [community driver] * [Neo4j Rest client](#section-neo4j-rest-client) [community driver] The easiest way to install the Python drivers for Neo4j is via PyPI (Python Package Index). You’ll find more information and installation instructions here: https://pip.pypa.io/en/latest/installing/ [block:callout] { "type": "info", "body": "We've used test credentials for all the following examples. Please replace them with your real connection parameters.\n\nYou'll find all the required information to connect to your database on our admin panel if you navigate to the Connection section. More on connecting to your database [here](doc:connecting-to-your-database)", "title": "About connection parameters" } [/block] ## Neo4j Bolt driver for Python The Neo4j Python driver is the one officially supported by Neo4j and connects to the database using Bolt protocol (HTTP/HTTPS not available). Driver web page: https://github.com/neo4j/neo4j-python-driver [block:callout] { "type": "info", "body": "**Bolt protocol is available in 3.0.0 or higher versions of Neo4j.** You can check your Neo4j version if you navigate to the Overview page of your database." } [/block] [block:callout] { "type": "warning", "title": "Attention", "body": "**GrapheneDB only accepts Bolt connections over TLS (1.1 and 1.2).**\nBolt over TLS is only available in Python 2.7.9+ and Python 3.3+." } [/block] Installing via Python Package Index (PyPI): [block:code] { "codes": [ { "code": "$ pip install neo4j-driver", "language": "shell", "name": "" } ] } [/block] Setting up the connection: [block:code] { "codes": [ { "code": "from neo4j.v1 import GraphDatabase, basic_auth\n\n\ndriver = GraphDatabase.driver(\"bolt://hobby-geefdaeefcom.dbs.graphenedb.com:24786\", auth=basic_auth(\"v303\", \"GtGq5rldxu\"))", "language": "python" } ] } [/block] You can test the connection by creating a dummy node: [block:code] { "codes": [ { "code": "session = driver.session()\n\n\nsession.run(\"CREATE (n:Person {name:'Bob'})\")\nresult = session.run(\"MATCH (n:Person) RETURN n.name AS name\")\nfor record in result:\n print(record[\"name\"])\nsession.close()", "language": "python" } ] } [/block] ## Py2Neo v3 Py2neo is a Neo4j community driver. It is a client library and toolkit for working with Neo4j from within Python applications and from the command line. Py2Neo documentation: http://py2neo.org/v3/ Installing via Python Package Index (PyPI): [block:code] { "codes": [ { "code": "$ pip install py2neo", "language": "shell" } ] } [/block] [block:callout] { "type": "warning", "title": "Attention", "body": "Since v3 supports Bolt protocol, the Bolt port has to be specified. If not using Bolt, you can specify HTTP/HTTPS instead ." } [/block] Setting up the **HTTP** or **HTTPS** connection: [block:code] { "codes": [ { "code": "from py2neo import Graph, authenticate\n\nauthenticate(\"hobby-geefdaeefcom.dbs.graphenedb.com:24789\", \"v303\", \"GtGq5rldxu\")\ngraph = Graph(\"http://hobby-geefdaeefcom.dbs.graphenedb.com:24789\", bolt = False)", "language": "python" } ] } [/block] Setting up the **Bolt/TLS** connection: [block:code] { "codes": [ { "code": "from py2neo import Graph\ngraph = Graph(\"bolt://hobby-geefdaeefcom.dbs.graphenedb.com:24786\", user=\"v303\", password=\"GtGq5rldxu\", bolt=True, secure = True, http_port = 24789, https_port = 24780)", "language": "python" } ] } [/block] [block:callout] { "type": "warning", "title": "Attention", "body": "Note that either HTTP or HTTPS must be enabled to allow for discovery and for some legacy features to be supported." } [/block] You can test the connection by creating a dummy node: [block:code] { "codes": [ { "code": "graph.run(\"CREATE (n:Person {name:'Bob'})\")\nresult = graph.run(\"MATCH (n:Person) RETURN n\")\nfor record in result:\n print(record)", "language": "python" } ] } [/block] ## Neo4j Rest Client [block:callout] { "type": "info", "title": "Please note", "body": "This driver doesn’t support the new binary Bolt protocol." } [/block] Neo4j Rest Client is a Neo4j community driver. This driver enables Python programmers already using Neo4j locally through python-embedded, to use the Neo4j REST server. Neo4j Rest Client documentation page: http://neo4j-rest-client.readthedocs.io/en/latest/ Installing via Python Package Index (PyPI): [block:code] { "codes": [ { "code": "$ pip install neo4jrestclient", "language": "shell" } ] } [/block] Setting up the connection: [block:code] { "codes": [ { "code": "from neo4jrestclient.client import GraphDatabase\n\n\ngdb = GraphDatabase(“http://hobby-geefdaeefcom.dbs.graphenedb.com:24789/db/data/”, username = “v303”, password = ”GtGq5rldxu”)", "language": "python" } ] } [/block] Test the connection by querying the database: [block:code] { "codes": [ { "code": "gdb.query(\"CREATE (n:Person {name:'Bob'})\")\nresult = gdb.query(\"MATCH (n:Person) RETURN n LIMIT 1\")\nfor record in result:\n print(record)", "language": "python" } ] } [/block]