Skip to content

Rows

Get row / rows

Get row

Gets one row of a table by its row ID.

base.get_row(table_name, row_id)

Example

row = base.get_row('Table1', 'U_eTV7mDSmSd-K2P535Wzw')

List rows

Lists multiple rows of a table.

base.list_rows(table_name, view_name=None, start=None, limit=None)

The default limit is 1000 which is also the maximum number of rows this method returns.

The query method (see below) offers more filter options and can return more rows.

Examples

rows = base.list_rows('Table1')
rows = base.list_rows('Table1', view_name='default', start=5, limit=20)

Query

Queries a base using a SQL statement.

base.query(sql-statement)

Unless the SQL statement specifies a higher limit, the method returns a maximum of 100 rows. The maximum number of rows returned is 10000 no matter the limit specified in the SQL statement.

Example with a wildcard

json_data = base.query('select * from Users') // (1)!
print(json.dumps(json_data, indent=2))
  1. Returns for example the following:
    [
        {
            "Name": "Thomas",
            "_id": "VkyADGkFRiif0bEVHd-CtA",
            "_ctime": "2023-08-16T15:04:56.018Z",
            "_mtime": "2023-08-17T07:02:59.585Z",
            "_creator": "a5adebe279e04415a28b2c7e256e9e8d@auth.local",
            "_last_modifier": "a5adebe279e04415a28b2c7e256e9e8d@auth.local",
            "_locked": null,
            "_locked_by": null,
            "_archived": false
        },
        {
            "Name": "Steve",
            "_id": "UevpAVOjRrmbfqMmpsuTEg",
            "_ctime": "2023-08-17T07:03:00.292Z",
            "_mtime": "2023-08-17T07:03:00.801Z",
            "_creator": "a5adebe279e04415a28b2c7e256e9e8d@auth.local",
            "_last_modifier": "a5adebe279e04415a28b2c7e256e9e8d@auth.local",
            "_locked": null,
            "_locked_by": null,
            "_archived": false
        },
    ]
    

Example with WHERE

json_data = base.query('select name, price from Bill where year = 2021')
print(json.dumps(json_data, indent=2))

Example with ORDER BY

json_data = base.query('select name, price, year from Bill order by year')
print(json.dumps(json_data, indent=2))

Example with GROUP BY

json_data = base.query('select name, sum(price) from Bill group by name')
print(json.dumps(json_data, indent=2))

Example with DISTINCT

json_data = base.query('select distinct name from Bill')
print(json.dumps(json_data, indent=2))

Add rows

By default, the default values specified for the table columns in the webinterface do not apply when adding/appending rows via API. In order to apply the default values, add apply_default=Trueas a function parameter. If set to True, the default values can be overwritten by specifying alternative values in row_data.

Append row

Appends one row to a table.

base.append_row(table_name, row_data, apply_default=False)

Example

row_data = {
    "Name": "Ron"
}

base.append_row('Table1', row_data, apply_default=True)

Batch append rows

Appends multiple rows to a table.

base.batch_append_rows(table_name, rows_data, apply_default=False)

Example

rows_data = [{
    'Name': 'Ron',
    'Birthday': '1975-01-01'
}, {
    'Name': 'Richard',
    'Birthday': '1978-10-08'
}]

base.batch_append_rows('Table6', rows_data)

Insert row

Inserts one row to a table under a anchor row.

base.insert_row(table_name, row_data, anchor_row_id, apply_default=False)

Example

row_data = {
    "Name": "Ron"
}
base.insert_row('Table1', row_data, 'U_eTV7mDSmSd-K2P535Wzw')

Update row

Update row

Updates one row in a table.

base.update_row(table_name, row_id, row_data)

Example

row_data = {
    "Name": "Ron"
}
base.update_row('Table1', 'U_eTV7mDSmSd-K2P535Wzw', row_data)

Batch update rows

Updates multiple rows in a table.

base.batch_update_rows(table_name, rows_data)

Example

rows_data = [{
    "row_id" : "fMmCFyoxT4GN5Y2Powbl0Q",
    "row" : {
        "Name" : "Ron",
        "Height" : "183"
        }
}, {
    "row_id" : "cF5JTE99Tae-VVx0BGT-3A",
    "row" : {
        "Name" : "Richard",
        "Height" : "184"
        }
}, {
    "row_id" : "WP-8rb5PSUaM-tZRmTOCPA",
    "row" : {
        "Name" : "Regina",
        "Heigt" : "173"
        }
}]
base.batch_update_rows('Table1', rows_data)

Delete rows

Delete row

Deletes one row from a table.

base.delete_row(table_name, row_id)

Example

base.delete_row('Table1', 'U_eTV7mDSmSd-K2P535Wzw')

Batch delete rows

Deletes multiple rows from a table.

base.batch_delete_rows(table_name, row_ids)

Example

del_rows = rows[:3]
row_ids = [row['_id'] for row in del_rows]
base.batch_delete_rows('Table1', row_ids)