Articles on: API

Using the Leviia S3 API - Python

To manage your S3 objects and buckets at Leviia (in Python), you need the following library :


https://github.com/boto/boto3


You can install it with the following command :


pip install boto3


  1. Start by building a customer object :


import boto3


access_key = <VOTRE_ACCESS_KEY>
secret_key = <VOTRE_SECRETE_KEY>
url_s3_leviia = 'https://s3.leviia.com'


s3 = boto3.client(service_name='s3',
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
endpoint_url=url_s3_leviia,)

You can then use this object for your operations.


  1. To list your buckets :


# Retrieve the list of existing buckets
response = s3.list_buckets()

# Output the bucket names
print('Existing buckets:')
for bucket in response['Buckets']:
print(f'{bucket["Name"]}')


  1. To create a bucket :


test = s3.create_bucket(
Bucket='nouveau_bucket',
CreateBucketConfiguration={
'LocationConstraint': 'default',
},
)
print(test)


You'll find more examples of how to use boto3 at documentation.

Updated on: 08/01/2024

Was this article helpful?

Share your feedback

Cancel

Thank you!