Skip to content

Tables

You'll find below all the available methods to interact with the tables of a SeaTable base.

Global structure

Here is the global structure of a table object:

{
    "_id": "IfcB",
    "name": "New table",
    "is_header_locked": false,
    "summary_configs": {},
    "columns": [ // (1)!
        {
        "key": "0000",
        "type": "number",
        "name": "First column",
        "editable": true,
        "width": 200,
        "resizable": true,
        "draggable": true,
        "data": null,
        "permission_type": "",
        "permitted_users": []
        },
        {
        "key": "2w6F",
        "type": "text",
        "name": "second column",
        "editable": true,
        "width": 200,
        "resizable": true,
        "draggable": true,
        "data": null,
        "permission_type": "",
        "permitted_users": []
        },
        {
        "key": "3aAf",
        "type": "date",
        "name": "third column",
        "editable": true,
        "width": 200,
        "resizable": true,
        "draggable": true,
        "data": null,
        "permission_type": "",
        "permitted_users": []
        }
    ],
    "rows": [], // (2)!
    "views": [ // (3)!
        {
        "_id": "0000",
        "name": "Default View",
        "type": "table",
        "is_locked": false,
        "filter_conjunction": "And",
        "filters": [],
        "sorts": [],
        "groupbys": [],
        "group_rows": [],
        "groups": [],
        "colorbys": {},
        "hidden_columns": [],
        "rows": [],
        "formula_rows": {},
        "link_rows": {},
        "summaries": {},
        "colors": {}
        }
    ],
    "id_row_map": {}
}

  1. Array of existing columns

    {
      "key": "g4s1",
      "type": "number",
      "name": "api3",
      "editable": true,
      "width": 200,
      "resizable": true,
      "draggable": true,
      "data": null,
      "permission_type": "",
      "permitted_users": []
    }
    

  2. Array of existing rows

    {
    "_id": "Qtf7xPmoRaiFyQPO1aENTjb",
    "_mtime": "2021-03-10T16:19:31.761+00:00",
    "Name": "NewName",
    "Date": "2020-08-01",
    "Content": "111",
    "link": [
                {
                "display_value": "1",
                "row_id": "XzdZfL2oS-aILnhfagTWEg"
                }
            ]
    }
    

  3. Array of existing views

    {
      "_id": "0000",
      "name": "Default View",
      "type": "table",
      "is_locked": false,
      "rows": [],
      "formula_rows": {},
      "summaries": [],
      "filter_conjunction": "And",
      "sorts": [],
      "filters": [],
      "hidden_columns": [],
      "groupbys": [],
      "group_rows": [],
      "groups": []
    }
    
    Please refer to the SeaTable API Reference for a more detailed presentation.

You can have a look at the specific view, column or row structure on the corresponding pages.

Retrieve table(s)

Get current table

There is no specific method to get the current (selected) table as it is a property from the context object, so simply use context.current_table.

list_tables

Get all tables of the current base.

base.list_tables()
__ Output__ List of table dicts

Example

from seatable_api import Base, context

base = Base(context.api_token, context.server_url)
base.auth()
tables = base.list_tables()
print(tables)

get_table_by_name

Get a table object by its name.

base.get_table_by_name(table_name)
Output Single table dict (None if there is no table named table_name)

Example

from seatable_api import Base, context

base = Base(context.api_token, context.server_url)
base.auth()
table = base.get_table_by_name('Table1')
print(table)

Add table

add_table

Add a table named table_name into a base. The columns argument is an optional list of column objects.

base.add_table(table_name, lang='en', columns=[]) # (1)!
  1. lang (optional): can be en (default) for English or zh-cn for Chinese and will determine the name of the first Name column (if no columns where specified) columns (optional): list of column objects describing the columns of the new table.

Output Single table dict (throws an error if a table named table_name already exists)

Example

from seatable_api import Base, context

base = Base(context.api_token, context.server_url)
base.auth()
new_table = base.add_table('Investigation', lang='zh-cn')
print(new_table)

from seatable_api import Base, context

base = Base(context.api_token, context.server_url)
base.auth()

columns=[
  {
    "column_type" : "text", 
    "column_name": "name"
  }, 
  {
  "column_type": "number",
  "column_name": "age"
  }
]

base.add_table("ScriptTest", lang='en', columns=columns)

Rename table

rename_table

Rename an existing table named table_name to new_table_name.

base.rename_table(table_name, new_table_name)
Output Dict containing a single success key with the result of the operation (throws an error if no table named table_name exists)

Example

from seatable_api import Base, context

base = Base(context.api_token, context.server_url)
base.auth()
print(base.rename_table('Table1', 'Table11'))
{'success': True}

Delete table

delete_table

Delete a table named tableName from the base. By the way, the table can be restored from the logs. Deleting the last table is not possible.

base.delete_table(table_name)

Output Dict containing a single success key with the result of the operation (throws an error if no table named table_name exists or if you try to delete the last table)

Example

from seatable_api import Base, context

base = Base(context.api_token, context.server_url)
base.auth()
delete_table_success = print(base.delete_table('Table1'))
print(delete_table_success)