Python WebDAV Client 3
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 actions of work with cloud storage. This set includes the following actions:
check, free, info, list, mkdir, clean, copy, move, download, upload, publish and unpublish.
Configuring the client
Required key is host name or IP address of the WevDAV-server with param name webdav_hostname.
For authentication in WebDAV server use webdav_login, webdav_password.
For an anonymous login do not specify auth properties.
from webdav3.client import Client
options = {
'webdav_hostname': "https://webdav.server.ru",
'webdav_login': "login",
'webdav_password': "password"
}
client = Client(options)
If your server does not support HEAD method or there are other reasons to override default WebDAV methods for actions use a dictionary option webdav_override_methods.
The key should be in the following list: check, free, info, list, mkdir, clean, copy, move, download, upload,
publish and unpublish. The value should a string name of WebDAV method, for example GET.
from webdav3.client import Client
options = {
'webdav_hostname': "https://webdav.server.ru",
'webdav_login': "login",
'webdav_password': "password",
'webdav_override_methods': {
'check': 'GET'
}
}
client = Client(options)
For configuring a requests timeout you can use an option webdav_timeout with int value in seconds, by default the timeout is set to 30 seconds.
from webdav3.client import Client
options = {
'webdav_hostname': "https://webdav.server.ru",
'webdav_login': "login",
'webdav_password': "password",
'webdav_timeout': 30
}
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.
For configuring chunk size of content downloading use chunk_size param, by default it is 65536
options = {
...
'chunk_size': 65536
}
client = Client(options)
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")
files3 = client.list("dir1", get_info=True) # returns a list of dictionaries with files details
# 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")
# Download a resource
client.download_sync(remote_path="dir1/file1", local_path="~/Downloads/file1")
client.download_sync(remote_path="dir1/dir2/", local_path="~/Downloads/dir2/")
# Upload 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)
For Contributors
Prepare development environment
- Install docker on your development machine
- Start WebDAV server for testing by following commands from the project's root folder or change path to
confdir in second command to correct:
docker pull bytemark/webdav
docker run -d --name webdav -e AUTH_TYPE=Basic -e USERNAME=alice -e PASSWORD=secret1234 -v conf:/usr/local/apache2/conf -p 8585:80 bytemark/webdav
Code convention
Please check your code according PEP8 Style guides.
Run tests
- Check that webdav container is started on your local machine
- Execute following command in the project's root folder:
python -m unittest discover -s tests
Prepare a Pull Request
Please use this check list before creating PR:
- You code should be formatted according PEP8
- All tests should successfully pass
- Your changes shouldn't change previous default behaviour, exclude defects
- All changes are covered by tests
Releasing
Releases follow a git-flow style: create branch release/X.Y.Z from develop, update version in pyproject.toml, merge into master, then create and push tag vX.Y.Z. GitHub Actions publishes to PyPI on tag push.
Required: In the repository Settings → Secrets and variables → Actions, add a secret PYPI_API_TOKEN with a PyPI API token (create at pypi.org/manage/account/token/). Alternatively, configure Trusted Publishing on PyPI and remove the password input from .github/workflows/publish.yml.
Metadata
Release files for webdavclient3 3.14.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| webdavclient3-3.14.7.tar.gz | 30.8 kB | Without provenance | Details for webdavclient3-3.14.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| webdavclient3-3.14.7-py3-none-any.whl | Python 3 | none | any | Details for webdavclient3-3.14.7-py3-none-any.whl |
Total release size: 53.7 kB
Release files / webdavclient3-3.14.7.tar.gz
| Download URL | webdavclient3-3.14.7.tar.gz |
|---|---|
| Size | 30.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c04252b579bc015cec78081480c63eadf1030f382768248777c6203f059b3f5
|
|
BLAKE2b-256 checksum How to use checksums |
67d8ca3981053ed553363322f71745f543186b93439b6417f5d6ca91d4b4fec7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / webdavclient3-3.14.7-py3-none-any.whl
| Download URL | webdavclient3-3.14.7-py3-none-any.whl |
|---|---|
| Size | 22.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a904381da8e3ae77b4ca9e11e05058d91a07704254d71c193c797f7c2fb15025
|
|
BLAKE2b-256 checksum How to use checksums |
895e0b1c2f494d03c4acbc44567fa68b954cd0fa3f21eb3f9528011da371f9b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for webdavclient3 3.14.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.