Skip to main content

WebDAV client, based on original package https://github.com/designerror/webdav-client-python but uses requests instead of PyCURL

Project description

webdavclient3

Build Status Quality Gate Status Coverage PyPI PyPI - Python Version

Package webdavclient3 based on https://github.com/designerror/webdav-client-python but uses requests instead of PyCURL. It provides easy way to work with WebDAV-servers.

Installation

$ pip install webdavclient3

Sample Usage

from webdav3.client import Client
options = {
 'webdav_hostname': "https://webdav.server.ru",
 'webdav_login':    "login",
 'webdav_password': "password"
}
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)
client.session.proxies(...) # To set proxy directly into the session (Optional)
client.session.auth(...) # To set proxy auth directly into the session (Optional)
client.execute_request("mkdir", 'directory_name')

Webdav API

Webdav API is a set of webdav methods of work with cloud storage. This set includes the following methods: check, free, info, list, mkdir, clean, copy, move, download, upload, publish and unpublish.

Configuring the client

Required keys for configuring client connection with WevDAV-server are webdav_hostname and webdav_login, webdav_password.

from webdav3.client import Client

options = {
 'webdav_hostname': "https://webdav.server.ru",
 'webdav_login':    "login",
 'webdav_password': "password"
}
client = Client(options)

When a proxy server you need to specify settings to connect through it.

from webdav3.client import Client
options = {
 'webdav_hostname': "https://webdav.server.ru",
 'webdav_login':    "w_login",
 'webdav_password': "w_password", 
 'proxy_hostname':  "http://127.0.0.1:8080",
 'proxy_login':     "p_login",
 'proxy_password':  "p_password"
}
client = Client(options)

If you want to use the certificate path to certificate and private key is defined as follows:

from webdav3.client import Client
options = {
 'webdav_hostname': "https://webdav.server.ru",
 'webdav_login':    "w_login",
 'webdav_password': "w_password",
 'cert_path':       "/etc/ssl/certs/certificate.crt",
 'key_path':        "/etc/ssl/private/certificate.key"
}
client = Client(options)

Or you want to limit the speed or turn on verbose mode:

options = {
 ...
 'recv_speed' : 3000000,
 'send_speed' : 3000000,
 'verbose'    : True
}
client = Client(options)

recv_speed: rate limit data download speed in Bytes per second. Defaults to unlimited speed.
send_speed: rate limit data upload speed in Bytes per second. Defaults to unlimited speed.
verbose: set verbose mode on/off. By default verbose mode is off.

Also if your server does not support check it is possible to disable it:

options = {
 ...
 'disable_check': True
}
client = Client(options)

By default checking of remote resources is enabled.

Synchronous methods

# Checking existence of the resource

client.check("dir1/file1")
client.check("dir1")
# Get information about the resource

client.info("dir1/file1")
client.info("dir1/")
# Check free space

free_size = client.free()
# Get a list of resources

files1 = client.list()
files2 = client.list("dir1")
# Create directory

client.mkdir("dir1/dir2")
# Delete resource

client.clean("dir1/dir2")
# Copy resource

client.copy(remote_path_from="dir1/file1", remote_path_to="dir2/file1")
client.copy(remote_path_from="dir2", remote_path_to="dir3")
# Move resource

client.move(remote_path_from="dir1/file1", remote_path_to="dir2/file1")
client.move(remote_path_from="dir2", remote_path_to="dir3")
# Move resource

client.download_sync(remote_path="dir1/file1", local_path="~/Downloads/file1")
client.download_sync(remote_path="dir1/dir2/", local_path="~/Downloads/dir2/")
# Unload resource

client.upload_sync(remote_path="dir1/file1", local_path="~/Documents/file1")
client.upload_sync(remote_path="dir1/dir2/", local_path="~/Documents/dir2/")
# Publish the resource

link = client.publish("dir1/file1")
link = client.publish("dir2")
# Unpublish resource

client.unpublish("dir1/file1")
client.unpublish("dir2")
# Exception handling

from webdav3.client import WebDavException
try:
...
except WebDavException as exception:
...
# Get the missing files

client.pull(remote_directory='dir1', local_directory='~/Documents/dir1')
# Send missing files

client.push(remote_directory='dir1', local_directory='~/Documents/dir1')

Asynchronous methods

# Load resource

kwargs = {
 'remote_path': "dir1/file1",
 'local_path':  "~/Downloads/file1",
 'callback':    callback
}
client.download_async(**kwargs)

kwargs = {
 'remote_path': "dir1/dir2/",
 'local_path':  "~/Downloads/dir2/",
 'callback':    callback
}
client.download_async(**kwargs)
# Unload resource

kwargs = {
 'remote_path': "dir1/file1",
 'local_path':  "~/Downloads/file1",
 'callback':    callback
}
client.upload_async(**kwargs)

kwargs = {
 'remote_path': "dir1/dir2/",
 'local_path':  "~/Downloads/dir2/",
 'callback':    callback
}
client.upload_async(**kwargs)

Resource API

Resource API using the concept of OOP that enables cloud-level resources.

# Get a resource

res1 = client.resource("dir1/file1")
# Work with the resource

res1.rename("file2")
res1.move("dir1/file2")
res1.copy("dir2/file1")
info = res1.info()
res1.read_from(buffer)
res1.read(local_path="~/Documents/file1")
res1.read_async(local_path="~/Documents/file1", callback)
res1.write_to(buffer)
res1.write(local_path="~/Downloads/file1")
res1.write_async(local_path="~/Downloads/file1", callback)

Release Notes

Version 0.14 – TBD

  • Fixed an issue with checking resources on Yandex WebDAV server

Version 0.13 – 27.11.2019

Version 0.12 - 21.06.2019

Version 0.11 – 30.03.2019

Version 0.10 – 31.01.2019

Version 0.9 – 10.05.2018

Version 0.8 – 07.05.2018

Version 0.7 – 16.03.2018

Version 0.6 – 21.02.2018

Version 0.5 – 03.12.2017

  • Added method for setting of WebDAV resource property values in batch

Version 0.4 - 27.11.2017

  • Refactoring of WebDAV client and making it works in following methods:
    • Checking is remote resource directory
    • Fixed problem when connection lost during request executing and nothing was happened, now it raises an exception

Version 0.3 - 18.10.2017

  • Refactoring of WebDAV client and making it works in following methods:
    • Getting of WebDAV resource property value
    • Setting of WebDAV resource property value
    • Coping of resource on WebDAV server
    • Moving of resource on WebDAV server
    • Deleting of resource on WebDAV server
    • Getting of information about WebDAV resource

Version 0.2 - 11.09.2017

  • Refactoring of WebDAV client and making it works in following methods:
    • Constructor with connecting to WebDAV
    • Getting a list of resources on WebDAV
    • Getting an information about free space on WebDAV
    • Checking of existence of resource on WebDAV
    • Making a directory on WebDAV
    • Downloading of files and directories from WebDAV
    • Asynchronously downloading of files and directories from WebDAV
    • Uploading of files and directories to WebDAV
    • Asynchronously uploading of files and directories to WebDAV

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for webdavclient3, version 0.14
Filename, size File type Python version Upload date Hashes
Filename, size webdavclient3-0.14.tar.gz (27.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page