GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GCS Blob does not support the io.IOBase interface · Issue #3903 · googleapis/google-cloud-python

GCS Blob does not support the io.IOBase interface #3903

New issue
Copy link
New issue
Copy link
Closed
Closed
GCS Blob does not support the io.IOBase interface#3903
Copy link
Assignees
chemelnucfin
Labels
api: storageIssues related to the Cloud Storage API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Description

@eap
eap
opened on Aug 30, 2017
Issue body actions

I'm branching this issue from the (currently resolved) issue #2871. The title covers the request, but to add some context see below.

Many python libraries (pandas, biopython, pillow, etc.) support reading from a 'python file object' which canonically are objects that implement the io.IOBase interface. If we could open a blob as a file object, we could do operations as shown in the example below where I'm just reading a few lines from a (possibly very large) file.

from Bio import SeqIO
from google.cloud.storage import blob

with blob.Blob('/data/example.fastq', 'mybucket').open('rb') as fileobj:
    for i, rec in enumerate(SeqIO.parse(fileobj, 'fastq')):
        print(rec.seq)
        print('  name=%s\n  annotations=%r' % (rec.name, rec.annotations))
        if i > 5:
            break

google-resumable-media covers some of the need expressed in this bug, but it does not satisfy users who need blobs to be parsed by libraries expecting standard file objects. The standard advice might be to download files first but that advice ignores the expense and time of downloading large files when indexed operations are available.

Some work has been done towards this end - the following two repositories have solutions. That said, I think most people would be far more happy to adopt a solution from this project since it has a far larger community and more active maintenance / governance.

  • https://github.com/Akrog/gcs-client
  • https://github.com/martindurant/gcsfs
Reacted by JP Martin, William Myers, roger6106, Kevin Locke, Yannick Einsweiler, John, Illia Derets, Ole Jørgen Brønner, François BAPTISTE, Samuel Carlsson and 7 more

Activity

  1. lukesneeringer
    assigned
    dhermes
    on Sep 1, 2017
  2. lukesneeringer
    added
    api: storageIssues related to the Cloud Storage API.
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    on Sep 1, 2017
  3. lukesneeringer commented on Sep 1, 2017

    @lukesneeringer
    lukesneeringer
    on Sep 1, 2017
    Contributor
    More actions

    @dhermes Any thoughts on how long it would take to implement a file-like interface on Blob?

  4. dhermes commented on Sep 5, 2017

    @dhermes
    dhermes
    on Sep 5, 2017
    Contributor
    More actions

    We already have Blob.download_to_file that takes a write-able stream. google-resumable-media allows manual chunking during downloads:

    >>> download = ChunkedDownload(
    ...     media_url, chunk_size, stream)
    >>> response = download.consume_next_chunk(transport)

    It might be easiest to support this if ChunkedDownload.consume_next_chunk just took an optional chunk_size argument that over-rides the instance's chunk size. Then fake_file.read(chunk_size) could be implemented in some wrapper.

    I don't think it makes sense to add support for this in google-cloud-storage, and I'm 50-50 on whether we should actually provide the file-like wrapper. I am totally fine adding support for the per-chunk over-ride on chunk size to make it possible.

  5. eap commented on Sep 5, 2017

    @eap
    eap
    on Sep 5, 2017
    Author
    More actions

    @dhermes
    would the implementation you described be able to provide a seek operation? The most commonly used methods for reading Python file objects are read, seek, tell, readlines, and readline. The first three alone are incredibly important for programs that read indexed files.

    As for the larger question of supporting file-like interface: I have additional notes on the topic -

    1. File interfaces are core to many Python libraries and programs. Failing to provide a file interface in a google-endorsed library simply forces developers to re-invent this interface over and over again, or it forces them to rely on poorly maintained community contributions that may or may-not support new functionality like requester-pays buckets, and may also block or slow upgrades when security patches are needed.

    2. Supporting file objects would enable appengine standard environment to appengine flexible environment migrations. If you recall, the standard environment has a cloudstorage library that gives file handles for GCS blobs (see their docs here). Large applications with this dependency will need extensive rewrites if no equivalent functionality can be added to the non-appengine GCS interface.

  6. yan-hic commented on Nov 13, 2017

    @yan-hic
    yan-hic
    on Nov 13, 2017
    More actions

    I second this request, not only for reading but writing too.

    Why is it that only App Engine Standard has cloudstorage.open(<path_to_blob>,'w') ?

    Because not supported elsewhere, one needs to provision a VM or similar with sufficient disk or memory to buffer before writing.
    Once Google Functions supports Python (?), I assume - hope - a file-like storage object will exist there too.

    Could boto not help in the meantime ?

    Reacted by Max Voitko
  7. martindurant commented on Nov 21, 2017

    @martindurant
    martindurant
    on Nov 21, 2017
    More actions

    Thank @yiga2 for the pointer.

    Indeed, anyone that wants pythonic file-like access to GCS is welcome to use gcsfs.

    Reacted by Samuel Carlsson
  8. eap commented on Nov 21, 2017

    @eap
    eap
    on Nov 21, 2017
    Author
    More actions

    I think that writable file objects is better left for a different discussion since it seems like seekable writers would conflict with core GCS concepts thanks to object-immutability. I could imagine a case being made for a non-seekable writer; many Python programs that accept file handles only require the availability of write or writelines methods.

    Aside from general GCS concept difficulties, even a non-seekable writer creates caching and failure-handling headaches that aren't shared on the read-side of the IOBase interface implementation.

  9. chemelnucfin commented on Jan 22, 2018

    @chemelnucfin
    chemelnucfin
    on Jan 22, 2018
    Contributor
    More actions

    Hello, feature requests will now be tracked in the project Feature Requests. I will close this issue now, please feel free to continue to address any issues/concerns here.

  10. chemelnucfin
    closed this as completedon Jan 22, 2018
  11. theacodes
    unassigned
    dhermes
    on Sep 28, 2018
  12. JustinBeckwith
    assigned
    chemelnucfin
    on Feb 1, 2021
  13. parthea
    added a commit that references this issue on Jul 6, 2023

    chore(deps): update dependency google-auth to v1.16.0 [(#3903)](Googl…

    abccfab
  14. parthea
    added a commit that references this issue on Sep 22, 2023

    chore: move samples from python-docs-sample (#66)

    d3dcbbc
  15. parthea
    added a commit that references this issue on Oct 21, 2023

    move monitoring samples from python-docs-samples (#51)

    d95f563
  16. parthea
    added a commit that references this issue on Aug 21, 2025

    chore(deps): update dependency google-auth to v1.16.0 [(#3903)](Googl…

    60f55a7
  17. parthea
    added a commit that references this issue on Sep 16, 2025

    chore(deps): update dependency google-auth to v1.16.0 [(#3903)](Googl…

    d4f6e9c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @chemelnucfin
    chemelnucfin

Labels

api: storageIssues related to the Cloud Storage API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.