Buckets & Bucket Types

Buckets are both namespaces for the key-value pairs you store in Riak, and containers for properties that apply to that namespace. In older versions of Riak, this was the only logical organization available. Now a higher-level collection called a Bucket Type can group buckets together. They allow for efficiently setting properties on a group of buckets at the same time.

Unlike buckets, Bucket Types must be explicitly created and activated before being used:

riak-admin bucket-type create n_equals_1 '{"props":{"n_val":1}}'
riak-admin bucket-type activate n_equals_1

Bucket Type creation and activation is only supported via the riak-admin bucket-type command-line tool. Riak 2.0 does not include an API to perform these actions, but the Python client can retrieve and set bucket-type properties.

If Bucket Types are not specified, the default bucket type is used. These buckets should be created via the bucket() method on the client object, like so:

import riak

client = riak.RiakClient()
mybucket = client.bucket('mybucket')

Buckets with a user-specified Bucket Type can also be created via the same bucket() method with an additional parameter or explicitly via bucket_type():

othertype = client.bucket_type('othertype')
otherbucket = othertype.bucket('otherbucket')

# Alternate way to get a bucket within a bucket-type
mybucket = client.bucket('mybucket', bucket_type='mybuckettype')

For more detailed discussion, see Using Bucket Types.

Bucket objects

Bucket properties

Bucket properties are flags and defaults that apply to all keys in the bucket.

Shortcuts for common properties

Some of the most commonly-used bucket properties are exposed as object properties as well. The getters and setters simply call RiakBucket.get_property() and RiakBucket.set_property() respectively.

Working with keys

The primary purpose of buckets is to act as namespaces for keys. As such, you can use the bucket object to create, fetch and delete objects.

Query operations


Similar to RiakClient, buckets can register custom transformation functions for media-types. When undefined on the bucket, RiakBucket.get_encoder() and RiakBucket.get_decoder() will delegate to the client associated with the bucket.

Listing keys

Shortcuts for RiakClient.get_keys() and RiakClient.stream_keys() are exposed on the bucket object. The same admonitions for these operations apply.

Bucket Type objects

Bucket Type properties

Bucket Type properties are flags and defaults that apply to all buckets in the Bucket Type.


The assigned datatype for this bucket type, if present.

Return type:None or str

Listing buckets

Shortcuts for RiakClient.get_buckets() and RiakClient.stream_buckets() are exposed on the bucket type object. This is similar to Listing keys on buckets.

Deprecated Features

Shortcuts for Riak Search 1.0

When Riak Search 1.0 is enabled on the server, you can toggle which buckets have automatic indexing turned on using the search bucket property (and on older versions, the precommit property). These methods simplify interacting with that configuration.

Legacy Counters

The get_counter() and update_counter(). See Legacy Counters for more details.


Legacy counters are incompatible with Bucket Types.