Boto3
Below example of how to list all containers and files in Swift using Boto3 and the S3 API. See S3 - Boto3 1.35.66 documentation for more information on how to use Boto3.
Replace aws_access_key_id and aws_secret_access_key with your S3 API keys.Â
#!/usr/bin/env python
import boto3
if __name__ == "__main__":
session = boto3.Session(
aws_access_key_id='AAABBBCCC111222333',
aws_secret_access_key='333222111CCCBBBAAA')
s3 = session.client('s3', endpoint_url='https://object.cloud.sdsc.edu')
buckets = s3.list_buckets()
for bucket in buckets['Buckets']:
print(bucket['Name'])
print('=======================')
paginator = s3.get_paginator('list_objects_v2')
pages = paginator.paginate(Bucket=bucket['Name'])
for page in pages:
if 'Contents' in page:
for object in page['Contents']:
print(object['Key'])