Python client library for WebDAV

Question:

I’d like to implement a piece of functionality in my application that uploads and manipulates files on a WebDAV server. I’m looking for a mature Python library that would give an interface similar to the os.* modules for working with the remote files. Googling has turned up a smattering of options for WebDAV in Python, but I’d like to know which are in wider use these days.

Asked By: Kamil Kisiel

||

Answers:

I don’t know of any specifically but, depending on your platform, it may be simpler to mount and access the WebDAV-served files through the file system. There’s davfs2 out there and some OS’s, like Mac OS X, have WebDAV file system support built in.

Answered By: Ned Deily

I have no experience with any of these libraries, but the Python Package Index (“PyPi”) lists quite a few webdav modules.

Answered By: dcrosta

Apparently you’re looking for a WebDAV client library.

Not sure how the gazillion hits came up, it seems the following 2 looks relevant:

Answered By: Gyuri

I just had a similar need and ended up testing a few Python WebDAV clients for my needs (uploading and downloading files from a WebDAV server). Here’s a summary of my experience:

1) The one that worked for me is python-webdav-lib.

Not much documentation, but a quick look at the code (in particular the example) was enough to figure out how to make it work for me.

2) PyDAV 0.21 (the latest release I found) doesn’t work with Python 2.6 because it uses strings as exceptions. I didn’t try to fix this, expecting further incompatibilities later on.

3) davclient 0.2.0. I looked at it but didn’s explore any further because the documentation didn’t mention the level of API I was looking for (file upload and download).

4) Python_WebDAV_Library-0.3.0. Doesn’t seem to have any upload functionality.

Answered By: khinsen

It’s sad that for this question (“What Python webdav library to use?”), which for sure interests more than one person, unrelated answer was accepted (“don’t use Python webdav library”). Well, common problem on Stackexchange.

For people who will be looking for real answers, and given the requirements in the original question (simple API similar to “os” module), I may suggest easywebdav, which has very easy API and even nice and simple implementation, offering upload/download and few file/dir management methods. Due to simple implementation, it so far doesn’t support directory listing, but bug for that was filed, and the author intends to add it.

Answered By: pfalcon
import easywebdav

webdav = easywebdav.connect(
    host='dav.dumptruck.goldenfrog.com',
    username='_snip_',
    port=443,
    protocol="https",
    password='_snip_')

_file = "test.py"

print webdav.cd("/dav/")
# print webdav._get_url("")
# print webdav.ls()
# print webdav.exists("/dav/test.py")
# print webdav.exists("ECS.zip")
# print webdav.download(_file, "./"+_file)
print webdav.upload("./test.py", "test.py")
Answered By: chrisallick

Install:

$ sudo apt-get install libxml2-dev libxslt-dev python-dev
$ sudo apt-get install libcurl4-openssl-dev python-pycurl
$ sudo easy_install webdavclient

Examples:

import webdav.client as wc

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

client = wc.Client(options)

client.check("dir1/file1")
client.info("dir1/file1")

files = client.list()
free_size = client.free()

client.mkdir("dir1/dir2")
client.clean("dir1/dir2")

client.copy(remote_path_from="dir1/file1", remote_path_to="dir2/file1")
client.move(remote_path_from="dir1/file1", remote_path_to="dir2/file1")

client.download_sync(remote_path="dir1/file1", local_path="~/Downloads/file1")
client.upload_sync(remote_path="dir1/file1", local_path="~/Documents/file1")
client.download_async(remote_path="dir1/file1", local_path="~/Downloads/file1", callback=callback)
client.upload_async(remote_path="dir1/file1", local_path="~/Documents/file1", callback=callback)

link = client.publish("dir1/file1")
client.unpublish("dir1/file1")

Links:

Answered By: designerror
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.