starbase package

Submodules

starbase.conf module

starbase.content_types module

starbase.defaults module

starbase.exceptions module

exception starbase.exceptions.BaseException[source]

Bases: exceptions.Exception

Base exception.

exception starbase.exceptions.ImproperlyConfigured[source]

Bases: starbase.exceptions.BaseException

Exception raised when developer didn’t configure the code properly.

exception starbase.exceptions.InvalidArguments[source]

Bases: exceptions.ValueError, starbase.exceptions.BaseException

Exception raised when invalid arguments supplied.

exception starbase.exceptions.ParseError[source]

Bases: starbase.exceptions.BaseException

Raised if the request or response contain malformed data.

exception starbase.exceptions.DoesNotExist[source]

Bases: starbase.exceptions.DatabaseError

Does not exist.

exception starbase.exceptions.DatabaseError[source]

Bases: starbase.exceptions.BaseException

General database error, as defined in PEP249 interface.

exception starbase.exceptions.IntegrityError[source]

Bases: starbase.exceptions.DatabaseError

Integrity error, as defined in PEP249 interface.

starbase.translations module

Module contents

class starbase.Connection(host='127.0.0.1', port=8000, user='', password='', secure=False, content_type='json', perfect_dict=True, retries=0, retry_delay=2)

Bases: object

Connection instance.

Parameters:
  • host (str) – Stargate host.
  • port (int) – Stargate port.
  • user (str) – Stargate user. Use this if your stargate is protected with HTTP basic auth (to be used in combination with password argument).
  • password (str) – Stargate password (see comment to user).
  • secure (bool) – If set to True, HTTPS is used; otherwise - HTTP. Default value is False.
  • content_type (str) – Content type for data wrapping when communicating with the Stargate. Possible options are: json.
  • perfect_dict (bool) – Global setting. If set to True, generally data will be returned as perfect dict.
  • retries (int) – Number of times to retry a failed request.
  • retry_delay (int) – Delay between retrying a failed request.
cluster_status

Storage cluster satus. Returns detailed status on the HBase cluster backing the Stargate instance.

Parameters:fail_silently (bool) –
Return dict:Dictionary with information on dead nodes, live nodes, average load, regions, etc.
cluster_version

Storage cluster version. Returns version information regarding the HBase cluster backing the Stargate instance.

Parameters:fail_silently (bool) –
Return str:HBase version.
create_table(name, *columns)

Creates the table and returns the instance created. If table already exists, returns None.

Parameters:
  • name (str) – Table name.
  • *columns (list|tuple) –
Return starbase.client.table.Table:
 
drop_table(name, fail_silently=True)

Drops the table.

Parameters:name (str) – Table name.
Return int:Status code.
table(name)

Initializes a table instance to work with.

Parameters:name (str) – Table name. Example value ‘test’.
Return stargate.base.Table:
 

This method does not check if table exists. Use the following methods to perform the check:

  • starbase.client.Connection.table_exists or
  • starbase.client.table.Table.exists.
table_exists(name, fail_silently=True)

Checks if table exists.

Parameters:
  • name (str) – Table name.
  • fail_silently (bool) –
Return bool:
tables(raw=False, fail_silently=True)

Table list. Retrieves the list of available tables.

Parameters:
  • raw (bool) – If set to True raw result (JSON) is returned.
  • fail_silently (bool) –
Return list:

Just a list of plain strings of table names, no Table instances.

version

Software version. Returns the software version.

Parameters:fail_silently (bool) –
Return dict:Dictionary with info on software versions (OS, Server, JVM, etc).
class starbase.Table(connection, name)

Bases: object

For HBase table operations.

Parameters:
  • connection (stargate.base.Connection) – Connection instance.
  • name (str) – Table name.
FALSE_ROW_KEY = 'false-row-key'
add_columns(*columns, **kwargs)

Add columns to existing table (POST). If not successful, returns appropriate HTTP error status code. If successful, returns HTTP 200 status.

Parameters:
  • name (str) – Table name.
  • *columns (list) –

    List of columns (plain strings) to ADD.

Return int:

HTTP response status code (200 on success).

Example:

In the example below we create a new table named table1 with columns column1 and column2. In the next step we add columns column3 and columns4 to it.

>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.create('column1', 'column2')
>>> table.add_columns('column3', 'column4')
batch(size=None, fail_silently=True)

Returns a Batch instance. Returns None if table does not exist.

Parameters:
  • size (int) – Size of auto-commit. If not given, auto-commit is disabled.
  • fail_silently (bool) –
Return starbase.client.table.batch.Batch:
 
Example:

Assuming that we have a table named table1 with columns column1 and column2.

>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> batch = table.batch()
>>> batch.insert('row1', {'column1': {'id': '1', 'name': 'Some name'}, 'column2': {'id': '2', 'age': '32'}})
>>> batch.insert('row2', {'column1': {'id': '12', 'name': 'Some name'}, 'column2': {'id': '22', 'age': '322'}})
>>> batch.insert('row3', {'column1': {'id': '13', 'name': 'Some name'}, 'column2': {'id': '23', 'age': '323'}})
>>> batch.commit(finalize=True)
check_if_exists_on_batch_operations
check_if_exists_on_schema_operations
columns()

Gets a plain list of column families of the table given.

Return list:Just a list of plain strings of column family names.
Example:
>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.columns()
create(*columns, **kwargs)

Creates a table schema. If not successful, returns appropriate HTTP error status code. If successful, returns HTTP 201 status.

Parameters:*columns (list) –

List of columns (plain strings).

Return int:HTTP response status code (201 on success). Returns boolean False on failure.
Example:
>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.create('column1', 'column2')
disable_if_exists_checks()

Skips calling the exists method on any operation.

disable_row_operation_if_exists_checks()

Disables exists method on row operations.

drop(fail_silently=True)

Drops current table. If not successful, returns appropriate HTTP error status code. If successful, returns HTTP 200 status.

Parameters:fail_silently (bool) –
Return int:HTTP response status code (200 on success).
Example:

In the example below we check if table named table1 exists and if so - drop it.

>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> if table.exists():
>>>     table.drop()
drop_columns(*columns, **kwargs)

Removes/drops columns from table (PUT).If not successful, returns appropriate HTTP error status code. If successful, returns HTTP 201 status.

Parameters:
  • name (str) – Table name.
  • *columns (list) –

    List of columns (plain strings) to REMOVE.

Return int:

HTTP response status code (201 on success).

Example:

Assuming that we have a table named table1 with columns column1 and column2.

>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.drop_columns('column1', 'column2')
enable_if_exists_checks()

Enables exists method on any operation. The opposite of disable_if_exists_checks.

enable_row_operation_if_exists_checks()

Enables exists method on row operations. The opposite of disable_row_operation_if_exists_checks.

exists(fail_silently=True)

Checks if table exists.

Parameters:fail_silently (bool) –
Return bool:
Example:
>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.exists()
fetch(row, columns=None, timestamp=None, number_of_versions=None, raw=False, perfect_dict=None, fail_silently=True)

Fetches a single row from table.

Parameters:
  • row (str) –
  • columns (list|set|tuple|dict) –
  • timestamp – Not yet used.
  • number_of_versions (int) – If provided, multiple versions of the given record are returned.
  • perfect_dict (bool) –
  • raw (bool) –
Return dict:
Example:

In the example below we first create a table named table1 with columns column1, column2 and column3, then insert a row with column1 and column2 data, then update the same row with column3 data and then fetch the data.

>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.create('column1', 'column2', 'column3')
>>> table.insert('row1', {'column1': {'id': '1', 'name': 'Some name'}, 'column2': {'id': '2', 'age': '32'}})
>>> table.update('row2', {'column3': {'gender': 'male', 'favourite_book': 'Steppenwolf', 'active': '1'}})

Fetching entire row1.

>>> table.fetch('row1')

Fetching the row row1 with data from column1 and column3 only.

>>> table.fetch('row1', ['column1', 'column3'])

Fetching the row row1 with fields gender and favourite_book from column3 and fild age of column column2.

>>> table.fetch('row1', {'column3': ['gender', 'favourite_book'], 'column2': ['age']})
fetch_all_rows(with_row_id=False, raw=False, perfect_dict=None, flat=False, filter_string=None, scanner_config='', fail_silently=True)

Fetches all table rows.

Parameters:
  • with_row_id (bool) – If set to True, returned along with row id.
  • raw (bool) – If set to True, raw response is returned.
  • perfect_dict (bool) – If set to True, a perfect dict struture is used for output data.
  • filter_string (string) – If set, applies the given filter string to the scanner.
Returns list:
Example:
>>> filter_string = '{"type": "RowFilter", "op": "EQUAL", "comparator": '
>>>                 '{"type": "RegexStringComparator", "value": "^row_1.+"}}'
>>> rows = self.table.fetch_all_rows(
>>>     with_row_id = True,
>>>     perfect_dict = perfect_dict,
>>>     filter_string = row_filter_string
>>>     )
insert(row, columns, timestamp=None, fail_silently=True)

Inserts a single row into a table.

Parameters:
  • row (str) –
  • tuple or set) columns ((list,) –
  • timestamp
Return int:

HTTP status code (200 on success).

Example:

In the example below we first create a table named table1 and then insert two rows to it.

>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.create('column1', 'column2', 'column3')
>>> table.insert('row1', {'column1': {'id': '1', 'name': 'Some name'}, 'column2': {'id': '2', 'age': '32'}})
>>> table.insert('row2', {'column3': {'gender': 'male', 'favourite_book': 'Steppenwolf'}})
metadata(fail_silently=True)

Table metadata. Retrieves table region metadata.

Return dict:
regions(fail_silently=True)

Table metadata. Retrieves table region metadata.

Return dict:
remove(row, column=None, qualifier=None, timestamp=None, fail_silently=True)

Removes/delets a single row/column/qualifier from a table (depending on the depth given). If only row is given, the entire row is deleted. If row and column, only the column value is deleted (entirely for the row given). If qualifier is given as well, then only the qualifier value would be deleted.

Parameters:
  • row (str) –
  • column (str) –
  • qualifier (str) –
Return int:

HTTP status code.

Example:

In the example below we first create a table named table1 with columns column1, column2 and column3. Then we insert a single row with multiple columns and then remove parts from that row.

>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.create('column1', 'column2', 'column3')
>>> table.insert('row1', {'column1': {'id': '1', 'name': 'Some name'}, 'column2': {'id': '2', 'age': '32'}})
>>> table.remove('row1', 'column2', 'id')
>>> table.remove('row1', 'column1')
>>> table.remove('row1')
schema(fail_silently=True)

Table schema. Retrieves table schema.

Return dict:Dictionary with schema info (detailed information on column families).
Example:
>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.schema()
update(row, columns, timestamp=None, fail_silently=True)

Updates a single row in a table.

Parameters:
  • row (str) –
  • columns (dict) –
  • timestamp – Not yet used.
Return int:

HTTP response status code (200 on success).

Example:

In the example below we first create a table named table1 with columns column1, column2 and column3. Then we insert a row with column1 and column2 data and then update the same row with column3 data.

>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.create('column1', 'column2', 'column3')
>>> table.insert('row1', {'column1': {'id': '1', 'name': 'Some name'}, 'column2': {'id': '2', 'age': '32'}})
>>> table.update('row1', {'column3': {'gender': 'female', 'favourite_book': 'Solaris'}})