gpt4 book ai didi

python - 使用 s3fs 连接到 aws s3 中的谷歌云存储(gcs)相当于什么?

转载 作者:行者123 更新时间:2023-12-05 02:28:46 27 4
gpt4 key购买 nike

我想按照下面的代码访问谷歌云存储。

# amazon s3 connection
import s3fs as fs

with fs.open("s3://mybucket/image1.jpg") as f:
image = Image.open(f).convert("RGB")


# Is there an equivalent code like this GCP side?
with cloudstorage.open("gs://my_bucket/image1.jpg") as f:
image = Image.open(f).convert("RGB")

最佳答案

您正在寻找 gcsfs . s3fs 和 gcsfs 都是 fsspec 的一部分项目并具有非常相似的 API。

import gcsfs

fs = gcsfs.GCSFileSystem()

with fs.open("gs://my_bucket/image1.jpg") as f:
image = Image.open(f).convert("RGB")

请注意,只要您安装了底层驱动程序,就可以从 fsspec 界面访问这两者,例如:

import fsspec

with fsspec.open('s3://my_s3_bucket/image1.jpg') as f:
image1 = Image.open(f).convert("RGB")

with fsspec.open('gs://my_gs_bucket/image1.jpg') as f:
image2 = Image.open(f).convert("RGB")

# fsspec handles local paths too!
with fsspec.open('/Users/myname/Downloads/image1.jpg') as f:
image3 = Image.open(f).convert("RGB")

fsspec 是 pandas 和其他解析云 URL 的库的文件系统处理程序。以下“正常工作”的原因是因为 fsspec 正在提供云 URI 处理:

pd.read_csv("s3://path/to/my/aws.csv")
pd.read_csv("gs://path/to/my/google.csv")
pd.read_csv("my/local.csv")

关于python - 使用 s3fs 连接到 aws s3 中的谷歌云存储(gcs)相当于什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72552217/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com