简体   繁体   English

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

[英]What is the equivalent of connecting to google cloud storage(gcs) like in aws s3 using s3fs?

I want to access google cloud storage as in the code below.我想访问谷歌云存储,如下面的代码所示。

# 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")

You're looking for gcsfs .您正在寻找gcsfs Both s3fs and gcsfs are part of the fsspec project and have very similar APIs. 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")

Note that both of these can be accessed from the fsspec interface, as long as you have the underlying drivers installed, eg:请注意,只要您安装了底层驱动程序,就可以从 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 is the file system handler underlying pandas and other libraries which parse cloud URLs. fsspec 是 pandas 和其他解析云 URL 的库的文件系统处理程序。 The reason the following "just works" is because fsspec is providing the cloud URI handling:以下“正常工作”的原因是因为 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")

You can use the cloud storage client libraries.您可以使用云存储客户端库。 They have an example in their docs .他们的文档中有一个示例。

If there's no client library for your language then you have to use the api though client libraries are available for python.如果您的语言没有客户端库,那么您必须使用api ,尽管客户端库可用于 python。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM