A while back we released our first python connector blog. Since then, things have gotten a bit easier to install and use due to the C_Client gaining an RPM package and CentOS coming with PCRE by default now.
If you would prefer to follow along with a video, please take a look here:
As an added bonus, the video will go over some very simple source code as well.
This small excerpt is taken from our Node.js Client Blog
The GridDB c_client (a preqrequisite to using the Python Client) can be found here: https://github.com/griddb/c_client. The c_client installation has been simplified since the last blog; instead of compiling from source yourself, there is now an RPM available for your convenience (the releases page can be found here). So to get started simply
wget the latest RPM and install.
$ wget \ https://github.com/griddb/c_client/releases/download/v4.2.0/griddb_c_client-4.2.0-1.linux.x86_64.rpm
then we need to actually install the rpm
$ sudo rpm -ivh griddb_c_client-4.2.0-1.linux.x86_64.rpm
and now the c_client is installed and ready in your
/usr/ directory. That was easy!
Install Python Client
Installing the Python Client is slightly more involved but still a very easy process. First, let’s download the file from GitHub
$ wget \ https://github.com/griddb/python_client/archive/0.8.1.tar.gz
Next, let’s unzip
$ tar xvzf 0.8.1.tar.gz
and let’s install the prereqs
$ wget https://prdownloads.sourceforge.net/swig/swig-3.0.12.tar.gz tar xvfz swig-3.0.12.tar.gz cd swig-3.0.12 ./configure make sudo make install
And then we may need to install pcre as well
$ sudo yum install pcre2-devel.x86_64
Now of course we actually
make our Python Client
$ cd ../python_client make
If by chance you encounter the following error when attempting to make your Python Client
/usr/bin/ld: cannot find -lgridstore
do not worry: it is an easy fix. The issue lies with needing your
Makefile to point to your c_client. This means the only thing we need to do is add the
c_client/bin location in the LDFLAGS option
SWIG = swig -DSWIGWORDSIZE64 CXX = g++ ARCH = $(shell arch) LDFLAGS = -L/home/israel/c_client/bin -lpthread -lrt -lgridstore #added /home/israel/c_client_bin right here CPPFLAGS = -fPIC -std=c++0x -g -O2 INCLUDES = -Iinclude -Isrc INCLUDES_PYTHON = $(INCLUDES) \ -I/usr/include/python3.6m PROGRAM = _griddb_python.so EXTRA = griddb_python.py griddb_python.pyc SOURCES = src/TimeSeriesProperties.cpp \ src/ContainerInfo.cpp \ src/AggregationResult.cpp \ src/Container.cpp \ src/Store.cpp \ src/StoreFactory.cpp \ src/PartitionController.cpp \ src/Query.cpp \ src/QueryAnalysisEntry.cpp \ src/RowKeyPredicate.cpp \ src/RowSet.cpp \ src/TimestampUtils.cpp \ all: $(PROGRAM) ... snip ...
With the fix in place,
make should work as intended. Next up: setting our environment variables. We just need to point to the proper locations:
$ export LIBRARY_PATH=$LIBRARY_PATH:[insert path to c_client]
$ export PYTHONPATH=$PYTHONPATH:[insert path to python_client]
$ export LIBRARY_PATH=$LD_LIBRARY_PATH:[insert path to c_client/bin]
Now we should be able to use both
python with our GridDB Cluster.
Usage with Python is fairly straight forward, so we won’t spent too much time here. However, if you are interested, you can check out the video posted on top. To follow along, please download the source code here: blog python sample code (57 downloads)