webdavclient3: WebDAV client, based on original package https://github.com/designerror/webdav-client-python but uses requests instead of PyCURL · Pythie
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.
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.
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:
# 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
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 conf dir in second command to correct:
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.
Alternatives
Use instead of webdavclient3: tools that do the same job, closest first.