Bakthat 0.4.5 released, introducing a new helper: KeyValue

Sometimes, you need to be able to quickly backup/restore data without storing them as files, like a complex configuration object or simply string, here comes KeyValue.

KeyValue is a simple "key value store" that allows you to quickly store/retrieve strings/objects on Amazon S3. All values are serialized with json, so you can directly backup any json serializable value.

You can check out bakthat documentation here.

It works only with S3 (since with glacier, there is a 3-5 hours restore time).

KeyValue allows you to backup directly any string, or python object that can be json encoded and backups can be easily managed/restored with bakthat command line tool.

It can also takes care of compressing (with gzip) and encrypting (optional).

from bakthat.helper import KeyValue
import json

bakthat_conf = {'access_key': 'YOURACCESSKEY',
                'secret_key': 'YOURSECRETKEY',
                'glacier_vault': 'yourvault',
                's3_bucket': 'yours3bucket',
                'region_name': 'es-east-1'}

kv = KeyValue(conf=bakthat_conf)

mydata = {"some": "data"}
kv.set_key("mykey", mydata)

mydata_restored = kv.get_key("mykey")

data_url = kv.get_key_url("mykey", 60)  # url expires in 60 secondes

kv.delete_key("mykey")

kv.set_key("my_encrypted_key", "myvalue", password="mypassword")
kv.get_key("my_encrypted_key", password="mypassword")

# You can also disable gzip compression if you want:
kv.set_key("my_non_compressed_key", {"my": "data"}, compress=False)

That's it. Please don't hesitate to leave feedback, ideas or to ask whatever questions you have.

You should follow me on Twitter

Share this article

Tip with Bitcoin

Tip me with Bitcoin and vote for this post!

1FKdaZ75Ck8Bfc3LgQ8cKA8W7B86fzZBe2

Leave a comment

© Thomas Sileo. Powered by Pelican and hosted by DigitalOcean.