Retrieve list of buckets in cluster using Python SDK


#1

I’m attempting to retrieve a list of buckets in a cluster using the Python SDK, but so far can’t find out exactly how to get it…

I’m currently setting up a connection to my cluster using

cluster = Cluster('couchbase://localhost')
authenticator = PasswordAuthenticator('admin', 'password')
cluster.authenticate(authenticator)

but I don’t see any way to list the buckets available on the cluster. Is there a way to do it, or am I stuck heading out to the CLI for that option?


#2

Hi, I’m afraid you are correct that there isn’t a direct way to retrieve a list of buckets in a cluster in Python. We do store the list in the _buckets member variable as an implementation detail but this isn’t supposed to be used externally. The supported way would be to use the REST API: https://developer.couchbase.com/documentation/server/5.1/rest-api/rest-endpoints-all.html

However, I will add this feature for the next release, which should be in the next week or two. Here is the JIRA:

https://issues.couchbase.com/browse/PYCBC-476

Many thanks,

Ellis


#3

Hi Ellis,

That sounds great, thank you for the swift action.

To extend on the question, is there a way to list production views on a bucket, or it that doable through the REST API as well?

Kindly,
Stefan Finseth


#4

Hi, I’m not aware of such a function - you would need to use REST calls for that, I think, for now. These look like the relevant endpoints:

https://developer.couchbase.com/documentation/server/5.1/rest-api/rest-views-intro.html