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 — Consider making buckets dictionary-like for cloud storage · Issue #29 · googleapis/google-cloud-python

Consider making buckets dictionary-like for cloud storage #29

New issue
Copy link
New issue
Copy link
Closed
Closed
Consider making buckets dictionary-like for cloud storage#29
Copy link
Assignees
tseaver
Labels
api: storageIssues related to the Cloud Storage API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
Milestone
Storage Stable

Description

@jgeewax
jgeewax
opened on Feb 19, 2014
Issue body actions

For example

connection = get_connection()
bucket = connection['bucket-name']
key = bucket['/path/to/file.txt']
del key

This would be a neat abstraction, though it's certainly not necessary.

Activity

Next
  1. jgeewax
    added
    enhancement
    on Feb 19, 2014
  2. jgeewax
    modified the milestone: Storage Stable on Jan 30, 2015
  3. dhermes commented on Feb 10, 2015

    @dhermes
    dhermes
    on Feb 10, 2015
    Contributor
    More actions

    RE: Our discussion today we want Connection to be stateless, so at best we want a Bucket to have __getitem__ defined (or to inherit from dict).

    Though given the observations from @thobrla in #545, Allowing

    blob = bucket['/remote/path/to/file.txt']

    would obscure the local / network interactions. What's more, via implicit behavior we can make it easy to create a reference to a blob and check if it exists:

    >>> blob = Blob('/remote/path/to/file.txt')
    >>> blob.exists()
    True
  4. dhermes
    changed the title [-]Consider making connections and buckets dictionary-like for cloud storage[/-] [+]Consider making buckets dictionary-like for cloud storage[/+] on Feb 10, 2015
  5. jgeewax commented on Feb 10, 2015

    @jgeewax
    jgeewax
    on Feb 10, 2015
    ContributorAuthor
    More actions

    I'm 👍 to giving buckets the __getitem__ type accessors.

    However, I think the code I'd rather see is:

    >>> blob = connection.blob('/remote/path/to/file.txt')
    >>> blob.exists()
    True

    I can see how Blob('/path/to/file.txt') would rely on the default connection, but it feels a tiny bit fishy to me that it has to figure out which credentials / project to use. (See related -- and just created -- #613)

  6. tseaver commented on Feb 11, 2015

    @tseaver
    tseaver
    on Feb 11, 2015
    Contributor
    More actions

    @jgeewax shouldn't your example read like so?

    >>> blob = bucket.blob('/remote/path/to/file.txt')
    >>> blob.exists()
    True
  7. jgeewax commented on Feb 11, 2015

    @jgeewax
    jgeewax
    on Feb 11, 2015
    ContributorAuthor
    More actions

    Yes -- sorry about that.

  8. tseaver
    self-assigned this
    on Feb 26, 2015
  9. tseaver commented on Feb 26, 2015

    @tseaver
    tseaver
    on Feb 26, 2015
    Contributor
    More actions

    OK, current status is:

    • storage.connection.Connection.get_bucket() incurs a network hit, and raises a NotFound on a miss.
    • storage.connection.Connection.create_bucket() incurs a network hit, and raises (Conflict, i.e. HTTP 409 status?) if the bucket exists already (API docs don't define error responses, and furthermore Carthago delenda est).
    • storage.bucket.Bucket.get_blob() incurs a network hit, and converts the NotFound on a miss to a None.
    • storage.bucket.Bucket.new_blob() does not incur a network hit.

    @jgeewax: IIUC, you would like Connection.__getitem__() to return a new Bucket instance, without the network hit, and have Bucket.exists() do that lookup if. Likewise, you would like Bucket.__getitem__() to return a new Blob instance, again without the network hit, and have Blob.exists() do that lookup.

    In this universe, I think Connection.get_bucket(), Connection.create_bucket(), Bucket.get_blob(), and Bucket.new_blob() would all disappear. Applications that wanted to ensure that a bucket or blob did or did not already exist would just call exits() and handle it themselves.

    This mode is somewhat counter-intuitive for Python programmers, who might reasonably expect __getitem__() to raise a KeyError on a miss. Unfortunately, we have to choose: a) do what I just proposed, and be less "Pythonic"; b) incur the network lookup (more "Pythonic" but worse at scale), or c) work out a mode for caching the buckets / blobs locally, and live with the pain / complexity of trying to do cache invalidation correctly.

  10. dhermes commented on Feb 26, 2015

    @dhermes
    dhermes
    on Feb 26, 2015
    Contributor
    More actions

    @tseaver We should move towards Connection being a low-level / power-user interface and put things in storage.api (like datastore.api). (RE: "Connection.__getitem__() to return a new Bucket")

    Overall I don't think __getitem__ can be done in a way that won't confound some users (will simultaneously pleasing others) since it is such a core language feature.

    I vote to close.

  11. dhermes
    closed this as completedon Mar 2, 2015
  12. vchudnov-g
    added a commit that references this issue on Apr 19, 2023

    fix(deps): require google-api-core>=1.31.5, >=2.3.2 (#29)

    e3b6486
  13. parthea
    added a commit that references this issue on Apr 20, 2023

    chore: Migrate code from googleapis/python-ids into packages/google-c…

    90d8f68
  14. 111 remaining items

  15. parthea
    added 6 commits that reference this issue on Nov 24, 2025

    test: fix mock credentials to allow for quota projects (#29)

    c6899e1

    chore: release 1.13.0 (#29)

    4551cc0

    chore: update templates (#29)

    64a139a

    chore: update repo-metadata.json (#29)

    cf7432e

    chore: fix trove classifier for release status to match version (#29)

    b5254ef

    port polymodel, with some required modifications to model (#29)

    e62936f
  16. parthea
    added 8 commits that reference this issue on Mar 2, 2026

    breaking: add 'google_' prefix to import name (#30)

    This issue will close once commit 01e869f is merged into the 'main' branch.
    01e869f

    Adding "requests" extra to `setup.py`.

    This issue will close once commit bc191e5 is merged into the 'main' branch.
    bc191e5

    dbapi: implement Cursor.executemany

    This issue will close once commit 9242000 is merged into the 'main' branch.
    9242000

    dbapi: implement Cursor.executemany()

    This issue will close once commit b3cc28f is merged into the 'main' branch.
    b3cc28f

    test: fix numeric compliance test (#29)

    This issue will close once commit 3c91fc0 is merged into the 'main' branch.
    3c91fc0

    feat: add blob.open() for file-like I/O (#385)

    This issue will close once commit f0aebdb is merged into the 'main' branch.
    f0aebdb

    docs: correct URLs for old issues (#29)

    This issue will close once commit 86f6807 is merged into the 'main' branch.
    86f6807

    chore(deps): update dependency sphinx to v4.0.2 (#29)

    This issue will close once commit d315293 is merged into the 'main' branch.
    d315293
  17. ohmayr
    added a commit that references this issue on Mar 31, 2026

    breaking: add 'google_' prefix to import name (#30)

    This issue will close once commit 2d80a0e is merged into the 'main' branch.
    2d80a0e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @tseaver
    tseaver

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

    • Storage Stable

    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.