Gremlin python: Difference between revisions
Jump to navigation
Jump to search
| Line 26: | Line 26: | ||
= Installing Gremlin Server and Console = | = Installing Gremlin Server and Console = | ||
* http://tinkerpop.apache.org/downloads.html | * http://tinkerpop.apache.org/downloads.html | ||
= | = Trial script = | ||
<source lang='bash'> | <source lang='bash'> | ||
#!/bin/bash | #!/bin/bash | ||
| Line 33: | Line 33: | ||
# see https://stackoverflow.com/questions/57936915/how-do-i-get-gremlin-python-with-gremlin-server-3-4-3-to-work | # see https://stackoverflow.com/questions/57936915/how-do-i-get-gremlin-python-with-gremlin-server-3-4-3-to-work | ||
version=3.4.3 | |||
mirror=http://mirror.dkd.de/apache/tinkerpop/$version | |||
gsd=apache-tinkerpop-gremlin-server-${version} | |||
gcd=apache-tinkerpop-gremlin-console-${version} | |||
# check that the given program is installed | # check that the given program is installed | ||
checkinstalled() { | checkinstalled() { | ||
local l_prg="$1" | local l_prg="$1" | ||
local l_version="$2" | local l_version="$2" | ||
| Line 49: | Line 53: | ||
exit 1;; | exit 1;; | ||
esac | esac | ||
fi | fi | ||
$l_prg $l_version | $l_prg $l_version | ||
} | } | ||
echo "checking prerequisites ..." | install() { | ||
checkinstalled java "-version" "openjdk-8-jre" | echo "checking prerequisites ..." | ||
checkinstalled python "--version" "python2.7" | checkinstalled java "-version" "openjdk-8-jre" | ||
checkinstalled pip "--version" "python-pip" | checkinstalled python "--version" "python2.7" | ||
checkinstalled pip "--version" "python-pip" | |||
for d in $gsd $gcd | for d in $gsd $gcd | ||
do | do | ||
if [ ! -d $d ] | |||
then | then | ||
echo "downloading $zip" | zip=$d-bin.zip | ||
if [ ! -f $zip ] | |||
then | |||
echo "downloading $zip" | |||
curl -s $mirror/$zip -o $zip | |||
else | |||
echo "$zip already downloaded" | |||
fi | |||
echo "unzipping $zip" | |||
unzip $zip | |||
else | else | ||
echo "$ | echo "$d already unzipped" | ||
fi | fi | ||
done | |||
} | |||
echo "$ | # commandline option | ||
while [ "$1" != "" ] | |||
do | |||
option=$1 | |||
shift | |||
case $option in | |||
-i|--install) | |||
install;; | |||
-s|--server) | |||
echo "starting gremlin-server ..." | |||
#conf=$(realpath $gsd/conf/gremlin-server-modern-py.yaml) | |||
conf=$(realpath $gsd/conf/gremlin-server-modern.yaml) | |||
$gsd/bin/gremlin-server.sh $conf | |||
;; | |||
-c|--console) | |||
echo "starting gremlin-console ..." | |||
$gcd/bin/gremlin.sh | |||
;; | |||
-h|--help) | |||
usage;; | |||
*) | |||
usage;; | |||
esac | |||
done | done | ||
</source> | </source> | ||
== Trial result == | |||
<pre> | <pre> | ||
./run -i | |||
./run -s | |||
# and in an other console | |||
./run -c | ./run -c | ||
starting gremlin-console ... | starting gremlin-console ... | ||
Revision as of 12:07, 17 September 2019
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
- Java
- Python
- Gremlin-Server
- Gremlin-Console (for debugging)
Installing Java
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
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 Server and Console
Trial script
#!/bin/bash
# WF 2019-09-17
# test gremlin-python
# see https://stackoverflow.com/questions/57936915/how-do-i-get-gremlin-python-with-gremlin-server-3-4-3-to-work
version=3.4.3
mirror=http://mirror.dkd.de/apache/tinkerpop/$version
gsd=apache-tinkerpop-gremlin-server-${version}
gcd=apache-tinkerpop-gremlin-console-${version}
# check that the given program is installed
checkinstalled() {
local l_prg="$1"
local l_version="$2"
local l_package="$3"
which $l_prg
if [ $? -ne 0 ]
then
echo "$l_prg is not available - shall i install it from $l_package y/n?"
read x
case $x in
y) sudo apt-get install $l_package;;
*) echo "aborting ..."
exit 1;;
esac
fi
$l_prg $l_version
}
install() {
echo "checking prerequisites ..."
checkinstalled java "-version" "openjdk-8-jre"
checkinstalled python "--version" "python2.7"
checkinstalled pip "--version" "python-pip"
for d in $gsd $gcd
do
if [ ! -d $d ]
then
zip=$d-bin.zip
if [ ! -f $zip ]
then
echo "downloading $zip"
curl -s $mirror/$zip -o $zip
else
echo "$zip already downloaded"
fi
echo "unzipping $zip"
unzip $zip
else
echo "$d already unzipped"
fi
done
}
# commandline option
while [ "$1" != "" ]
do
option=$1
shift
case $option in
-i|--install)
install;;
-s|--server)
echo "starting gremlin-server ..."
#conf=$(realpath $gsd/conf/gremlin-server-modern-py.yaml)
conf=$(realpath $gsd/conf/gremlin-server-modern.yaml)
$gsd/bin/gremlin-server.sh $conf
;;
-c|--console)
echo "starting gremlin-console ..."
$gcd/bin/gremlin.sh
;;
-h|--help)
usage;;
*)
usage;;
esac
done
Trial result
./run -i
./run -s
# and in an other console
./run -c
starting gremlin-console ...
\,,,/
(o o)
-----oOOo-(3)-oOOo-----
plugin activated: tinkerpop.server
plugin activated: tinkerpop.utilities
plugin activated: tinkerpop.tinkergraph
gremlin> g=traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
No signature of method: groovysh_evaluate.DriverRemoteConnection() is applicable for argument types: (String, String) values: [ws://localhost:8182/gremlin, g]
Type ':help' or ':h' for help.