Bob Database Support

Bob provides an API to easily query and interface with well known database protocols. A Bob database contains information about the organization of the files, functions to query information such as the data which might be used for training a model, but it usually does not contain the data itself (except for some toy examples). Many of the database packages provide functionality through data stored in sqlite files, whereas the smallest ones can be stored as filelists.

As databases usually contain thousands of files, and as verification protocols often require to store information about pairs of files, the size of such databases can become very large. For this reason, we have decided to externalize many of them in Satellite Packages.

Reference

This section contains the reference guide for bob.db.base.

The db package contains simplified APIs to access data for various databases that can be used in Biometry, Machine Learning or Pattern Classification.

bob.db.base.get_config()[source]

Returns a string containing the configuration information.

Database Handling Utilities

Some utilities shared by many of the databases.

class bob.db.base.utils.null[source]

Bases: object

A look-alike stream that discards the input

write(s)[source]

Writes contents of string s on this stream

flush()[source]

Flushes the stream

bob.db.base.utils.apsw_is_available()[source]

Checks lock-ability for SQLite on the current file system

class bob.db.base.utils.SQLiteConnector(filename, readonly=False, lock=None)[source]

Bases: object

An object that handles the connection to SQLite databases.

Initializes the connector

Keyword arguments

filename
The name of the file containing the SQLite database
readonly
Should I try and open the database in read-only mode?
lock
Any vfs name as output by apsw.vfsnames()
static filesystem_is_lockable(database)[source]

Checks if the filesystem is lockable

APSW_IS_AVAILABLE = False
create_engine(echo=False)[source]

Returns an SQLAlchemy engine

session(echo=False)[source]

Returns an SQLAlchemy session

bob.db.base.utils.session(dbtype, dbfile, echo=False)[source]

Creates a session to an SQLite database

bob.db.base.utils.session_try_readonly(dbtype, dbfile, echo=False)[source]

Creates a read-only session to an SQLite database. If read-only sessions are not supported by the underlying sqlite3 python DB driver, then a normal session is returned. A warning is emitted in case the underlying filesystem does not support locking properly.

Raises a NotImplementedError if the dbtype is not supported.

bob.db.base.utils.create_engine_try_nolock(dbtype, dbfile, echo=False)[source]

Creates an engine connected to an SQLite database with no locks. If engines without locks are not supported by the underlying sqlite3 python DB driver, then a normal engine is returned. A warning is emitted if the underlying filesystem does not support locking properly in this case.

Raises a NotImplementedError if the dbtype is not supported.

bob.db.base.utils.session_try_nolock(dbtype, dbfile, echo=False)[source]

Creates a session to an SQLite database with no locks. If sessions without locks are not supported by the underlying sqlite3 python DB driver, then a normal session is returned. A warning is emitted if the underlying filesystem does not support locking properly in this case.

Raises a NotImplementedError if the dbtype is not supported.

bob.db.base.utils.connection_string(dbtype, dbfile, opts={})[source]

Returns a connection string for supported platforms

Keyword parameters

dbtype
The type of database (only ‘sqlite’ is supported for the time being)
dbfile
The location of the file to be used

Driver API

This module defines, among other less important constructions, a management interface that can be used by Bob to display information about the database and manage installed files.

class bob.db.base.driver.Interface[source]

Bases: abc.NewBase

Base manager for Bob databases

name()[source]

Returns a simple name for this database, w/o funny characters, spaces

files()[source]

Returns a python iterable with all auxiliary files needed.

The values should be take w.r.t. where the python file that declares the database is sitting at.

version()[source]

Returns the current version number defined in setup.py

type()[source]

Returns the type of auxiliary files you have for this database

If you return ‘sqlite’, then we append special actions such as ‘dbshell’ on ‘bob_dbmanage.py’ automatically for you. Otherwise, we don’t.

If you use auxiliary text files, just return ‘text’. We may provide special services for those types in the future.

Use the special name ‘builtin’ if this database is an integral part of Bob.

setup_parser(parser, short_description, long_description)[source]

Sets up the base parser for this database.

Keyword arguments:

short_description
A short description (one-liner) for this database
long_description
A more involved explanation of this database

Returns a subparser, ready to be added commands on

add_commands(parser)[source]

Adds commands to a given (argparse) parser.

This method, effectively, allows you to define special commands that your database will be able to perform when called from the common driver like for example create or checkfiles.

You are not obliged to overwrite this method. If you do, you will have the chance to establish your own commands. You don’t have to worry about stock commands such as files() or version(). They will be automatically hooked-in depending on the values you return for type() and files().

Keyword arguments

parser
An instance of a argparse.ArgumentParser that you can customize, i.e., call argparse.ArgumentParser.add_argument() on.

Indices and tables