Articles on: API

Using the Leviia Drive API - Python

Initialization :

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

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

domain = "";
auth=('user', 'password');
url = "https://"+domain+"/remote.php/dav/files/"+auth[0];

Replace "user" and "password" with your login and your application password.

List the contents of a folder :

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];

Recover a file :

path = "/path/on/leviia";

r = requests.request('GET', url+path, auth=auth);
open('/path/local', 'wb').write(r.content);

Envoyer un fichier :

path = "/path/on/leviia";

file = open("/path/on/computeur", "rb");
r = requests.request('PUT', url+path, data=file, auth=auth);

Send a file :

path = "/path/on/leviia";

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

Delete a file/folder :

path = "/path/on/leviia";

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

Move a file/folder :

path = "/path/on/leviia";

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

Copy a file/folder :

path = "/path/on/leviia";

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

Updated on: 08/01/2024

Was this article helpful?

Share your feedback


Thank you!