SkillAgentSearch skills...

Starbase

DEPRECATED - HBase Stargate (REST API) client wrapper for Python.

Install / Use

/learn @barseghyanartur/Starbase
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

======== starbase

HBase Stargate (REST API) client wrapper for Python.

Read the official documentation of the Stargate <http://wiki.apache.org/hadoop/Hbase/Stargate>_.

Deprecation warning!

This package is no longer supported. Either maintain your own fork or switch to alternative.

Description

starbase is (at the moment) a client implementation of the Apache HBase REST API (Stargate).

What you have to know

Beware, that REST API is slow (not to blame on this library!). If you can operate with HBase directly better do so.

Prerequisites

You need to have Hadoop, HBase, Thrift and Stargate running. If you want to make it easy for yourself, read my instructions on installing Cloudera manager (free) on Ubuntu 12.04 LTS here <http://barseghyanartur.blogspot.nl/2013/08/installing-cloudera-on-ubuntu-1204.html>_ or there <https://bitbucket.org/barseghyanartur/simple-cloudera-install>_.

Once you have everything installed and running (by default Stargate runs on 127.0.0.1:8000), you should be able to run src/starbase/client/test.py without problems (UnitTest).

Supported Python versions

  • 2.6.8 and up
  • 2.7
  • 3.3

Features

Project is still in development, thus not all the features of the API are available.

Features implemented

  • Connect to Stargate.
  • Show software version.
  • Show cluster version.
  • Show cluster status.
  • List tables.
  • Retrieve table schema.
  • Retrieve table meta data.
  • Get a list of tables' column families.
  • Create a table.
  • Delete a table.
  • Alter table schema.
  • Insert (PUT) data into a single row (single or multiple columns).
  • Update (POST) data of a single row (single or multiple columns).
  • Select (GET) a single row from table, optionally with selected columns only.
  • Delete (DELETE) a single row by id.
  • Batch insert (PUT).
  • Batch update (POST).
  • Basic HTTP auth is working. You could provide a login and a password to the connection.
  • Retrive all rows in a table (table scanning).

Features in-development

  • Table scanning.
  • Syntax globbing.

Installation

Install latest stable version from PyPI.

.. code-block:: none

$ pip install starbase

Or latest stable version from github.

.. code-block:: none

$ pip install -e git+https://github.com/barseghyanartur/starbase@stable#egg=starbase

Usage and examples

Operating with API starts with making a connection instance.

Required imports

.. code-block:: python

from starbase import Connection

Create a connection instance

Defaults to 127.0.0.1:8000. Specify host and port arguments when creating a connection instance, if your settings are different.

.. code-block:: python

c = Connection()

With customisations, would look simlar to the following.

.. code-block:: python

c = Connection(host='192.168.88.22', port=8001)

Show tables

Assuming that there are two existing tables named table1 and table2, the following would be printed out.

.. code-block:: python

c.tables()

Output.

.. code-block:: none

['table1', 'table2']

Operating with table schema

Whenever you need to operate with a table (also, if you need to create one), you need to have a table instance created.

Create a table instance (note, that at this step no table is created).

.. code-block:: python

t = c.table('table3')

Create a new table

Assuming that no table named ``table3`` yet exists in the database, create a table named ``table3`` with
columns (column families) ``column1``, ``column2``, ``column3`` (this is the point where the table is
actually created). In the example below, ``column1``, ``column2`` and ``column3`` are column families (in
short - columns). Columns are declared in the table schema.

.. code-block:: python

    t.create('column1', 'column2', 'column3')

Output.

.. code-block:: none

    201

Check if table exists

.. code-block:: python

t.exists()

Output.

.. code-block:: none

True

Show table columns (column families)

.. code-block:: python

    t.columns()

Output.

.. code-block:: none

    ['column1', 'column2', 'column3']

Add columns to the table

Add columns given (column4, column5, column6, column7).

.. code-block:: python

t.add_columns('column4', 'column5', 'column6', 'column7')

Output.

.. code-block:: none

200

Drop columns from table

Drop columns given (``column6``, ``column7``).

.. code-block:: python

    t.drop_columns('column6', 'column7')

Output.

.. code-block:: none

    201

Drop entire table schema

.. code-block:: python

t.drop()

Output.

.. code-block:: none

200

Operating with table data

Insert data into a single row

HBase is a key/value store. In HBase columns (also named column families) are part of declared table schema
and have to be defined when a table is created. Columns have qualifiers, which are not declared in the table
schema. Number of column qualifiers is not limited.

Within a single row, a value is mapped by a column family and a qualifier (in terms of key/value store
concept). Value might be anything castable to string (JSON objects, data structures, XML, etc).

In the example below, ``key11``, ``key12``, ``key21``, etc. - are the qualifiers. Obviously, ``column1``,
``column2`` and ``column3`` are column families.

Column families must be composed of printable characters. Qualifiers can be made of any arbitrary bytes.

Table rows are identified by row keys - unique identifiers (UID or so called primary key). In the example
below, ``my-key-1`` is the row key (UID).

То recap all what's said above, HBase maps (row key, column family, column qualifier and timestamp) to a
value.

.. code-block:: python

    t.insert(
        'my-key-1',
        {
            'column1': {'key11': 'value 11', 'key12': 'value 12',
                        'key13': 'value 13'},
            'column2': {'key21': 'value 21', 'key22': 'value 22'},
            'column3': {'key32': 'value 31', 'key32': 'value 32'}
        }
        )

Output.

.. code-block:: none

    200

Note, that you may also use the `native` way of naming the columns and cells (qualifiers). Result of
the following would be equal to the result of the previous example.

.. code-block:: python

    t.insert(
        'my-key-1',
        {
            'column1:key11': 'value 11', 'column1:key12': 'value 12',
            'column1:key13': 'value 13',
            'column2:key21': 'value 21', 'column2:key22': 'value 22',
            'column3:key32': 'value 31', 'column3:key32': 'value 32'
        }
        )

Output.

.. code-block:: none

    200

Update row data

.. code-block:: python

t.update(
    'my-key-1',
    {'column4': {'key41': 'value 41', 'key42': 'value 42'}}
    )

Output.

.. code-block:: none

200

Remove row, row column or row cell data

Remove a row cell (qualifier) data. In the example below, the ``my-key-1`` is table row UID, ``column4``
is the column family and the ``key41`` is the qualifier. Note, that only qualifer data (for the row given)
is being removed. All other possible qualifiers of the column ``column4`` will remain untouched.

.. code-block:: python

    t.remove('my-key-1', 'column4', 'key41')

Output.

.. code-block:: none

    200

Remove a row column (column family) data. Note, that at this point, the entire column data (data of all
qualifiers for the row given) is being removed.

.. code-block:: python

    t.remove('my-key-1', 'column4')

Output.

.. code-block:: none

    200

Remove an entire row data. Note, that in this case, entire row data, along with all columns and qualifiers
for the row given, is being removed.

.. code-block:: python

    t.remove('my-key-1')

Output.

.. code-block:: none

    200

Fetch table data

Fetch a single row data with all columns and qualifiers.

.. code-block:: python

t.fetch('my-key-1')

Output.

.. code-block:: none

{
    'column1': {'key11': 'value 11', 'key12': 'value 12', 'key13': 'value 13'},
    'column2': {'key21': 'value 21', 'key22': 'value 22'},
    'column3': {'key32': 'value 31', 'key32': 'value 32'}
}

Fetch a single row data with selected columns (limit to column1 and column2 columns and all their qualifiers).

.. code-block:: python

t.fetch('my-key-1', ['column1', 'column2'])

Output.

.. code-block:: none

{
    'column1': {'key11': 'value 11', 'key12': 'value 12', 'key13': 'value 13'},
    'column2': {'key21': 'value 21', 'key22': 'value 22'},
}

Narrow the result set even more (limit to qualifiers key1 and key2 of column column1 and qualifier key32 of column column3).

.. code-block:: python

t.fetch('my-key-1', {'column1': ['key11', 'key13'], 'column3': ['key32']})

Output.

.. code-block:: none

{
    'column1': {'key11': 'value 11', 'key13': 'value 13'},
    'column3': {'key32': 'value 32'}
}

Note, that you may also use the native way of naming the columns and cells (qualifiers). Example below does exactly the same as example above.

.. code-block:: python

t.fet

Related Skills

View on GitHub
GitHub Stars54
CategoryDevelopment
Updated3mo ago
Forks32

Languages

Python

Security Score

82/100

Audited on Jan 6, 2026

No findings