Python¶
Python scripts connect to SeaTable bases with the library seatable-api. The source code is available on GitHub.
The same library is used both inside SeaTable scripts and in external Python programs. The only difference is how you authenticate. All objects and methods work identically in both contexts.
Installation¶
Not needed for scripts inside SeaTable
When running scripts directly in SeaTable (via the built-in Python editor), seatable-api is already available. No installation required.
Script vs. External Client¶
| Script in SeaTable | External client | |
|---|---|---|
| Authentication | context.api_token (automatic) | API token or account credentials (manual) |
context object | Available | Not available |
current_row (button execution) | Available | Not available |
| Python version | 3.12 | Your choice |
| Available libraries | Predefined set | Unlimited |
| Execution | SeaTable server (Python Pipeline) | Your own machine/server |
Authentication¶
In a SeaTable script¶
Within SeaTable's integrated Python editor, the context object provides the authentication credentials automatically:
from seatable_api import Base, context
base = Base(context.api_token, context.server_url)
base.auth()
In an external program¶
When running Python on your own machine or server, you provide the API token and server URL directly. API tokens can be generated in the SeaTable web interface.
from seatable_api import Base
API_TOKEN = 'your-api-token' # (1)!
SERVER_URL = 'https://cloud.seatable.io'
base = Base(API_TOKEN, SERVER_URL)
base.auth()
- Avoid exposing credentials directly in the code. Use environment variables or
.envfiles instead.
Authentication with account credentials
Instead of using an API token (which is specific to a base), you can authenticate with your SeaTable account credentials. This gives you access to all your bases.
from seatable_api import Account
account = Account(username, password, server_url)
account.auth()
base = account.get_base(workspace_id, base_name)
To find the workspace_id, open the base in your browser. The URL looks like https://cloud.seatable.io/workspace/84254/dtable/MyBase.
Handling authorization expiration
For long-running programs, authorization may expire. Catch AuthExpiredError to re-authenticate:
Base Operation Limits¶
Python scripts rely on the SeaTable API and are subject to rate and size limits. Tips to stay within limits:
- Be careful with operations in
fororwhileloops - Use batch operations whenever possible:
base.batch_append_rowsbase.batch_update_rowsbase.batch_delete_rowsbase.batch_update_links
- Learn more about optimizing your API calls