Friday 9 September 2011

Easily access Cloud computing and files with python libcloud

I heard about libcloud on the podcast FLOSS 181, it makes it easy to access cloud things from Python. This example code lists all the file objects in all containers, to use this you will need to modify the API_ constants to your account.



import libcloud.storage.providers, libcloud.storage.types

API_USERNAME = "xxxxxxxx"
API_PASSWORD = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
API_PROVIDER = libcloud.storage.types.Provider.CLOUDFILES_UK

storage = libcloud.storage.providers.get_driver(API_PROVIDER)(
    API_USERNAME, API_PASSWORD)

for container in storage.list_containers():
    print "Container: %s" % container.name
    for fileobj in container.list_objects():
        print "> Object: \"%s\", Size: %d bytes" % (
            fileobj.name, fileobj.size) 

No comments:

Post a Comment