Swift API Access to StorageGRID Webscale




This post gives a short overview how StorageGRID Webscale 10.2's Swift API can be accessed via Python through Python-Swiftclient.




First, we need to install the Swift Client for Python:


sudo pip install python-swiftclient


Next, we need to create a Swift Account in the StorageGRID NMS GUI by selecting: Grid Management -> Storage Tenants -> Tenant Accounts. After creating the new user, you can copy the Swift Tenant ID from the same view. This creates the API username in the format of "Swift Tenant ID:Swift Username".


API Examples


Connect to the StorageGRID Swift API Endpoint:


import swiftclient
username = '11071826158283910917:swiftadmin'
password = 'supersecret'
authurl = ''
swift = swiftclient.client.Connection(auth_version='1', user=username, key=password, insecure=True, authurl=authurl)

 In order to rely on proper TLS security, you can pass in a CA certificate:


cacert = '/path/to/server/cert'
swift = swiftclient.client.Connection(auth_version='1', user=username, key=password, cacert=cacert, authurl=authurl)

Now, we can start creating new containers via:



In order to list all containers, including various metrics, we can use the follow snippet:


response = swift.get_account()
containers = response[1]
for c in containers:
  name = c['name']
  num_objects = c['count']
  size = c['bytes']
  print("Container name: %s (total: %s objects, %s bytes)" % (name, num_objects, size))

We can delete an empty bucket via:




Finally, let's put some objects into StorageGRID and associate some metadata:


swift.put_object('test-container', 'test-object',
  contents='This is my object\'s content',

And, obviously, we also can retrieve our objects again:


response = swift.get_object('test-container', 'test-object')
object_headers = response[0]
object_content = response[1]
print "Object headers: ", object_headers
print "Object content: ", object_content

For more examples, visit https://github.com/csiebler/storagegrid-examples.

Feel free to reach out via @clemenssiebler