Difference between revisions of "Gremlin python"

From BITPlan Wiki
Jump to navigation Jump to search
Line 161: Line 161:
 
</source>
 
</source>
 
starts the gremlin console
 
starts the gremlin console
 +
<source lang='bash'>
 +
starting gremlin-console ...
 +
Sep 17, 2019 4:16:03 PM java.util.prefs.FileSystemPreferences$1 run
 +
INFO: Created user preferences directory.
 +
 +
        \,,,/
 +
        (o o)
 +
-----oOOo-(3)-oOOo-----
 +
plugin activated: tinkerpop.server
 +
plugin activated: tinkerpop.utilities
 +
plugin activated: tinkerpop.tinkergraph
 +
gremlin>
 +
</source>
  
 
===Python script start===
 
===Python script start===

Revision as of 16:16, 17 September 2019

OsProject
edit
id  gremlin-python-tutorial
state  
owner  WolfgangFahl
title  Gremlin-Python mini tutorial
url  https://github.com/WolfgangFahl/gremlin-python-tutorial
version  0.0.1
description  
date  2019-09-17
since  
until  

This mini-tutorial is inspired by this stackoverflow question

The goal is to get access to an apache tinkerpop/gremlin graph database via Python.

Prerequisites

  1. Java
  2. Python
  3. Gremlin-Server
  4. Gremlin-Console (for debugging)

To get the preqequisites you can either follow the manual or script based installation below. The script based installation is quicker - the manual installation gives you more insight and control over the installation steps.

Manual Installation

Installing Java

There are many ways to install Java and your mileage may vary.

sudo apt-get install openjdk-8-jre 
java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~18.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)

Installing Python and Pip

We assume you'd like to work with python 2.7

sudo apt install python2.7
python --version
Python 2.7.15+
sudo apt install python-pip
pip --version
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

Installing Gremlin-Python

sudo -H pip install -r requirements.txt

Installing Gremlin Server and Console

Download Gremlin Server and optionally Gremlin Console and unzip the downloaded files.

Script based installation

The "run" installation helper script tries to automate the necessary steps

  1. Installation
  2. Gremlin-Server start
  3. Gremlin-Console start (for debugging)
  4. Python script start

The following command should get you going:

git clone https://github.com/WolfgangFahl/gremlin-python-tutorial
./run -i
./run -s
# in another console
./run -p

Help

./run -h
usage: ./run  [-c|-h|-i|-p|-s|-v]
  -c|--console: start console
  -h|--help: show this usage
  -i|--install: install prerequisites
  -p|--python: start python trial code
  -s|--server: start server
  -v|--version: show version

Version

./run -v
apache-tinkerpop-gremlin version 3.4.3

Installation

 run -i

installs

  1. gremlin server
  2. gremlin console
  3. gremlin python module
checking prerequisites ...
/usr/bin/java
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~18.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
/usr/bin/python
Python 2.7.15+
/usr/bin/pip
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
downloading apache-tinkerpop-gremlin-server-3.4.3-bin.zip
unzipping apache-tinkerpop-gremlin-server-3.4.3-bin.zip
downloading apache-tinkerpop-gremlin-console-3.4.3-bin.zip
unzipping apache-tinkerpop-gremlin-console-3.4.3-bin.zip
installing needed python modules
Requirement already satisfied: futures in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 2))
Requirement already satisfied: gremlinpython in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 4))
Requirement already satisfied: isodate>=0.6.0 in /usr/local/lib/python2.7/dist-packages (from gremlinpython->-r requirements.txt (line 4))
Requirement already satisfied: six>=1.10.0 in /usr/lib/python2.7/dist-packages (from gremlinpython->-r requirements.txt (line 4))
Requirement already satisfied: aenum>=1.4.5 in /usr/local/lib/python2.7/dist-packages (from gremlinpython->-r requirements.txt (line 4))
Requirement already satisfied: tornado<5.0,>=4.4.1 in /usr/local/lib/python2.7/dist-packages (from gremlinpython->-r requirements.txt (line 4))
Requirement already satisfied: certifi in /usr/local/lib/python2.7/dist-packages (from tornado<5.0,>=4.4.1->gremlinpython->-r requirements.txt (line 4))
Requirement already satisfied: singledispatch in /usr/local/lib/python2.7/dist-packages (from tornado<5.0,>=4.4.1->gremlinpython->-r requirements.txt (line 4))
Requirement already satisfied: backports-abc>=0.4 in /usr/local/lib/python2.7/dist-packages (from tornado<5.0,>=4.4.1->gremlinpython->-r requirements.txt (line 4))

Gremlin-Server start

 ./run -s

starts the gremlin server with a default yaml-file in foreground

starting gremlin-server ...
[INFO] GremlinServer - 3.4.3
         \,,,/
         (o o)
-----oOOo-(3)-oOOo-----

[INFO] GremlinServer - Configuring Gremlin Server from /home/wf/source/python/gremlin-python-tutorial/apache-tinkerpop-gremlin-server-3.4.3/conf/gremlin-server-modern.yaml
[INFO] MetricManager - Configured Metrics Slf4jReporter configured with interval=180000ms and loggerName=org.apache.tinkerpop.gremlin.server.Settings$Slf4jReporterMetrics
[INFO] DefaultGraphManager - Graph [graph] was successfully configured via [conf/tinkergraph-empty.properties].
[INFO] ServerGremlinExecutor - Initialized Gremlin thread pool.  Threads in pool named with pattern gremlin-*
[INFO] ServerGremlinExecutor - Initialized GremlinExecutor and preparing GremlinScriptEngines instances.
[INFO] ServerGremlinExecutor - Initialized gremlin-groovy GremlinScriptEngine and registered metrics
[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
[INFO] OpLoader - Adding the standard OpProcessor.
[INFO] OpLoader - Adding the session OpProcessor.
[INFO] OpLoader - Adding the traversal OpProcessor.
[INFO] TraversalOpProcessor - Initialized cache for TraversalOpProcessor with size 1000 and expiration time of 600000 ms
[INFO] GremlinServer - Executing start up LifeCycleHook
[INFO] Logger$info - Loading 'modern' graph data.
[INFO] GremlinServer - idleConnectionTimeout was set to 0 which resolves to 0 seconds when configuring this value - this feature will be disabled
[INFO] GremlinServer - keepAliveInterval was set to 0 which resolves to 0 seconds when configuring this value - this feature will be disabled
[WARN] AbstractChannelizer - The org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0 serialization class is deprecated.
[INFO] AbstractChannelizer - Configured application/vnd.gremlin-v3.0+gryo with org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0
[WARN] AbstractChannelizer - The org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0 serialization class is deprecated.
[INFO] AbstractChannelizer - Configured application/vnd.gremlin-v3.0+gryo-stringd with org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0
[INFO] AbstractChannelizer - Configured application/vnd.gremlin-v3.0+json with org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0
[INFO] AbstractChannelizer - Configured application/json with org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0
[INFO] AbstractChannelizer - Configured application/vnd.graphbinary-v1.0 with org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1
[INFO] AbstractChannelizer - Configured application/vnd.graphbinary-v1.0-stringd with org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1
[INFO] GremlinServer$1 - Gremlin Server configured with worker thread pool of 1, gremlin pool of 4 and boss thread pool of 1.
[INFO] GremlinServer$1 - Channel started at port 8182.

Gremlin-Console start (for debugging)

 ./run -c

starts the gremlin console

starting gremlin-console ...
Sep 17, 2019 4:16:03 PM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.

         \,,,/
         (o o)
-----oOOo-(3)-oOOo-----
plugin activated: tinkerpop.server
plugin activated: tinkerpop.utilities
plugin activated: tinkerpop.tinkergraph
gremlin>

Python script start

./run -p

starts the python test script.