Rows

class dbapix.row.Row(raw, cur)[source]

A row in a query result.

Rows are tuples, but they have been augmented to behave like dicts:

for row in cur.execute('''SELECT foo FROM bar'''):
    print(row[0])
    print(row['foo']) # The same thing.

Warning

Checking if a string is in a row via 'foo' in row will check for both the key 'foo' and the value 'foo'! If you need to be explicit, then you should look in the various views:

'foo' in row.keys()
# or
'foo' in row.values()
Row.__getitem__(x)[source]

Get an item via index or key.

Parameters

x – If an int, lookup by index. If a str, lookup by name.

Raises

KeyError or IndexError

Dict-like

Row.get(key, default=None)[source]

Get a value by column name.

Parameters
  • key (str) – The name of the column.

  • default – What to return if the name doesn’t exist.

Raises

KeyError if the column doesn’t exist.

Row.copy()[source]

Get a copy of the row as a dict.

The next 3 have the appropriate behaviour in Python 2 or Python 3

Row.keys()[source]
Row.values()[source]
Row.items()[source]

The following are also defined as in Python 2:

Row.iterkeys()[source]
Row.viewkeys()[source]
Row.itervalues()[source]
Row.viewvalues()[source]
Row.iteritems()[source]
Row.viewitems()[source]

Row Lists

class dbapix.row.RowList(cur)[source]

An extension of list for holding rows.

RowList.as_dataframe(**kwargs)[source]

Convert these rows into a pandas.DataFrame.