> ## 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).

# Using the Leviia Drive API - Python

###### Initialization :

This part of the code must be at the beginning of your program.

```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];
```
_Replace "user" and "password" with your login and [your application password](https://wiki.leviia.com/en/article/generate-your-application-password-1jbdde7/)._

###### List the contents of a folder :

```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);
```

###### Recover a file :

```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);
```

###### Send a file :

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

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

###### Delete a file/folder :

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

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

###### Move a file/folder :

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

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

###### Copy a file/folder :

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

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