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
. Both s3fs and gcsfs are part of thefsspec
project and have very similar APIs.Note that both of these can be accessed from the fsspec interface, as long as you have the underlying drivers installed, e.g.:
fsspec is the file system handler underlying pandas and other libraries which parse cloud URLs. The reason the following "just works" is because fsspec is providing the cloud URI handling: