dlt s3 集成试用

属于一个简单试用,dlt 支持destinations 为filesystem,当然也支持source 为filesystem,内部处理是使用了s3fs

环境准备

这个比较简单,推荐基于venv

  • dlt
pip install dlt[filesystem]
  • s3

通过docker 部署,同时可以需要创建demo bucket

version: "3"
services:
  minio:
    image: minio/minio
    ports:
      - "9000:9000"
      - "19001:19001"
    environment:
      MINIO_ACCESS_KEY: minio
      MINIO_SECRET_KEY: minio123
    command: server --console-address :19001 --quiet /data
  • 配置文件系统的key

可以直接在项目的.dlt 文件夹下.dlt/secrets.toml

[destination.filesystem]
bucket_url = "s3://demo" # replace with your bucket name,
[destination.filesystem.credentials]
aws_access_key_id = "minio" # copy the access key here
aws_secret_access_key = "minio123" # copy the secret access key here
endpoint_url = "http://localhost:9000" # copy your endpoint URL here

数据处理

  • s3.py
import dlt
 
data = [{'id': 1, 'name': 'John','age':111}, {'id': 2, 'name': 'Jane'}]
 
pipeline = dlt.pipeline(
    pipeline_name="dalong",
    destination='filesystem',
    dataset_name='postgres_data'
)
 
load_info = pipeline.run(
    data,
    write_disposition="merge",
    table_name='postgres_data',
    # 数据存储为parquet 格式
    loader_file_format='parquet',
)
 
print(load_info)
  • 执行效果
python s3.py

s3 数据效果

说明

注意filesystem 对于merge 模式是不支持的,会后退为append,以上是一个简单的集成测试,还是挺强大的,值得试试

参考资料

https://dlthub.com/docs/dlt-ecosystem/destinations/filesystem
https://dlthub.com/docs/general-usage/credentials/configuration

posted on 2024-02-17 08:00  荣锋亮  阅读(7)  评论(0编辑  收藏  举报

导航