> ## 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 Drive - Python

###### Initialisation :

Cette partie de code doit être au début de votre programme.

```python
import xml.etree.ElementTree as ET;
import requests;

domain = "cloud.leviia.com";
auth=('user', 'password');
url = "https://"+domain+"/remote.php/dav/files/"+auth[0];
```
_Remplacez « user » et « password » par votre identifiant et [votre mot de passe d'application](https://wiki.leviia.com/fr/article/generer-votre-mot-de-passe-dapplication-tz9g9d/)._

###### Lister le contenu d'un dossier :

```python
path = "/path/on/leviia";

r = requests.request('PROPFIND', url+path, data=None, auth=auth);
data = ET.fromstring(r.text);
list = [el[0].text for el in data];
print(list);
```
###### Récupérer un fichier :

```python
path = "/path/on/leviia";

r = requests.request('GET', url+path, auth=auth);
open('/path/local', 'wb').write(r.content);
```
###### Envoyer un fichier :

```python
path = "/path/on/leviia";

file = open("/path/on/computeur", "rb");
r = requests.request('PUT', url+path, data=file, auth=auth);
```
###### Créer un dossier :

```python
path = "/path/on/leviia";

r = requests.request('MKCOL', url+path, auth=auth);```

###### Supprimer un fichier/dossier :

```python
path = "/path/on/leviia";

r = requests.request('DELETE', url+path, auth=auth);
```
###### Déplacer un fichier/dossier :

```python
path = "/path/on/leviia";

r = requests.request('MOVE', url+path, data=None,headers={"Destination":url+"/new/path"}, auth=auth);
```
###### Copier un fichier/dossier :

```python
path = "/path/on/leviia";

r = requests.request('COPY', url+path, data=None,headers={"Destination":url+"/new/path"}, auth=auth);
```
