You need to enable JavaScript to run this app.
文档中心
E-MapReduce

E-MapReduce

复制全文
下载 pdf
最佳实践
使用 Lance Python SDK 访问 TOS 上的 Lance 数据
复制全文
下载 pdf
使用 Lance Python SDK 访问 TOS 上的 Lance 数据

安装 Lance Python SDK

pip install ve-pylance

使用案例

读取案例

import lance
ds = lance.dataset(
    "s3://{PATH}",
    storage_options={
        "access_key_id": "<用户实际的AK>",
        "secret_access_key": "<用户实际的SK>",
        "aws_endpoint": "https://{bucket name}.{S3 Endpoint}.ivolces.com",
        "virtual_hosted_style_request": "true"
    }
)
print(ds.to_table().to_pandas())

参数说明

  • PATH:对象存储的路径,包含桶名,例:s3://bucket1/test/lance.db
  • AK/SK:访问秘钥。
  • aws_endpoint:TOS 的 S3 Endpoint ,必须使用https协议, Endpoint 路径中必须包含桶名,且为 VirtualHost 模式。
    华北2为例:
    • 如在火山引擎的ECS上运行,Endpoint的地址请使用: https://bucket1.tos-s3-cn-beijing.ivolces.com。
    • 如在本地的机器上运行,使用公网地址: https://bucket1.tos-s3-cn-beijing.volces.com。

    说明

    其中ivolces代表内网访问, volces代表从公网访问。

  • virtual_hosted_style_request:必须为 True。

注意

目前 TOS 的 S3 地址只支持 VirtualHost 使用方式。

写入案例

import lance
import pyarrow as pa

table = pa.Table.from_pylist([{"name": "Alice", "age": 20},
                              {"name": "Bob", "age": 30}])
schema = pa.schema([
        pa.field("name", pa.string()),
        pa.field("age", pa.int64()),
    ])

storage_options={
        "access_key_id": "<用户实际的AK>",
        "secret_access_key": "<用户实际的SK>",
        "aws_endpoint": "https://bucket1.tos-s3-cn-beijing.ivolces.com",
        "virtual_hosted_style_request": "true"
    }
lance.write_dataset(table, "s3://{PATH}", schema, storage_options=storage_options)
最近更新时间:2025.09.09 20:04:36
这个页面对您有帮助吗?
有用
有用
无用
无用