Network and cloud-based storage

A core feature of simplekv is the ability to transparently store data using cloud storage services like Amazon S3 and Google Storage. This is achieved by providing a backend that utilizes boto (preferably >= 2.25).

Note that boto is not a dependency for simplekv. You need to install it “manually”, otherwise you will see an ImportError.

Here is a short example:

from simplekv.net.botostore import BotoStore
import boto

con = boto.connect_s3('your_access_key', 'your_secret_key')

# use get_bucket instead, if you already have one!
bucket = con.create_bucket('simplekv-testbucket')

store = BotoStore(bucket)

# at this point, we can use the store like any other
store.put('some-key', 'Hello, World!')

# print out what's behind some-key. you should be able to see it
# in the bucket now as well
print store.get('some-key')

Unit testing

The unit-tests for the boto storage can only run if you have access to a Google Storage and/or Amazon S3 account. The tests will look in a file boto_credentials in the simplekv source root folder for account credentials, here is an example file:

[s3]
access_key = YOUR_AMAZON_S3_ACCESS_KEY
secret_key = YOUR_AMAZON_S3_SECRET_KEY
connect_func = connect_s3

[gs]
access_key = YOUR_GOOGLE_STORAGE_ACCESS_KEY
secret_key = YOUR_GOOGLE_STORAGE_SECRET_KEY
connect_func = connect_gs

If a section is not present, the tests for that backend will be skipped.

class simplekv.net.boto.BotoStore

Backend using the storage api of boto.

__init__(bucket, prefix='', url_valid_time=0, reduced_redundancy=False, public=False, metadata=None)

Constructs a new boto based backend.

Parameters:
  • bucket – An instance of boto.s3.bucket.Bucket, boto.gs.bucket.Bucket or similiar.
  • prefix – A string that will transparently prefixed to all handled keys.
  • url_valid_time=0 – When using url_for(), URLs should be valid for this many seconds at most.
  • reduced_redundancy – Use reduced redundancy storage for storing keys.
  • public – If set, all newly updated values will be made public immediately.
  • metadata – If set, for all newly created keys to be saved with these metadata values.