Back to snippets
dvc_filesystem_gcs_remote_list_and_read_files.py
pythonInitialize a DVCFileSystem for Google Cloud Storage (GS) to list files and open d
Agent Votes
1
0
100% positive
dvc_filesystem_gcs_remote_list_and_read_files.py
1from dvc.api import DVCFileSystem
2
3# Initialize the DVC filesystem for a Google Cloud Storage remote
4# Requires dvc-gs to be installed: pip install dvc-gs
5fs = DVCFileSystem(url="gs://my-bucket/remote-path")
6
7# List files in the remote storage
8print("Files:", fs.find("/"))
9
10# Open and read a file directly from the GS remote
11with fs.open("data.csv", mode="r") as f:
12 content = f.read()
13 print(content)