Package: aiowebdav
aiowebdavPackage aiowebdav based onhttps://github.com/designerror/webdav-client-pythonbut usesaiohttpinstead ofrequests.
It provides easy way to work with WebDAV-servers.Installation$pipinstallaiowebdavSample Usageimportasynciofromaiowebdav.clientimportClientoptions={'webdav_hostname':"https://webdav.server.ru",'webdav_login':"login",'webdav_password':"password","disable_check":True}asyncdefmain():client=Client(options)client.verify=False# To not check SSL certificates (Default = True)client.execute_request("mkdir",'directory_name')asyncio.run(main())Webdav APIWebdav 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,publishandunpublish.Configuring the clientRequired key is host name or IP address of the WevDAV-server with param namewebdav_hostname.For authentication in WebDAV server usewebdav_login,webdav_password.For an anonymous login do not specify auth properties.fromaiowebdav.clientimportClientoptions={'webdav_hostname':"https://webdav.server.ru",'webdav_login':"login",'webdav_password':"password"}client=Client(options)If your server does not supportHEADmethod or there are other reasons to override default WebDAV methods for actions use a dictionary optionwebdav_override_methods.
The key should be in the following list:check,free,info,list,mkdir,clean,copy,move,download,upload,publishandunpublish. The value should a string name of WebDAV method, for exampleGET.fromaiowebdav.clientimportClientoptions={'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 optionwebdav_timeoutwith int value in seconds, by default the timeout is set to 30 seconds.fromaiowebdav.clientimportClientoptions={'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.fromaiowebdav.clientimportClientoptions={'webdav_hostname':"https://webdav.server.ru",'webdav_login':"w_login",'webdav_password':"w_password",'webdav_proxy':"http://127.0.0.1:8080",'webdav_proxy_auth':"xxx",}client=Client(options)If you want to use the certificate path to certificate and private key is defined as follows:fromaiowebdav.clientimportClientoptions={'webdav_hostname':"https://webdav.server.ru",'webdav_login':"w_login",'webdav_password':"w_password",'webdav_ssl':'sslcontext'}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 supportcheckit 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 usechunk_sizeparam, by default it is65536options={...'chunk_size':65536}client=Client(options)Asynchronous methods# Checking existence of the resourceawaitclient.check("dir1/file1")awaitclient.check("dir1")# Get information about the resourceawaitclient.info("dir1/file1")awaitclient.info("dir1/")# Check free spacefree_size=awaitclient.free()# Get a list of resourcesfiles1=awaitclient.list()files2=awaitclient.list("dir1")files3=awaitclient.list("dir1",get_info=True)# returns a list of dictionaries with files details# Create directoryawaitclient.mkdir("dir1/dir2")# Delete resourceawaitclient.clean("dir1/dir2")# Copy resourceawaitclient.copy(remote_path_from="dir1/file1",remote_path_to="dir2/file1")awaitclient.copy(remote_path_from="dir2",remote_path_to="dir3")# Move resourceawaitclient.move(remote_path_from="dir1/file1",remote_path_to="dir2/file1")awaitclient.move(remote_path_from="dir2",remote_path_to="dir3")# Download a resourceawaitclient.download(remote_path="dir1/file1",local_path="~/Downloads/file1")awaitclient.download(remote_path="dir1/dir2/",local_path="~/Downloads/dir2/")# Upload resourceawaitclient.upload(remote_path="dir1/file1",local_path="~/Documents/file1")awaitclient.upload(remote_path="dir1/dir2/",local_path="~/Documents/dir2/")# Publish the resourcelink=awaitclient.publish("dir1/file1")link=awaitclient.publish("dir2")# Unpublish resourceawaitclient.unpublish("dir1/file1")awaitclient.unpublish("dir2")# Exception handlingfromaiowebdav.exceptionsimportWebDavExceptiontry:...exceptWebDavExceptionasexception:...# Get the missing filesawaitclient.pull(remote_directory='dir1',local_directory='~/Documents/dir1')# Send missing filesawaitclient.push(remote_directory='dir1',local_directory='~/Documents/dir1')# Unload resourcekwargs={'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 APIResource API using the concept of OOP that enables cloud-level resources.# Get a resourceres1=client.resource("dir1/file1")# Work with the resourceawaitres1.rename("file2")awaitres1.move("dir1/file2")awaitres1.copy("dir2/file1")info=awaitres1.info()awaitres1.read_from(buffer)awaitres1.read(local_path="~/Documents/file1")awaitres1.write_to(buffer)awaitres1.write(local_path="~/Downloads/file1")For ContributorsPrepare development environmentInstall docker on your development machineStart WebDAV server for testing by following commands from the project's root folder or change path toconfdir in second command to correct:dockerpullbytemark/webdav
dockerrun-d--namewebdav-eAUTH_TYPE=Basic-eUSERNAME=alice-ePASSWORD=secret1234-vconf:/usr/local/apache2/conf-p8585:80bytemark/webdavCode conventionPlease check your code according PEP8 Style guides.Run testsCheck that webdav container is started on your local machineExecute following command in the project's root folder:python-munittestdiscover-stestsPrepare a Pull RequestPlease use this check list before creating PR:You code should be formatted according PEP8All tests should successfully passYour changes shouldn't change previous default behaviour, exclude defectsAll changes are covered by tests