<?php require_once( dirname(dirname(dirname( __FILE__ ))) . '/wp-load.php' ); ?>
<!-- START of header -->
<?php get_header(); ?>
<!-- END of header -->

<!-- warapper -->

<div class="docs-content">
    <!-- START of page navigation -->
    <?php get_template_part( 'docs_navigation' ); ?>
    <!-- END of page navigation -->
    <!-- START of pusher -->
    <div class="docs-content-body">
        <div id="content" class="docs-content-body__inner">


            <div id="outline-container-1" class="outline-3">
            <h1 id="sec-1"><span class="section-number-3">2.4.2</span> Python Quickstart </h1>
            <div class="outline-text-3" id="text-1">
<h2> Introduction </h2>
<p>
A while back we released our first <a href="https://griddb.net/en/blog/using-griddbs-cpythonruby-apis/">python connector blog</a>. Since then, things have gotten a bit easier to install and use due to the <a href="https://github.com/griddb/c_client">C_Client</a> gaining an RPM package and CentOS coming with PCRE by default now.
</p>

<h2> Video </h2>

<p> If you would prefer to follow along with a video, please take a look here:</p>

<div style="text-align:center">
<iframe width="560" height="315" src="https://www.youtube.com/embed/yWCVfLoV9_0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>

<p>As an added bonus, the video will go over some very simple source code as well.</p>


<h2> Installation</h2>

<h3> Install c_client</h3>

<p> <i>This small excerpt is taken from our <a href="https://griddb.net/en/blog/nodejs-client/">Node.js Client Blog</i></a></p>

<p>
    The GridDB c_client (a preqrequisite to using the Python Client) can be found here: <a href="https://github.com/griddb/c_client">https://github.com/griddb/c_client</a>. 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 (<a href="https://github.com/griddb/c_client/releases">the releases page can be found here</a>). So to get started simply <code>wget</code> the latest RPM and install.

    <div class="clipboard">
        <pre><code class="language-sh">$ wget \
https://github.com/griddb/c_client/releases/download/v4.2.0/griddb_c_client-4.2.0-1.linux.x86_64.rpm</code></pre>
    </div>

    then we need to actually install the rpm

    <div class="clipboard">
        <pre><code class="language-sh">$ sudo rpm -ivh griddb_c_client-4.2.0-1.linux.x86_64.rpm</code></pre>
    </div>

    and now the c_client is installed and ready in your <code>/usr/</code> directory. That was easy!
</p>

<h3> Install Python Client </h3>

<p> Installing the Python Client is slightly more involved but still a very easy process. First, let's download the file from GitHub</p>

<div class="clipboard">
    <pre><code class="language-sh">$ wget \
https://github.com/griddb/python_client/archive/0.8.1.tar.gz</code></pre>
</div>

<p> Next, let's unzip </p>

<div class="clipboard">
    <pre><code class="language-sh">$ tar xvzf 0.8.1.tar.gz</code></pre>
</div>

<p> and let's install the prereqs </p>

<div class="clipboard">
    <pre><code class="language-sh">$ 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</code></pre>
</div>

<p> And then we may need to install pcre as well</p>

<div class="clipboard">
    <pre><code class="language-sh">$ sudo yum install pcre2-devel.x86_64</code></pre>
</div>

<p> Now of course we actually <code>make</code> our Python Client</p>

<div class="clipboard">
    <pre><code class="language-sh">$ cd ../python_client
make</code></pre>
</div>

<p>If by chance you encounter the following error when attempting to make your Python Client</p>

<pre><code class="language-sh">/usr/bin/ld: cannot find -lgridstore</code></pre>

<p> do not worry: it is an easy fix. The issue lies with needing your <code>Makefile</code> to point to your c_client. This means the only thing we need to do is add the <code>c_client/bin</code> location in the LDFLAGS option</p>

<pre>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 ...</pre>

<p> With the fix in place, <code>make</code> should work as intended. Next up: setting our environment variables. We just need to point to the proper locations:</p>


<pre><code class="language-sh">$ export LIBRARY_PATH=$LIBRARY_PATH:[insert path to c_client]</code></pre>
<pre><code class="language-sh">$ export  PYTHONPATH=$PYTHONPATH:[insert path to python_client]</code></pre>
<pre><code class="language-sh">$ export LIBRARY_PATH=$LD_LIBRARY_PATH:[insert path to c_client/bin]</code></pre>

<p> Now we should be able to use both <code>c</code> and <code>python</code> with our GridDB Cluster.</p>

<h2>Sample Code</h2>

<p> 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: <a href="https://griddb.net/en/download/26145/">DOWNLOAD (zip)</a> </p>



        </div>
    </div>
</div>
<!-- / main -->

<?php get_footer(); ?>
