{ "cells": [ { "cell_type": "markdown", "id": "2de103b2-9f26-4c67-b97b-8907807a847a", "metadata": {}, "source": [ "## Print out misc. info about the system, and test the connection to the Neo4j database\n", "You will be prompted for your database credentials" ] }, { "cell_type": "code", "execution_count": 1, "id": "f6511c28-84fa-45bf-ae93-17990e5baf4a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Added 'D:\\Docs\\- MY CODE\\Brain Annex\\BA-Win7' to sys.path\n" ] } ], "source": [ "import set_path # Importing this module will add the project's home directory to sys.path" ] }, { "cell_type": "code", "execution_count": 2, "id": "e00686a6-c019-414e-92be-a44d32cfe138", "metadata": {}, "outputs": [], "source": [ "import os\n", "import sys\n", "import getpass\n", "\n", "from neoaccess import NeoAccess" ] }, { "cell_type": "code", "execution_count": 3, "id": "0bfca9e9-2785-42b5-9c7d-04451495f7e5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "*** SOME DIAGNOSTIC VALUES: ***\n", "\n", "sys.executable: D:\\Docs\\- MY CODE\\Brain Annex\\BA-Win7\\venv\\Scripts\\python.exe\n", "\n", "cwd: D:\\Docs\\- MY CODE\\Brain Annex\\BA-Win7\\notebooks\n", "\n", "sys.path using separate lines: \n", " D:\\Docs\\- MY CODE\\Brain Annex\\BA-Win7\\notebooks\n", " D:\\Docs\\- MY CODE\\Brain Annex\\BA-Win7\n", " C:\\Program Files\\Python 3.8.10\\python38.zip\n", " C:\\Program Files\\Python 3.8.10\\DLLs\n", " C:\\Program Files\\Python 3.8.10\\lib\n", " C:\\Program Files\\Python 3.8.10\n", " D:\\Docs\\- MY CODE\\Brain Annex\\BA-Win7\\venv\n", " \n", " D:\\Docs\\- MY CODE\\Brain Annex\\BA-Win7\\venv\\lib\\site-packages\n", " D:\\Docs\\- MY CODE\\Brain Annex\\BA-Win7\\venv\\lib\\site-packages\\win32\n", " D:\\Docs\\- MY CODE\\Brain Annex\\BA-Win7\\venv\\lib\\site-packages\\win32\\lib\n", " D:\\Docs\\- MY CODE\\Brain Annex\\BA-Win7\\venv\\lib\\site-packages\\Pythonwin\n", " D:\\Docs\\- MY CODE\\Brain Annex\\BA-Win7\n" ] } ], "source": [ "print(\"*** SOME DIAGNOSTIC VALUES: ***\")\n", "\n", "print(\"\\nsys.executable: \", sys.executable)\n", "\n", "print(\"\\ncwd: \", os.getcwd())\n", "\n", "#print(\"\\nsys.path: \", sys.path)\n", "\n", "print(\"\\nsys.path using separate lines: \")\n", "for p in sys.path:\n", " print(\" \", p)" ] }, { "cell_type": "markdown", "id": "bd82fa14-258a-4d44-a9f6-336becda196e", "metadata": {}, "source": [ "# Connect to the database\n", "#### You can use a free local install of the Neo4j database, or a remote one on a virtual machine under your control, or a hosted solution, or simply the FREE \"Sandbox\" : [instructions here](https://julianspolymathexplorations.blogspot.com/2023/03/neo4j-sandbox-tutorial-cypher.html)\n", "NOTE: This tutorial is tested on version 4 of the Neo4j database, but will probably also work on the new version 5# Connect to the database" ] }, { "cell_type": "code", "execution_count": 4, "id": "2d0fd3af-ce34-49ed-8256-b197645211b2", "metadata": { "tags": [] }, "outputs": [], "source": [ "# Save your credentials here - or use the prompts given by the next cell\n", "host = \"\" # EXAMPLES: bolt://123.456.789.012 OR neo4j://localhost\n", "password = \"\"" ] }, { "cell_type": "code", "execution_count": 5, "id": "9e3d2dda-5759-46ec-8ebe-906b34c38c5e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "To create a database connection, enter the host IP, but leave out the port number: (EXAMPLES: bolt://123.456.789.012 OR neo4j://localhost )\n", "\n" ] }, { "name": "stdin", "output_type": "stream", "text": [ "Enter host IP WITHOUT the port number. EXAMPLE: bolt://123.456.789.012 bolt://123.456.789.012\n", "Enter the database password: ········\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "=> Will be using: host='bolt://123.456.789.012:7687', username='neo4j', password=**********\n" ] } ], "source": [ "print(\"To create a database connection, enter the host IP, but leave out the port number: (EXAMPLES: bolt://123.456.789.012 OR neo4j://localhost )\\n\")\n", "\n", "host = input(\"Enter host IP WITHOUT the port number. EXAMPLE: bolt://123.456.789.012 \")\n", "host += \":7687\" # EXAMPLE of host value: \"bolt://123.456.789.012:7687\"\n", "\n", "password = getpass.getpass(\"Enter the database password:\")\n", "\n", "print(f\"\\n=> Will be using: host='{host}', username='neo4j', password=**********\")" ] }, { "cell_type": "code", "execution_count": 6, "id": "9c6ff8d0-734e-431f-94e5-4c172fc913a3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Attempting to connect to Neo4j database\n" ] } ], "source": [ "db = NeoAccess(host=host,\n", " credentials=(\"neo4j\", password), debug=False) # Notice the debug option being OFF" ] }, { "cell_type": "code", "execution_count": 7, "id": "c96ece03-2b07-4a4d-ad6e-e41ccbf67251", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Version of the Neo4j driver: 4.4.11\n" ] } ], "source": [ "print(\"Version of the Neo4j driver: \", db.version())" ] }, { "cell_type": "code", "execution_count": null, "id": "709597ce-f3f0-4c0d-91eb-03e9b6336af2", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 5 }