This release is a pre-release and may not be stable for production use.
aiowebdav
Package aiowebdav based on https://github.com/designerror/webdav-client-python but uses aiohttp instead of requests.
It provides easy way to work with WebDAV-servers.
Installation
$ pip install aiowebdav
Sample Usage
import asyncio
from aiowebdav.client import Client
options = {
'webdav_hostname': "https://webdav.server.ru",
'webdav_login': "login",
'webdav_password': "password",
"disable_check": True
}
async def main():
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)
client.execute_request("mkdir", 'directory_name')
asyncio.run(main())
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 aiowebdav.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 aiowebdav.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 aiowebdav.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 aiowebdav.client import Client
options = {
'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:
from aiowebdav.client import Client
options = {
'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 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)
Asynchronous methods
# Checking existence of the resource
await client.check("dir1/file1")
await client.check("dir1")
# Get information about the resource
await client.info("dir1/file1")
await client.info("dir1/")
# Check free space
free_size = await client.free()
# Get a list of resources
files1 = await client.list()
files2 = await client.list("dir1")
files3 = await client.list("dir1", get_info=True) # returns a list of dictionaries with files details
# Create directory
await client.mkdir("dir1/dir2")
# Delete resource
await client.clean("dir1/dir2")
# Copy resource
await client.copy(remote_path_from="dir1/file1", remote_path_to="dir2/file1")
await client.copy(remote_path_from="dir2", remote_path_to="dir3")
# Move resource
await client.move(remote_path_from="dir1/file1", remote_path_to="dir2/file1")
await client.move(remote_path_from="dir2", remote_path_to="dir3")
# Download a resource
await client.download(remote_path="dir1/file1", local_path="~/Downloads/file1")
await client.download(remote_path="dir1/dir2/", local_path="~/Downloads/dir2/")
# Upload resource
await client.upload(remote_path="dir1/file1", local_path="~/Documents/file1")
await client.upload(remote_path="dir1/dir2/", local_path="~/Documents/dir2/")
# Publish the resource
link = await client.publish("dir1/file1")
link = await client.publish("dir2")
# Unpublish resource
await client.unpublish("dir1/file1")
await client.unpublish("dir2")
# Exception handling
from aiowebdav.exceptions import WebDavException
try:
...
except WebDavException as exception:
...
# Get the missing files
await client.pull(remote_directory='dir1', local_directory='~/Documents/dir1')
# Send missing files
await client.push(remote_directory='dir1', local_directory='~/Documents/dir1')
# 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
await res1.rename("file2")
await res1.move("dir1/file2")
await res1.copy("dir2/file1")
info = await res1.info()
await res1.read_from(buffer)
await res1.read(local_path="~/Documents/file1")
await res1.write_to(buffer)
await res1.write(local_path="~/Downloads/file1")
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
Metadata
Release files for aiowebdav 0.1.0rc5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aiowebdav-0.1.0rc5.tar.gz | 24.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aiowebdav-0.1.0rc5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.5 kB
Release files / aiowebdav-0.1.0rc5.tar.gz
| Download URL | aiowebdav-0.1.0rc5.tar.gz |
|---|---|
| Size | 24.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8345f8a55a5eea4e029de0b5c7ba38fbeaaee3e0fdc1e0ca29e60d997643cc2f
|
|
BLAKE2b-256 checksum How to use checksums |
a8eb2cc5a9b133d95516009db90d249e527397fd229afe8b6a6372b4a12fa500
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / aiowebdav-0.1.0rc5-py3-none-any.whl
| Download URL | aiowebdav-0.1.0rc5-py3-none-any.whl |
|---|---|
| Size | 22.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1b7be6122ab69f06f1639bfea9fd3beb43a7d375b5e1ced560b832e04c000026
|
|
BLAKE2b-256 checksum How to use checksums |
0eb13ed16f06e87ccebd90a44558de02ee9d45db7806ad3aca44de0a1962913a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|