Skip to main content

异步版本的 SeaTable API Python 客户端,基于 aiohttp 实现

Project description

SeaTable API Async

PyPI version Python License

异步版本的 SeaTable API Python 客户端库,基于 seatable-api-python 改造,使用 aiohttpasync/await 实现完全异步操作。

特性

  • 完全异步 - 基于 aiohttpasync/await,支持高并发操作
  • WebSocket 支持 - 内置 SocketIO 客户端,支持实时事件推送
  • 自动 Token 管理 - JWT token 自动刷新,无需手动干预
  • 批量操作 - 支持批量增删改,提高数据处理效率
  • 分块操作 - 自动处理大数据集,突破 SeaTable API 单次请求限制(新增 v0.3.0)
  • 完整功能 - 覆盖表、行、列、视图、链接、评论、文件上传等所有核心 API

安装

# 使用 pip
pip install seatable-api-async

# 使用 uv
uv add seatable-api-async

快速开始

AccountApi 操作

import asyncio
from seatable_api_async import AccountApiAsync

async def main():
    async with AccountApiAsync(
        login_name="your_email@example.com",
        password="your_password",
        server_url="https://cloud.seatable.io"
    ) as account:
        # 列出工作区
        workspaces = await account.list_workspaces()

        # 获取 Base API Token
        token = await account.get_temp_api_token(
            workspace_id=1,
            dtable_name="My Base"
        )

if __name__ == "__main__":
    asyncio.run(main())

SeatableApi 操作

from seatable_api_async import SeaTableApiAsync

async def main():
    async with SeaTableApiAsync(
        token="your_api_token",
        server_url="https://cloud.seatable.io"
    ) as base:
        # 列出行
        rows = await base.list_rows("Table1")

        # 添加行
        await base.append_row("Table1", {"Name": "Alice", "Age": 30})

        # 批量添加
        await base.batch_append_rows("Table1", [
            {"Name": "Bob", "Age": 25},
            {"Name": "Charlie", "Age": 35}
        ])

        # SQL 查询
        results = await base.query("SELECT * FROM Table1 WHERE Age > 25")

if __name__ == "__main__":
    asyncio.run(main())

WebSocket 实时通讯

from seatable_api_async import SeaTableApiAsync, SocketIOAsync

async def main():
    async with SeaTableApiAsync(token, server_url) as base:
        # 使用 async with 自动管理连接
        async with SocketIOAsync(base) as socket:
            @socket.on("custom_event")
            async def handle_event(data):
                print(f"Received: {data}")

            await socket.emit("my_event", {"data": "hello"})
            # 退出时自动断开连接

if __name__ == "__main__":
    asyncio.run(main())

API 文档

官方文档

使用说明

详细的 API 方法请参考同步版本 seatable-api 文档,所有方法名称保持一致,只需添加 await 关键字。

主要模块:

  • AccountApiAsync - 账户管理、工作区操作
  • SeaTableApiAsync - Base 操作、表/行/列/视图管理、SQL 查询
  • SocketIOAsync - WebSocket 实时通讯

API 限制

  • 批量操作(batch_append/update_rows):最多 1,000 行/请求
  • 批量删除(batch_delete_rows):最多 10,000 行/请求
  • 列出行(list_rows):最多 1,000 行/请求
  • SQL 查询返回:最多 10,000 行
  • 速率限制:SeaTable Cloud 200 请求/分钟(Base 操作)

开发建议

使用异步上下文管理器

async with SeaTableApiAsync(token, server_url) as api:
    rows = await api.list_rows("Table1")
# 会话自动关闭

批量操作优先

# 推荐 - 使用批量操作
await api.batch_append_rows("Table1", rows)

# 避免 - 循环单个操作
for row in rows:
    await api.append_row("Table1", row)  # 性能较差

处理大数据集(分块操作)

当数据量超过 SeaTable API 限制时,使用 _chunked 方法自动分块处理:

# 添加超过 1000 行的数据
rows = [{"Name": f"User {i}", "Age": 20} for i in range(5000)]
await api.batch_append_rows_chunked("Table1", rows, chunk_size=1000)

# 获取所有行(自动分页)
all_rows = await api.list_rows_chunked("Table1", max_rows=10000)

# 更新大量数据
updates = [{"row_id": row["_id"], "row": {"Status": "Processed"}} for row in all_rows]
await api.batch_update_rows_chunked("Table1", updates)

# 删除大量行
row_ids = [row["_id"] for row in all_rows]
await api.batch_delete_rows_chunked("Table1", row_ids)

# 使用进度回调监控进度
def progress_callback(processed, total):
    print(f"进度: {processed}/{total} ({processed*100//total}%)")

await api.batch_append_rows_chunked(
    "Table1",
    large_dataset,
    progress_callback=progress_callback
)

可用的分块方法:

  • batch_append_rows_chunked() - 添加大量行(>1000)
  • batch_update_rows_chunked() - 更新大量行(>1000)
  • batch_delete_rows_chunked() - 删除大量行(>10000)
  • list_rows_chunked() - 获取所有行(>1000)
  • batch_add_links_chunked() - 添加大量链接(>1000)
  • batch_remove_links_chunked() - 删除大量链接(>1000)
  • batch_update_links_chunked() - 更新大量链接(>1000)

测试

# 配置环境变量
cp .env_template .env

# 运行测试
pytest tests/

贡献

欢迎贡献代码!请 Fork 本仓库,创建特性分支,提交 Pull Request。

许可证

本项目基于 Apache License 2.0 开源协议。

链接

致谢

本项目基于 seatable-api,感谢 SeaTable 团队的优秀工作。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

seatable_api_async-0.3.0.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

seatable_api_async-0.3.0-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file seatable_api_async-0.3.0.tar.gz.

File metadata

  • Download URL: seatable_api_async-0.3.0.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for seatable_api_async-0.3.0.tar.gz
Algorithm Hash digest
SHA256 220c199349b61de4dab05fd72f6059017355711c4aeb9f24ea33505e333545bc
MD5 9321bf018272e034238064daf6e3ffee
BLAKE2b-256 e3175ba7b50e645937a95aa31844011f12c69a800bc55d7114e1531fcc388ce3

See more details on using hashes here.

File details

Details for the file seatable_api_async-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: seatable_api_async-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 23.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for seatable_api_async-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f9a379179940b6be0823b211f26dc0e9b188d30f437b83335f3e044b7cb2760
MD5 8524d3300a45458ce7e3b2f9faf63d0b
BLAKE2b-256 ec16f9386107027c9529a39c7f1659eefaff06b8180a233de606bc2310de4773

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page