Debian Codegraph @

README.md

raw
1 aiowebdav2
2 =========
3 [![GitHub Release][releases-shield]][releases]
4 [![Python Versions][python-versions-shield]][pypi]
5 ![Project Stage][project-stage-shield]
6 ![Project Maintenance][maintenance-shield]
7 [![License][license-shield]](LICENSE.md)
8
9 [![Build Status][build-shield]][build]
10 [![Code Coverage][codecov-shield]][codecov]
11
12 `aiowebdav2` is an asyncio based Python 3 client for WebDAV.
13
14 It is based on https://github.com/designerror/webdav-client-python and https://github.com/synodriver/aiowebdav.
15
16 Installation
17 ------------
18 ```bash
19 $ pip install aiowebdav2
20 ```
21
22 Sample Usage
23 ------------
24
25 ```python
26 import asyncio
27 from aiowebdav2.client import Client
28
29 options = {
30 'webdav_hostname': "https://webdav.server.ru",
31 'webdav_login': "login",
32 'webdav_password': "password",
33 "disable_check": True
34 }
35
36 async def main():
37 client = Client(options)
38 client.verify = False # To not check SSL certificates (Default = True)
39 await client.execute_request("mkdir", 'directory_name')
40 asyncio.run(main())
41 ```
42
43 Webdav API
44 ==========
45
46 Webdav API is a set of webdav actions of work with cloud storage. This set includes the following actions:
47 `check`, `free`, `info`, `list`, `mkdir`, `clean`, `copy`, `move`, `download`, `upload`, `publish` and `unpublish`.
48
49 **Configuring the client**
50
51 Required key is host name or IP address of the WevDAV-server with param name `webdav_hostname`.
52 For authentication in WebDAV server use `webdav_login`, `webdav_password`.
53 For an anonymous login do not specify auth properties.
54
55 ```python
56 from aiowebdav2.client import Client
57
58 options = {
59 'webdav_hostname': "https://webdav.server.ru",
60 'webdav_login': "login",
61 'webdav_password': "password"
62 }
63 client = Client(options)
64 ```
65
66 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`.
67 The key should be in the following list: `check`, `free`, `info`, `list`, `mkdir`, `clean`, `copy`, `move`, `download`, `upload`,
68 `publish` and `unpublish`. The value should a string name of WebDAV method, for example `GET`.
69
70 ```python
71 from aiowebdav2.client import Client
72
73 options = {
74 'webdav_hostname': "https://webdav.server.ru",
75 'webdav_login': "login",
76 'webdav_password': "password",
77 'webdav_override_methods': {
78 'check': 'GET'
79 }
80
81 }
82 client = Client(options)
83 ```
84
85 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.
86
87 ```python
88 from aiowebdav2.client import Client
89
90 options = {
91 'webdav_hostname': "https://webdav.server.ru",
92 'webdav_login': "login",
93 'webdav_password': "password",
94 'webdav_timeout': 30
95 }
96 client = Client(options)
97 ```
98
99 When a proxy server you need to specify settings to connect through it.
100
101 ```python
102 from aiowebdav2.client import Client
103
104 options = {
105 'webdav_hostname': "https://webdav.server.ru",
106 'webdav_login': "w_login",
107 'webdav_password': "w_password",
108 'webdav_proxy': "http://127.0.0.1:8080",
109 'webdav_proxy_auth': "xxx",
110 }
111 client = Client(options)
112 ```
113
114 If you want to use the certificate path to certificate and private key is defined as follows:
115
116 ```python
117 from aiowebdav2.client import Client
118
119 options = {
120 'webdav_hostname': "https://webdav.server.ru",
121 'webdav_login': "w_login",
122 'webdav_password': "w_password",
123 'webdav_ssl': 'sslcontext'
124 }
125 client = Client(options)
126 ```
127
128 Or you want to limit the speed or turn on verbose mode:
129
130 ```python
131 options = {
132 ...
133 'recv_speed' : 3000000,
134 'send_speed' : 3000000,
135 'verbose' : True
136 }
137 client = Client(options)
138 ```
139
140 recv_speed: rate limit data download speed in Bytes per second. Defaults to unlimited speed.
141 send_speed: rate limit data upload speed in Bytes per second. Defaults to unlimited speed.
142 verbose: set verbose mode on/off. By default verbose mode is off.
143
144 Also if your server does not support `check` it is possible to disable it:
145
146 ```python
147 options = {
148 ...
149 'disable_check': True
150 }
151 client = Client(options)
152 ```
153
154 By default, checking of remote resources is enabled.
155
156 For configuring chunk size of content downloading use `chunk_size` param, by default it is `65536`
157
158 ```python
159 options = {
160 ...
161 'chunk_size': 65536
162 }
163 client = Client(options)
164 ```
165
166 **Asynchronous methods**
167
168 ```python
169 # Checking existence of the resource
170
171 await client.check("dir1/file1")
172 await client.check("dir1")
173 ```
174
175 ```python
176 # Get information about the resource
177
178 await client.info("dir1/file1")
179 await client.info("dir1/")
180 ```
181
182 ```python
183 # Check free space
184
185 free_size = await client.free()
186 ```
187
188 ```python
189 # Get a list of resources
190
191 files1 = await client.list()
192 files2 = await client.list("dir1")
193 files3 = await client.list("dir1", get_info=True) # returns a list of dictionaries with files details
194 ```
195
196 ```python
197 # Create directory
198
199 await client.mkdir("dir1/dir2")
200 ```
201
202 ```python
203 # Delete resource
204
205 await client.clean("dir1/dir2")
206 ```
207
208 ```python
209 # Copy resource
210
211 await client.copy(remote_path_from="dir1/file1", remote_path_to="dir2/file1")
212 await client.copy(remote_path_from="dir2", remote_path_to="dir3")
213 ```
214
215 ```python
216 # Move resource
217
218 await client.move(remote_path_from="dir1/file1", remote_path_to="dir2/file1")
219 await client.move(remote_path_from="dir2", remote_path_to="dir3")
220 ```
221
222 ```python
223 # Download a resource
224
225 await client.download(remote_path="dir1/file1", local_path="~/Downloads/file1")
226 await client.download(remote_path="dir1/dir2/", local_path="~/Downloads/dir2/")
227 ```
228
229 ```python
230 # Upload resource
231
232 await client.upload(remote_path="dir1/file1", local_path="~/Documents/file1")
233 await client.upload(remote_path="dir1/dir2/", local_path="~/Documents/dir2/")
234 ```
235
236 ```python
237 # Publish the resource
238
239 link = await client.publish("dir1/file1")
240 link = await client.publish("dir2")
241 ```
242
243 ```python
244 # Unpublish resource
245
246 await client.unpublish("dir1/file1")
247 await client.unpublish("dir2")
248 ```
249
250 ```python
251 # Exception handling
252
253 from aiowebdav.exceptions import WebDavException
254
255 try:
256 ...
257 except WebDavException as exception:
258 ...
259 ```
260
261 ```python
262 # Get the missing files
263
264 await client.pull(remote_directory='dir1', local_directory='~/Documents/dir1')
265 ```
266
267 ```python
268 # Send missing files
269
270 await client.push(remote_directory='dir1', local_directory='~/Documents/dir1')
271 ```
272
273 ```python
274 # Unload resource
275
276 kwargs = {
277 'remote_path': "dir1/file1",
278 'local_path': "~/Downloads/file1",
279 'callback': callback
280 }
281 client.upload_async(**kwargs)
282
283 kwargs = {
284 'remote_path': "dir1/dir2/",
285 'local_path': "~/Downloads/dir2/",
286 'callback': callback
287 }
288 client.upload_async(**kwargs)
289 ```
290
291 Resource API
292 ============
293
294 Resource API using the concept of OOP that enables cloud-level resources.
295
296 ```python
297 # Get a resource
298
299 res1 = client.resource("dir1/file1")
300 ```
301
302 ```python
303 # Work with the resource
304
305 await res1.rename("file2")
306 await res1.move("dir1/file2")
307 await res1.copy("dir2/file1")
308 info = await res1.info()
309 await res1.read_from(buffer)
310 await res1.read(local_path="~/Documents/file1")
311 await res1.write_to(buffer)
312 await res1.write(local_path="~/Downloads/file1")
313
314 ```
315
316 ## Changelog & Releases
317
318 This repository keeps a change log using [GitHub's releases][releases]
319 functionality. The format of the log is based on
320 [Keep a Changelog][keepchangelog].
321
322 Releases are based on [Semantic Versioning][semver], and use the format
323 of `MAJOR.MINOR.PATCH`. In a nutshell, the version will be incremented
324 based on the following:
325
326 - `MAJOR`: Incompatible or major changes.
327 - `MINOR`: Backwards-compatible new features and enhancements.
328 - `PATCH`: Backwards-compatible bugfixes and package updates.
329
330 ## Contributing
331
332 This is an active open-source project. I am always open to people who want to
333 use the code or contribute to it.
334
335 Thank you for being involved! :heart_eyes:
336
337 ## Setting up development environment
338
339 This Python project is fully managed using the [Poetry][poetry] dependency manager. But also relies on the use of NodeJS for certain checks during development.
340
341 You need at least:
342
343 - Python 3.11+
344 - [Poetry][poetry-install]
345 - NodeJS 20+ (including NPM)
346
347 To install all packages, including all development requirements:
348
349 ```bash
350 npm install
351 poetry install
352 ```
353
354 As this repository uses the [pre-commit][pre-commit] framework, all changes
355 are linted and tested with each commit. You can run all checks and tests
356 manually, using the following command:
357
358 ```bash
359 poetry run pre-commit run --all-files
360 ```
361
362 To run just the Python tests:
363
364 ```bash
365 poetry run pytest
366 ```
367
368 ## Authors & contributors
369
370 The content is by [Jan-Philipp Benecke][jpbede].
371
372 For a full list of all authors and contributors,
373 check [the contributor's page][contributors].
374
375 ## License
376
377 MIT License
378
379 Copyright (c) 2025 Jan-Philipp Benecke
380
381 Permission is hereby granted, free of charge, to any person obtaining a copy
382 of this software and associated documentation files (the "Software"), to deal
383 in the Software without restriction, including without limitation the rights
384 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
385 copies of the Software, and to permit persons to whom the Software is
386 furnished to do so, subject to the following conditions:
387
388 The above copyright notice and this permission notice shall be included in all
389 copies or substantial portions of the Software.
390
391 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
392 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
393 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
394 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
395 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
396 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
397 SOFTWARE.
398
399 [build-shield]: https://github.com/jpbede/aiowebdav2/actions/workflows/release.yml/badge.svg
400 [build]: https://github.com/jpbede/aiowebdav2/actions
401 [codecov-shield]: https://codecov.io/gh/jpbede/aiowebdav2/branch/main/graph/badge.svg
402 [codecov]: https://codecov.io/gh/jpbede/aiowebdav2
403 [commits-shield]: https://img.shields.io/github/commit-activity/y/jpbede/aiowebdav2.svg
404 [commits]: https://github.com/jpbede/aiowebdav2/commits/main
405 [contributors]: https://github.com/jpbede/aiowebdav2/graphs/contributors
406 [jpbede]: https://github.com/jpbede
407 [keepchangelog]: http://keepachangelog.com/en/1.0.0/
408 [license-shield]: https://img.shields.io/github/license/jpbede/aiowebdav2.svg
409 [maintenance-shield]: https://img.shields.io/maintenance/yes/2025.svg
410 [poetry-install]: https://python-poetry.org/docs/#installation
411 [poetry]: https://python-poetry.org
412 [pre-commit]: https://pre-commit.com/
413 [project-stage-shield]: https://img.shields.io/badge/project%20stage-stable-green.svg
414 [python-versions-shield]: https://img.shields.io/pypi/pyversions/aiowebdav2
415 [releases-shield]: https://img.shields.io/github/release/jpbede/aiowebdav2.svg
416 [releases]: https://github.com/jpbede/aiowebdav2/releases
417 [semver]: http://semver.org/spec/v2.0.0.html
418 [pypi]: https://pypi.org/project/aiowebdav2/