Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Support context manager, so each developer can use this module more efficiently #471

Closed

Description

@nnaka2992

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

Is your feature request related to a problem? Please describe.
Currently, the Client class does not support context manager. Supporting context manager would make programmers easy to write and maintenance their code.

Describe the solution you'd like
Add __enter__ method which returns self and __exit__ method to free instance in order to enable contextmanager. Works as following would be perfect.

with storage.Client() as client:
    bucket = client.get_bucket(bucket_name)
    blob = bucket.blob(file_name

Activity

  1. tseaver commented on Jun 21, 2021

    @tseaver
    Contributor

    As of googleapis/python-cloud-core#100 (merged released with google-cloud-core 1.7.0), the following works:

    import contextlib
    from google.cloud.storage import Client
    
    client = Client()
    
    with contextlib.closing(client):
        do_something_with(client)
    

    AFAICT, that addresses this feature request.

  2. danielduhh commented on Jun 22, 2021

    @danielduhh
    Contributor

    Should we bump our core dependency to 1.7.0? @tseaver

  3. tseaver commented on Jun 23, 2021

    @tseaver
    Contributor

    @danielduhh

    Should we bump our core dependency to 1.7.0?

    I don't think so -- google-cloud-storage works fine without that version, it is just missing this feature.

  4. added
    priority: p3Desirable enhancement or fix. May not be included in next release.
    on Jun 28, 2021
  5. danielduhh commented on Jun 28, 2021

    @danielduhh
    Contributor

    @nnaka2992 could you verify that pinning google-cloud-storage to >=1.7.0 resolves this issue?

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

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the googleapis/python-storage API.priority: p3Desirable enhancement or fix. May not be included in next release.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