Bucket

class couchbase.bucket.Bucket(cluster: Cluster, bucket_name: str)

Create a Couchbase Bucket instance.

Exposes the operations which are available to be performed against a bucket. Namely the ability to access to Collections as well as performing management operations against the bucket.

Parameters:
  • cluster (Cluster) – A Cluster instance.

  • bucket_name (str) – Name of the bucket.

Raises:

BucketNotFoundException – If provided bucket_name cannot be found.

close() → None

Shuts down this bucket instance. Cleaning up all resources associated with it.

Warning

Use of this method is almost always unnecessary. Bucket resources should be cleaned up once the bucket instance falls out of scope. However, in some applications tuning resources is necessary and in those types of applications, this method might be beneficial.

collection(collection_name: str) → Collection

Creates a Collection instance of the specified collection.

Parameters:

collection_name (str) – Name of the collection to reference.

Returns:

A Collection instance of the specified collection.

Return type:

Collection

collections() → CollectionManager

Get a manager for the scopes and collections of this bucket.

Returns:

A CollectionManager instance.

Return type:

CollectionManager

default_collection() → Collection

Creates a Collection instance of the default collection.

Returns:

A Collection instance of the default collection.

Return type:

Collection

default_scope() → Scope

Creates a Scope instance of the default scope.

Returns:

A Scope instance of the default scope.

Return type:

Scope

property name: str

The name of this bucket.

ping(opts: PingOptions | None = None, **kwargs: Unpack[PingOptionsKwargs]) → PingResult

Performs a ping operation against the bucket.

The ping operation pings the services which are specified (or all services if none are specified). Returns a report which describes the outcome of the ping operations which were performed.

Parameters:
  • opts (PingOptions) – Optional parameters for this operation.

  • **kwargs – keyword arguments that can be used in place or to override provided PingOptions

Returns:

A report which describes the outcome of the ping operations which were performed.

Return type:

PingResult

scope(name: str) → Scope

Creates a Scope instance of the specified scope.

Parameters:

name (str) – Name of the scope to reference.

Returns:

A Scope instance of the specified scope.

Return type:

Scope

view_indexes() → ViewIndexManager

Get a manager for the view design documents and views of this bucket.

Deprecated since version 4.6.0: Views are deprecated in Couchbase Server 7.0+, and will be removed from a future server version. Views are not compatible with the Magma storage engine. Instead of views, use indexes and queries using the Index Service (GSI) and the Query Service (SQL++).

Returns:

A ViewIndexManager instance.

Return type:

ViewIndexManager

view_query(design_doc: str, view_name: str, view_options: ViewOptions | None = None, **kwargs: Unpack[ViewOptionsKwargs]) → ViewResult

Executes a View query against the bucket.

Deprecated since version 4.6.0: Views are deprecated in Couchbase Server 7.0+, and will be removed from a future server version. Views are not compatible with the Magma storage engine. Instead of views, use indexes and queries using the Index Service (GSI) and the Query Service (SQL++).

Note

The query is executed lazily in that it is executed once iteration over the ViewResult begins.

See also

Parameters:
  • design_doc (str) – The name of the design document containing the view to execute.

  • view_name (str) – The name of the view to execute.

  • view_options (ViewOptions) – Optional parameters for the view query operation.

  • **kwargs – keyword arguments that can be used in place or to override provided ViewOptions

Returns:

An instance of a ViewResult which provides access to iterate over the query results and access metadata about the query.

Return type:

ViewResult

Examples

Simple view query:

from couchbase.management.views import DesignDocumentNamespace

# ... other code ...

view_result = bucket.view_query('ddoc-name',
                                'view-name',
                                limit=10,
                                namespace=DesignDocumentNamespace.DEVELOPMENT)

for row in view_result.rows():
    print(f'Found row: {row}')