{"action":"closed","issue":{"url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-python/issues/861","labels_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-python/issues/861/labels{/name}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-python/issues/861/comments","events_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-python/issues/861/events","html_url":"https://github.com/GoogleCloudPlatform/gcloud-python/issues/861","id":73402634,"number":861,"title":"Explore going the route of using Clients ?","user":{"login":"jgeewax","id":112928,"avatar_url":"https://avatars.githubusercontent.com/u/112928?v=3","gravatar_id":"","url":"https://api.github.com/users/jgeewax","html_url":"https://github.com/jgeewax","followers_url":"https://api.github.com/users/jgeewax/followers","following_url":"https://api.github.com/users/jgeewax/following{/other_user}","gists_url":"https://api.github.com/users/jgeewax/gists{/gist_id}","starred_url":"https://api.github.com/users/jgeewax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgeewax/subscriptions","organizations_url":"https://api.github.com/users/jgeewax/orgs","repos_url":"https://api.github.com/users/jgeewax/repos","events_url":"https://api.github.com/users/jgeewax/events{/privacy}","received_events_url":"https://api.github.com/users/jgeewax/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-python/labels/auth","name":"auth","color":"bfdadc"},{"url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-python/labels/core","name":"core","color":"f7c6c7"},{"url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-python/labels/hygiene","name":"hygiene","color":"bfdadc"},{"url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-python/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-python/milestones/16","html_url":"https://github.com/GoogleCloudPlatform/gcloud-python/milestones/Core%20Future","labels_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-python/milestones/16/labels","id":963982,"number":16,"title":"Core Future","description":"","creator":{"login":"jgeewax","id":112928,"avatar_url":"https://avatars.githubusercontent.com/u/112928?v=3","gravatar_id":"","url":"https://api.github.com/users/jgeewax","html_url":"https://github.com/jgeewax","followers_url":"https://api.github.com/users/jgeewax/followers","following_url":"https://api.github.com/users/jgeewax/following{/other_user}","gists_url":"https://api.github.com/users/jgeewax/gists{/gist_id}","starred_url":"https://api.github.com/users/jgeewax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgeewax/subscriptions","organizations_url":"https://api.github.com/users/jgeewax/orgs","repos_url":"https://api.github.com/users/jgeewax/repos","events_url":"https://api.github.com/users/jgeewax/events{/privacy}","received_events_url":"https://api.github.com/users/jgeewax/received_events","type":"User","site_admin":false},"open_issues":15,"closed_issues":11,"state":"open","created_at":"2015-02-03T18:05:34Z","updated_at":"2015-08-27T00:39:25Z","due_on":null,"closed_at":null},"comments":60,"created_at":"2015-05-05T19:08:48Z","updated_at":"2015-08-27T00:39:25Z","closed_at":"2015-08-27T00:39:25Z","body":"After our last talk, there have been quite a few different ideas tossed around to make it clear and obvious which credentials and project IDs are in use during a particular API call, some of those have been....\r\n\r\n1. Changing the default values globally\r\n1. Making \"Connections\" a context manager (`with connection: # do something`)\r\n1. Creating the concept of a client\r\n\r\nWe do (1), are talking about doing (2), while the others tend to do (3) -- and comparing the code, I think (3) is the nicest. \r\n\r\ngcloud-node:\r\n\r\n```javascript\r\nvar gcloud = require('gcloud');\r\nvar project1_storage = gcloud.storage({projectId: 'project1', keyFilename: '/path/to/key'});\r\nvar project2_storage_auto = gcloud.storage();\r\n\r\n# Do things with the two \"clients\"...\r\nbucket1 = project1_storage.get_bucket('bucket-1')\r\nbucket2 = project2_storage_auto.get_bucket('bucket2')\r\n```\r\n\r\ngcloud-ruby\r\n\r\n```ruby\r\nrequire 'gcloud/storage'\r\nproject1_storage = Gcloud.storage \"project-id-1\" \"/path/to/key\"\r\nproject2_storage_auto = Gcloud.storage  # Magically figure out the project ID and credentials\r\n\r\n# Do things with the two \"clients\"...\r\nbucket1 = project1_storage.find_bucket \"bucket-1\"\r\nbucket2 = project2_storage_auto.find_bucket \"bucket-2\"\r\n```\r\n\r\ngcloud-python\r\n\r\n```python\r\nfrom gcloud import storage\r\nfrom gcloud.credentials import get_for_service_account_json\r\n\r\n# Create two different credentials.\r\ncredentials1 = get_for_service_account_json('key1.json')\r\ncredentials2 = get_for_service_account_json('key2.json')\r\n\r\n# Create two different connections.\r\nconnection1 = storage.Connection(credentials=credentials1)\r\nconnection2 = storage.Connection(credentials=credentials2)\r\n\r\n# Get two different buckets\r\nbucket1 = storage.get_bucket('bucket-1', project='project1', connection=connection1)\r\nbucket2 = storage.get_bucket('bucket-2', project='project2', connection=connection2)\r\n```\r\n\r\ngcloud-python if we followed the client pattern:\r\n\r\n```python\r\nfrom gcloud import storage\r\n\r\nproject1_storage = storage.Client('project1', '/path/to/key')\r\nproject2_storage_auto = storage.Client()\r\n\r\n# Do things with the two \"clients\"...\r\nbucket1 = project1_storage.get_bucket('bucket-1')\r\nbucket2 = project2_storage_auto.get_bucket('bucket-2')\r\n```\r\n\r\nAnother option for gcloud-python using the client pattern:\r\n\r\n```python\r\nimport gcloud\r\n\r\nproject1_storage = gcloud.storage('project1', '/path/to/key')\r\nproject2_storage_auto = gcloud.storage()\r\n\r\n# Do things with the two \"clients\"\r\nbucket1 = project1_storage.get_bucket('bucket-1')\r\nbucket2 = project2_storage_auto.get_bucket('bucket-2')\r\n```\r\n\r\n/cc @dhermes @tseaver "}}