> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://wiki.leviia.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Utiliser l'API Leviia S3 - Python

Pour gérer vos objects et vos bucket S3 chez Leviia (en python), vous devez utiliser la librairie suivante : 

https://github.com/boto/boto3

Vous pouvez l'installer avec l'aide de la commande suivante :

```bash
pip install boto3
```

1. Commencez par vous construire un objet client :

```python
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,)
```

Par la suite, vous pourrez utiliser cet objet pour vos opérations. 

2. Pour lister vos buckets :

```python
# 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"]}')
```

3. Pour créer un bucket :

```python

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

Vous trouverez d'autres exemples d'utilisation de boto3 sur [la documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-examples.html). 