Skip to content

gcs_fs

Google Cloud Storage FileSystem implementation.

This module provides GcsFs, a FileSystem backend for gs:// URLs delegating the operations to the top-level py_misc_utils.gcs_fs module. Reads go through the block-cache machinery (GCS supports pread) while writes are staged locally and uploaded on close.

CacheHandler

Bases: Handler

Object-cache handler creating per-bucket GcsFs instances.

Source code in py_misc_utils/fs/gcs_fs.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class CacheHandler(objc.Handler):
  """Object-cache handler creating per-bucket GcsFs instances."""

  def __init__(self, *args, **kwargs):
    """Initialize the handler with the GcsFs creation arguments.

    Args:
      *args: Positional arguments forwarded to GcsFs, such as the bucket.
      **kwargs: Keyword arguments forwarded to GcsFs.
    """
    super().__init__()
    # Positional and keyword arguments used to create the GcsFs.
    self._args = args
    self._kwargs = kwargs

  def create(self):
    """Create a new GcsFs for the bucket.

    Returns:
      A top-level GcsFs bound to the handler bucket.
    """
    return gcs.GcsFs(*self._args, **self._kwargs)

create()

Create a new GcsFs for the bucket.

Returns:

Type Description

A top-level GcsFs bound to the handler bucket.

Source code in py_misc_utils/fs/gcs_fs.py
41
42
43
44
45
46
47
def create(self):
  """Create a new GcsFs for the bucket.

  Returns:
    A top-level GcsFs bound to the handler bucket.
  """
  return gcs.GcsFs(*self._args, **self._kwargs)

GcsReader

Reader fetching data from GCS, supporting both pread and full reads.

Source code in py_misc_utils/fs/gcs_fs.py
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
class GcsReader:
  """Reader fetching data from GCS, supporting both pread and full reads."""

  def __init__(self, fs, path, sres):
    """Initialize the reader.

    Args:
      fs: GcsFs used for the reads.
      path: Path of the object to read.
      sres: Stat result of the object.
    """
    # GcsFs used for the reads, object path and its stat result.
    self._fs = fs
    self._path = path
    self._sres = sres

  @classmethod
  def tag(cls, sres):
    """Build a cache tag from a GCS stat result.

    Args:
      sres: Stat result of the object, as returned by GcsFs.stat().

    Returns:
      The object ETag, or a tag built from size and modification time.
    """
    return sres.etag or chf.make_tag(size=sres.st_size, mtime=sres.st_mtime)

  def support_blocks(self):
    """Return True since GCS supports pread operations."""
    return True

  def read_block(self, bpath, offset, size):
    """Read data into a local cache file.

    Args:
      bpath: Local path of the cache file to write the contents to.
      offset: Offset in the object where reading starts; WHOLE_OFFSET
        streams the whole object.
      size: Number of bytes to read.

    Returns:
      The number of bytes written into the cache file.
    """
    if offset != chf.CachedBlockFile.WHOLE_OFFSET:
      size = min(size, self._sres.st_size - offset)
      data = self._fs.pread(self._path, offset, size)

      with osfd.OsFd(bpath, os.O_CREAT | os.O_TRUNC | os.O_WRONLY, mode=0o440) as wfd:
        os.write(wfd, data)

      return len(data)
    else:
      with osfd.OsFd(bpath, os.O_CREAT | os.O_TRUNC | os.O_WRONLY, mode=0o440) as wfd:
        for data in self._fs.download(self._path):
          os.write(wfd, data)

      return os.path.getsize(bpath)

tag(sres) classmethod

Build a cache tag from a GCS stat result.

Parameters:

Name Type Description Default
sres

Stat result of the object, as returned by GcsFs.stat().

required

Returns:

Type Description

The object ETag, or a tag built from size and modification time.

Source code in py_misc_utils/fs/gcs_fs.py
66
67
68
69
70
71
72
73
74
75
76
@classmethod
def tag(cls, sres):
  """Build a cache tag from a GCS stat result.

  Args:
    sres: Stat result of the object, as returned by GcsFs.stat().

  Returns:
    The object ETag, or a tag built from size and modification time.
  """
  return sres.etag or chf.make_tag(size=sres.st_size, mtime=sres.st_mtime)

support_blocks()

Return True since GCS supports pread operations.

Source code in py_misc_utils/fs/gcs_fs.py
78
79
80
def support_blocks(self):
  """Return True since GCS supports pread operations."""
  return True

read_block(bpath, offset, size)

Read data into a local cache file.

Parameters:

Name Type Description Default
bpath

Local path of the cache file to write the contents to.

required
offset

Offset in the object where reading starts; WHOLE_OFFSET streams the whole object.

required
size

Number of bytes to read.

required

Returns:

Type Description

The number of bytes written into the cache file.

Source code in py_misc_utils/fs/gcs_fs.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
def read_block(self, bpath, offset, size):
  """Read data into a local cache file.

  Args:
    bpath: Local path of the cache file to write the contents to.
    offset: Offset in the object where reading starts; WHOLE_OFFSET
      streams the whole object.
    size: Number of bytes to read.

  Returns:
    The number of bytes written into the cache file.
  """
  if offset != chf.CachedBlockFile.WHOLE_OFFSET:
    size = min(size, self._sres.st_size - offset)
    data = self._fs.pread(self._path, offset, size)

    with osfd.OsFd(bpath, os.O_CREAT | os.O_TRUNC | os.O_WRONLY, mode=0o440) as wfd:
      os.write(wfd, data)

    return len(data)
  else:
    with osfd.OsFd(bpath, os.O_CREAT | os.O_TRUNC | os.O_WRONLY, mode=0o440) as wfd:
      for data in self._fs.download(self._path):
        os.write(wfd, data)

    return os.path.getsize(bpath)

GcsFs

Bases: FsBase

FileSystem implementation for gs:// URLs.

GcsFs instances are pooled per bucket through the object cache. Paths are relative to the bucket root, so the leading slash of the URL path is stripped before dispatching the operations to the underlying GcsFs.

The credentials are resolved by the google-cloud-storage machinery - from the GOOGLE_APPLICATION_CREDENTIALS environment variable or the environment default - and can be pointed at an emulator with the STORAGE_EMULATOR_HOST environment variable.

See py_misc_utils.fs for the shared backend contract.

Example
from py_misc_utils import cached_file as chf
from py_misc_utils.fs import gcs_fs as gf

iface = chf.CacheInterface('/tmp/gfs-cache')
fs = gf.GcsFs(cache_dir='/tmp/gfs-cache', cache_iface=iface)

with fs.open('gs://my-bucket/data/file.bin', mode='rb') as f:
  header = f.read(512)
Source code in py_misc_utils/fs/gcs_fs.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
class GcsFs(fsb.FsBase):
  """FileSystem implementation for gs:// URLs.

  GcsFs instances are pooled per bucket through the object cache. Paths are
  relative to the bucket root, so the leading slash of the URL path is
  stripped before dispatching the operations to the underlying GcsFs.

  The credentials are resolved by the google-cloud-storage machinery -
  from the GOOGLE_APPLICATION_CREDENTIALS environment variable or the
  environment default - and can be pointed at an emulator with the
  STORAGE_EMULATOR_HOST environment variable.

  See py_misc_utils.fs for the shared backend contract.

  Example:
    from py_misc_utils import cached_file as chf
    from py_misc_utils.fs import gcs_fs as gf

    iface = chf.CacheInterface('/tmp/gfs-cache')
    fs = gf.GcsFs(cache_dir='/tmp/gfs-cache', cache_iface=iface)

    with fs.open('gs://my-bucket/data/file.bin', mode='rb') as f:
      header = f.read(512)
  """

  ID = 'gcs'
  IDS = (ID,)

  def __init__(self, cache_iface=None, **kwargs):
    """Initialize the backend.

    Args:
      cache_iface: Optional cache interface customizing the caching of
        the remote contents.
      **kwargs: Extra keyword arguments forwarded to FsBase.
    """
    super().__init__(cache_iface=cache_iface, **kwargs)

  def _get_fs(self, bucket):
    """Get a pooled GcsFs for a bucket.

    Args:
      bucket: Name of the GCS bucket.

    Returns:
      The GcsFs instance from the object cache, shared per bucket.
    """
    handler = CacheHandler(bucket)
    name = ('GCSFS', bucket)

    return objc.cache().get(name, handler)

  def _parse_url(self, url):
    """Parse a gs:// URL and return its bucket filesystem.

    Args:
      url: gs:// URL to parse.

    Returns:
      A tuple with the GcsFs of the URL bucket and the parsed URL with the
      leading slash of the path removed.
    """
    purl = uparse.urlparse(url)
    purl = purl._replace(path=purl.path.lstrip('/'))
    fs = self._get_fs(purl.hostname)

    return fs, purl

  def _make_reader(self, fs, purl):
    """Create a reader and metadata for the remote object.

    Args:
      fs: GcsFs of the URL bucket.
      purl: Parsed gs:// URL.

    Returns:
      A tuple with the GcsReader and the cache Meta describing the object.
    """
    sres = fs.stat(purl.path)
    tas.check_is_not_none(sres,
                          exception=FileNotFoundError,
                          msg=f'File does not exist: {purl.geturl()}')

    tag = GcsReader.tag(sres)
    meta = chf.Meta(size=sres.st_size, mtime=sres.st_mtime, tag=tag)
    reader = GcsReader(fs, purl.path, sres)

    return reader, meta

  def _parse_samefs(self, src_url, dest_url):
    """Parse two URLs and check they refer to the same bucket.

    Args:
      src_url: Source gs:// URL.
      dest_url: Destination gs:// URL.

    Returns:
      A tuple with the (filesystem, parsed URL) pair for the source and
      for the destination.
    """
    src_fs, src_purl = self._parse_url(src_url)
    dest_fs, dest_purl = self._parse_url(dest_url)

    tas.check_eq(src_fs.bucket, dest_fs.bucket,
                 msg=f'Source and destination URL must be on the same bucket: ' \
                 f'{src_url} vs. {dest_url}')

    return (src_fs, src_purl), (dest_fs, dest_purl)

  def _copy(self, src_url, dest_url):
    """Server-side copy an object within the same bucket."""
    (src_fs, src_purl), (_, dest_purl) = self._parse_samefs(src_url, dest_url)

    src_fs.copy(src_purl.path, dest_purl.path)

  def remove(self, url):
    """Remove an object.

    Args:
      url: gs:// URL of the object to remove.
    """
    fs, purl = self._parse_url(url)
    fs.remove(purl.path)

  def rename(self, src_url, dest_url):
    """Rename an object within the same bucket.

    Args:
      src_url: gs:// URL of the source object.
      dest_url: gs:// URL of the destination object.
    """
    (src_fs, src_purl), (_, dest_purl) = self._parse_samefs(src_url, dest_url)

    src_fs.rename(src_purl.path, dest_purl.path)

  def mkdir(self, url, mode=None):
    """No-op since GCS has no real directories."""

  def makedirs(self, url, mode=None, exist_ok=None):
    """No-op since GCS has no real directories."""

  def rmdir(self, url):
    """No-op since GCS has no real directories."""

  def rmtree(self, url, ignore_errors=None):
    """Recursively remove all the objects under a URL.

    Args:
      url: gs:// URL of the prefix to remove.
      ignore_errors: When True errors raised while removing the objects
        are logged instead of propagating.
    """
    fs, purl = self._parse_url(url)

    fs.rmtree(purl.path, ignore_errors=ignore_errors or False)

  def stat(self, url):
    """Stat an object.

    Args:
      url: gs:// URL to stat.

    Returns:
      The DirEntry of the object.

    Raises:
      FileNotFoundError: If the object does not exist.
    """
    fs, purl = self._parse_url(url)

    dentry = fs.stat(purl.path)
    tas.check_is_not_none(dentry,
                          exception=FileNotFoundError,
                          msg=f'Not found: {purl.hostname}:{purl.path}')

    return dentry

  def list(self, url):
    """List the entries under a URL.

    Args:
      url: gs:// URL of the prefix to enumerate.

    Returns:
      A list of DirEntry objects for the objects under the prefix.
    """
    fs, purl = self._parse_url(url)

    return fs.listdir(purl.path)

  def open(self, url, mode, **kwargs):
    """Open a URL for reading or writing.

    Read modes are served through the block-cache interface, while write
    modes download the existing contents when truncation is not requested
    and wrap the stream into a WritebackFile uploading on close.

    Args:
      url: gs:// URL to open.
      mode: Open mode string.
      **kwargs: Extra keyword arguments forwarded to the cache interface.

    Returns:
      A file-like object, wrapped into a TextIOWrapper in text modes.
    """
    fs, purl = self._parse_url(url)

    if self.read_mode(mode):
      reader, meta = self._make_reader(fs, purl)
      cfile = self._cache_iface.open(url, meta, reader, **kwargs)

      return io.TextIOWrapper(cfile) if self.text_mode(mode) else cfile
    else:
      writeback_fn = functools.partial(self._upload_file, url)
      if not self.truncate_mode(mode) and fs.exists(purl.path):
        url_file = self._download_file(url)
        self.seek_stream(mode, url_file)
      else:
        # The WritebackFile owns the temp file's lifetime.
        url_file = tempfile.TemporaryFile()  # noqa: SIM115

      wbfile = wbf.WritebackFile(url_file, writeback_fn)

      return io.TextIOWrapper(wbfile) if self.text_mode(mode) else wbfile

  def _upload_file(self, url, stream):
    """Rewind a stream and upload its contents to the given URL.

    Args:
      url: Destination gs:// URL of the upload.
      stream: Seekable file-like object with the contents to upload.
    """
    stream.seek(0)
    self.put_file(url, fsu.enum_chunks(stream))

  def _download_file(self, url):
    """Download the contents of a URL into a temporary file.

    Args:
      url: gs:// URL to download.

    Returns:
      A seekable temporary file with the downloaded contents.
    """
    with cm.Wrapper(tempfile.TemporaryFile()) as ftmp:
      for data in self.get_file(url):
        ftmp.v.write(data)

      return ftmp.detach()

  def put_file(self, url, data_gen):
    """Upload data chunks to a URL.

    Args:
      url: Destination gs:// URL of the upload.
      data_gen: Iterable of bytes chunks to upload.
    """
    fs, purl = self._parse_url(url)

    fs.upload(purl.path, data_gen)

  def get_file(self, url):
    """Read the contents of a URL.

    Args:
      url: gs:// URL to read.

    Returns:
      A generator yielding the file contents as bytes chunks.
    """
    fs, purl = self._parse_url(url)

    return fs.download(purl.path)

  def as_local(self, url, **kwargs):
    """Return a local file with the contents of a URL.

    Args:
      url: gs:// URL of the file to access.
      **kwargs: Extra keyword arguments forwarded to the cache interface.

    Returns:
      The path of the local file, downloaded through the cache interface.
    """
    fs, purl = self._parse_url(url)
    reader, meta = self._make_reader(fs, purl)

    return self._cache_iface.as_local(url, meta, reader, **kwargs)

  def link(self, src_url, dest_url):
    """Copy an object, since GCS has no hard links.

    Args:
      src_url: gs:// URL of the source object.
      dest_url: gs:// URL of the destination object.
    """
    self._copy(src_url, dest_url)

  def symlink(self, src_url, dest_url):
    """Copy an object, since GCS has no symbolic links.

    Args:
      src_url: gs:// URL of the source object.
      dest_url: gs:// URL of the destination object.
    """
    self.link(src_url, dest_url)

remove(url)

Remove an object.

Parameters:

Name Type Description Default
url

gs:// URL of the object to remove.

required
Source code in py_misc_utils/fs/gcs_fs.py
225
226
227
228
229
230
231
232
def remove(self, url):
  """Remove an object.

  Args:
    url: gs:// URL of the object to remove.
  """
  fs, purl = self._parse_url(url)
  fs.remove(purl.path)

rename(src_url, dest_url)

Rename an object within the same bucket.

Parameters:

Name Type Description Default
src_url

gs:// URL of the source object.

required
dest_url

gs:// URL of the destination object.

required
Source code in py_misc_utils/fs/gcs_fs.py
234
235
236
237
238
239
240
241
242
243
def rename(self, src_url, dest_url):
  """Rename an object within the same bucket.

  Args:
    src_url: gs:// URL of the source object.
    dest_url: gs:// URL of the destination object.
  """
  (src_fs, src_purl), (_, dest_purl) = self._parse_samefs(src_url, dest_url)

  src_fs.rename(src_purl.path, dest_purl.path)

mkdir(url, mode=None)

No-op since GCS has no real directories.

Source code in py_misc_utils/fs/gcs_fs.py
245
246
def mkdir(self, url, mode=None):
  """No-op since GCS has no real directories."""

makedirs(url, mode=None, exist_ok=None)

No-op since GCS has no real directories.

Source code in py_misc_utils/fs/gcs_fs.py
248
249
def makedirs(self, url, mode=None, exist_ok=None):
  """No-op since GCS has no real directories."""

rmdir(url)

No-op since GCS has no real directories.

Source code in py_misc_utils/fs/gcs_fs.py
251
252
def rmdir(self, url):
  """No-op since GCS has no real directories."""

rmtree(url, ignore_errors=None)

Recursively remove all the objects under a URL.

Parameters:

Name Type Description Default
url

gs:// URL of the prefix to remove.

required
ignore_errors

When True errors raised while removing the objects are logged instead of propagating.

None
Source code in py_misc_utils/fs/gcs_fs.py
254
255
256
257
258
259
260
261
262
263
264
def rmtree(self, url, ignore_errors=None):
  """Recursively remove all the objects under a URL.

  Args:
    url: gs:// URL of the prefix to remove.
    ignore_errors: When True errors raised while removing the objects
      are logged instead of propagating.
  """
  fs, purl = self._parse_url(url)

  fs.rmtree(purl.path, ignore_errors=ignore_errors or False)

stat(url)

Stat an object.

Parameters:

Name Type Description Default
url

gs:// URL to stat.

required

Returns:

Type Description

The DirEntry of the object.

Raises:

Type Description
FileNotFoundError

If the object does not exist.

Source code in py_misc_utils/fs/gcs_fs.py
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
def stat(self, url):
  """Stat an object.

  Args:
    url: gs:// URL to stat.

  Returns:
    The DirEntry of the object.

  Raises:
    FileNotFoundError: If the object does not exist.
  """
  fs, purl = self._parse_url(url)

  dentry = fs.stat(purl.path)
  tas.check_is_not_none(dentry,
                        exception=FileNotFoundError,
                        msg=f'Not found: {purl.hostname}:{purl.path}')

  return dentry

list(url)

List the entries under a URL.

Parameters:

Name Type Description Default
url

gs:// URL of the prefix to enumerate.

required

Returns:

Type Description

A list of DirEntry objects for the objects under the prefix.

Source code in py_misc_utils/fs/gcs_fs.py
287
288
289
290
291
292
293
294
295
296
297
298
def list(self, url):
  """List the entries under a URL.

  Args:
    url: gs:// URL of the prefix to enumerate.

  Returns:
    A list of DirEntry objects for the objects under the prefix.
  """
  fs, purl = self._parse_url(url)

  return fs.listdir(purl.path)

open(url, mode, **kwargs)

Open a URL for reading or writing.

Read modes are served through the block-cache interface, while write modes download the existing contents when truncation is not requested and wrap the stream into a WritebackFile uploading on close.

Parameters:

Name Type Description Default
url

gs:// URL to open.

required
mode

Open mode string.

required
**kwargs

Extra keyword arguments forwarded to the cache interface.

{}

Returns:

Type Description

A file-like object, wrapped into a TextIOWrapper in text modes.

Source code in py_misc_utils/fs/gcs_fs.py
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
def open(self, url, mode, **kwargs):
  """Open a URL for reading or writing.

  Read modes are served through the block-cache interface, while write
  modes download the existing contents when truncation is not requested
  and wrap the stream into a WritebackFile uploading on close.

  Args:
    url: gs:// URL to open.
    mode: Open mode string.
    **kwargs: Extra keyword arguments forwarded to the cache interface.

  Returns:
    A file-like object, wrapped into a TextIOWrapper in text modes.
  """
  fs, purl = self._parse_url(url)

  if self.read_mode(mode):
    reader, meta = self._make_reader(fs, purl)
    cfile = self._cache_iface.open(url, meta, reader, **kwargs)

    return io.TextIOWrapper(cfile) if self.text_mode(mode) else cfile
  else:
    writeback_fn = functools.partial(self._upload_file, url)
    if not self.truncate_mode(mode) and fs.exists(purl.path):
      url_file = self._download_file(url)
      self.seek_stream(mode, url_file)
    else:
      # The WritebackFile owns the temp file's lifetime.
      url_file = tempfile.TemporaryFile()  # noqa: SIM115

    wbfile = wbf.WritebackFile(url_file, writeback_fn)

    return io.TextIOWrapper(wbfile) if self.text_mode(mode) else wbfile

put_file(url, data_gen)

Upload data chunks to a URL.

Parameters:

Name Type Description Default
url

Destination gs:// URL of the upload.

required
data_gen

Iterable of bytes chunks to upload.

required
Source code in py_misc_utils/fs/gcs_fs.py
360
361
362
363
364
365
366
367
368
369
def put_file(self, url, data_gen):
  """Upload data chunks to a URL.

  Args:
    url: Destination gs:// URL of the upload.
    data_gen: Iterable of bytes chunks to upload.
  """
  fs, purl = self._parse_url(url)

  fs.upload(purl.path, data_gen)

get_file(url)

Read the contents of a URL.

Parameters:

Name Type Description Default
url

gs:// URL to read.

required

Returns:

Type Description

A generator yielding the file contents as bytes chunks.

Source code in py_misc_utils/fs/gcs_fs.py
371
372
373
374
375
376
377
378
379
380
381
382
def get_file(self, url):
  """Read the contents of a URL.

  Args:
    url: gs:// URL to read.

  Returns:
    A generator yielding the file contents as bytes chunks.
  """
  fs, purl = self._parse_url(url)

  return fs.download(purl.path)

as_local(url, **kwargs)

Return a local file with the contents of a URL.

Parameters:

Name Type Description Default
url

gs:// URL of the file to access.

required
**kwargs

Extra keyword arguments forwarded to the cache interface.

{}

Returns:

Type Description

The path of the local file, downloaded through the cache interface.

Source code in py_misc_utils/fs/gcs_fs.py
384
385
386
387
388
389
390
391
392
393
394
395
396
397
def as_local(self, url, **kwargs):
  """Return a local file with the contents of a URL.

  Args:
    url: gs:// URL of the file to access.
    **kwargs: Extra keyword arguments forwarded to the cache interface.

  Returns:
    The path of the local file, downloaded through the cache interface.
  """
  fs, purl = self._parse_url(url)
  reader, meta = self._make_reader(fs, purl)

  return self._cache_iface.as_local(url, meta, reader, **kwargs)

Copy an object, since GCS has no hard links.

Parameters:

Name Type Description Default
src_url

gs:// URL of the source object.

required
dest_url

gs:// URL of the destination object.

required
Source code in py_misc_utils/fs/gcs_fs.py
399
400
401
402
403
404
405
406
def link(self, src_url, dest_url):
  """Copy an object, since GCS has no hard links.

  Args:
    src_url: gs:// URL of the source object.
    dest_url: gs:// URL of the destination object.
  """
  self._copy(src_url, dest_url)

Copy an object, since GCS has no symbolic links.

Parameters:

Name Type Description Default
src_url

gs:// URL of the source object.

required
dest_url

gs:// URL of the destination object.

required
Source code in py_misc_utils/fs/gcs_fs.py
408
409
410
411
412
413
414
415
def symlink(self, src_url, dest_url):
  """Copy an object, since GCS has no symbolic links.

  Args:
    src_url: gs:// URL of the source object.
    dest_url: gs:// URL of the destination object.
  """
  self.link(src_url, dest_url)