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 — Provide a way to retrieve gcloud config programmatically · Issue #1934 · googleapis/google-cloud-python

Provide a way to retrieve gcloud config programmatically #1934

New issue
Copy link
New issue
Copy link
Closed
Closed
Provide a way to retrieve gcloud config programmatically#1934
Copy link
Assignees
lukesneeringer
Labels
authtype: questionRequest for information or clarification. Not an issue.

Description

@nikhilk
nikhilk
opened on Jun 29, 2016
Issue body actions

especially things like default project id.

Activity

  1. daspecster commented on Jun 29, 2016

    @daspecster
    daspecster
    on Jun 29, 2016
    Contributor
    More actions

    @nikhilk, You can get the current client project ID via client.project

    Was there something else you're trying to access?

  2. nikhilk commented on Jun 29, 2016

    @nikhilk
    nikhilk
    on Jun 29, 2016
    Author
    More actions

    I must be missing something obvious. I tried the following two:

    pip install gcloud

    import gcloud
    gcloud.client.project

    -- as well as --

    import gcloud.client
    gcloud.client.project

    -- then tried to instantiate Client --
    c = gcloud.client.Client()
    but get an error about no app default credentials being available.

    Can you help with the exact code I need to use?

  3. daspecster commented on Jun 29, 2016

    @daspecster
    daspecster
    on Jun 29, 2016
    Contributor
    More actions

    You can use the gcloud sdk cli tool to get your default credentials as outline here.

    After that, your last example should work.

    from gcloud import pubsub  # Or whichever service you need
    client = pubsub.Client()
    client.project

    You can also use $ gcloud config list project from the cli to get the project ID if you have the SDK installed.

  4. daspecster
    added
    type: questionRequest for information or clarification. Not an issue.
    auth
    on Jun 29, 2016
  5. daspecster
    self-assigned this
    on Jun 29, 2016
  6. dhermes commented on Jun 29, 2016

    @dhermes
    dhermes
    on Jun 29, 2016
    Contributor
    More actions

    This project is distinct from the gcloud SDK. You'd want to ask that team for such an API. @jgeewax @jonparrott who would be the person to reach out to for that?

    Reacted by Thomas Schultz
  7. nikhilk commented on Jun 30, 2016

    @nikhilk
    nikhilk
    on Jun 30, 2016
    Author
    More actions

    The desire was to use a programmatic API rather than calling gcloud as a subprocess (which is what we do right now). Yes, ideally this would be functionality gcloud would expose as a library, but gcloud-python seemed like the next logical thing.

    So from the example above, it seems if you create a client for a particular service, you can get the project off of it. I guess I would be expected there be a way to get the project without needing to first create a client instance for a specific service, but I suppose that is a possible workaround that could work.

  8. tseaver commented on Jun 30, 2016

    @tseaver
    tseaver
    on Jun 30, 2016
    Contributor
    More actions

    gcloud._helpers._determine_default_project is the function the various Client classes use to sniff a project (the datastore client tweaks it a bit to deal with the emulator). It isn't public, but we could look at making it so. Note that the logic there is not related (directly) to the gcloud CLI's notion of determining the project.

    Reacted by Thomas Schultz and Alfonso Montero López
  9. daspecster commented on Jul 6, 2016

    @daspecster
    daspecster
    on Jul 6, 2016
    Contributor
    More actions

    @nikhilk do you think that @tseaver's answer will work for you?

  10. lukesneeringer
    closed this as completedon Apr 19, 2017
  11. lukesneeringer
    unassigned
    daspecster
    on Apr 19, 2017
  12. jgeewax commented on Apr 19, 2017

    @jgeewax
    jgeewax
    on Apr 19, 2017
    Contributor
    More actions

    I'm not sure this has been settled... It seems like we have a way to do it that is private and not documented, and we should look at potentially exposing this... Re-opening for discussion, feel free to re-close if there was an off-line conversation that was omitted here.

  13. jgeewax
    reopened this on Apr 19, 2017
  14. dhermes commented on Apr 19, 2017

    @dhermes
    dhermes
    on Apr 19, 2017
    Contributor
    More actions

    @jgeewax That is outside our purview. If people want to use what we do it is all in public surfaces provided by https://github.com/GoogleCloudPlatform/google-auth-library-python/

  15. dhermes
    closed this as completedon Apr 19, 2017
  16. timonbimon commented on Oct 8, 2018

    @timonbimon
    timonbimon
    on Oct 8, 2018
    More actions

    hey do i understand correctly that there is no way currently to access the currently active account (that i could get with 'gcloud auth list' on the command line) programmatically via python?

    Reacted by melissachang, Ryan Williams and karan bhatia
  17. tseaver commented on Oct 8, 2018

    @tseaver
    tseaver
    on Oct 8, 2018
    Contributor
    More actions

    @timonbimon Unlike the gcloud CLI, the google-cloud-* libraries do not keep any persistent store of credentials: we use the service account credentials file explicitly set in the environment (GOOGLE_APPLICATION_CREDENTIALS), or passed explicitly to the client's from_service_account_json method (we fall back from those to the implicit ones: gcloud SDK, GAE, or GCE)

    If you have a client instance, you can query its project attribute to get the named project associated with the client's credentials. Two of the API clients (bigquery and storage) expose a get_service_account_email method which returns the e-mail address associated with the client.

    While we don't currently expose the _credentials attribute of client instances as a public API for any client except spanner's: you could use the private attribute to get information using the interface provided by google.auth.credentials.Signing.signer_email.

  18. JustinBeckwith
    assigned
    lukesneeringer
    on Feb 1, 2021
  19. parthea
    added 3 commits that reference this issue on Mar 2, 2026

    fix: removes `content-header` from AWS IMDS get request (#1934)

    6cd4191

    chore: librarian release pull request: 20260121T162706Z (#1946)

    4598454

    chore(deps): update all dependencies (#1934)

    d06e813
  20. parthea
    added a commit that references this issue on Apr 1, 2026

    feat: Add CSS styling for TableWidget pagination interface (#1934)

    bd63ef7
  21. parthea
    added a commit that references this issue on Sep 8, 2026

    docs: migrate code from googleapis/python-bigquery (#18303)

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

Metadata

Metadata

Assignees

  • @lukesneeringer
    lukesneeringer

Labels

authtype: questionRequest for information or clarification. Not an issue.

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.