CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-webdavclient

WebDAV client library providing easy access to cloud storage services like Yandex.Drive, Dropbox, Google Drive, Box, and 4shared.

Overview
Eval results
Files

configuration.mddocs/

Configuration

WebDAV and proxy server configuration with comprehensive validation, SSL certificate support, and connection management. The configuration system provides flexible options for connecting to various WebDAV servers and cloud storage providers.

Capabilities

WebDAV Configuration

Settings for connecting to WebDAV servers with authentication and advanced options.

class WebDAVSettings:
    """WebDAV connection configuration settings."""
    
    keys = {'hostname', 'login', 'password', 'token', 'root', 'cert_path', 'key_path', 'recv_speed', 'send_speed', 'verbose'}
    ns = "webdav:"
    prefix = "webdav_"
    
    def __init__(self, options: dict) -> None:
        """
        Initialize WebDAV settings from options dictionary.
        
        Parameters:
        - options: dict containing configuration options:
            - hostname: str, WebDAV server URL (required)
            - login: str, username for authentication  
            - password: str, password for authentication
            - token: str, OAuth token for authentication (alternative to login/password)
            - root: str, root directory path on server (default: "/")
            - cert_path: str, path to SSL client certificate file
            - key_path: str, path to SSL private key file  
            - recv_speed: int, download speed limit in bytes/second
            - send_speed: int, upload speed limit in bytes/second
            - verbose: bool, enable verbose logging
        """
    
    def is_valid(self) -> None:
        """
        Validate WebDAV configuration settings.
        
        Raises:
        - OptionNotValid: if required options are missing or invalid
        """
    
    def valid(self) -> bool:
        """
        Check if WebDAV configuration is valid.
        
        Returns:
        - bool: True if configuration is valid, False otherwise
        """

Proxy Configuration

Settings for connecting through proxy servers with authentication support.

class ProxySettings:
    """Proxy server configuration settings."""
    
    keys = {'hostname', 'login', 'password'}
    ns = "proxy:"
    prefix = "proxy_"
    
    def __init__(self, options: dict) -> None:
        """
        Initialize proxy settings from options dictionary.
        
        Parameters:
        - options: dict containing proxy configuration:
            - hostname: str, proxy server URL
            - login: str, proxy username
            - password: str, proxy password
        """
    
    def is_valid(self) -> None:
        """
        Validate proxy configuration settings.
        
        Raises:
        - OptionNotValid: if proxy options are invalid
        """
    
    def valid(self) -> bool:
        """
        Check if proxy configuration is valid.
        
        Returns:
        - bool: True if configuration is valid, False otherwise
        """

Connection Settings Base Class

Base class providing common configuration validation functionality.

class ConnectionSettings:
    """Base class for connection configuration settings."""
    
    def is_valid(self) -> None:
        """
        Validate configuration settings.
        Must be implemented by subclasses.
        """
    
    def valid(self) -> bool:
        """
        Check if configuration is valid.
        
        Returns:
        - bool: True if configuration is valid, False otherwise
        """

Configuration Examples

Basic WebDAV Authentication

import webdav.client as wc

# Basic username/password authentication
basic_config = {
    'webdav_hostname': "https://webdav.example.com",
    'webdav_login': "username",
    'webdav_password': "password"
}

client = wc.Client(basic_config)

OAuth Token Authentication

# OAuth token authentication (for services like Yandex.Disk)
oauth_config = {
    'webdav_hostname': "https://webdav.yandex.ru",
    'webdav_token': "your_oauth_token_here"
}

client = wc.Client(oauth_config)

SSL Certificate Configuration

# Client certificate authentication
ssl_config = {
    'webdav_hostname': "https://secure.webdav.com",
    'webdav_login': "username", 
    'webdav_password': "password",
    'cert_path': "/etc/ssl/certs/client.crt",
    'key_path': "/etc/ssl/private/client.key"
}

client = wc.Client(ssl_config)

Proxy Server Configuration

# WebDAV through proxy server
proxy_config = {
    'webdav_hostname': "https://webdav.company.com",
    'webdav_login': "employee_id",
    'webdav_password': "employee_password",
    'proxy_hostname': "http://proxy.company.com:8080",
    'proxy_login': "proxy_user", 
    'proxy_password': "proxy_pass"
}

client = wc.Client(proxy_config)

Advanced Configuration with Speed Limits

# Advanced configuration with speed limits and verbose logging
advanced_config = {
    'webdav_hostname': "https://webdav.example.com",
    'webdav_login': "username",
    'webdav_password': "password",
    'webdav_root': "/user_files",  # Start in subdirectory
    'recv_speed': 1024 * 1024,     # 1 MB/s download limit
    'send_speed': 512 * 1024,      # 512 KB/s upload limit
    'verbose': True                 # Enable verbose logging
}

client = wc.Client(advanced_config)

Cloud Service Configurations

# Yandex.Disk configuration
yandex_config = {
    'webdav_hostname': "https://webdav.yandex.ru",
    'webdav_token': "your_yandex_oauth_token"
}

# Box.com configuration  
box_config = {
    'webdav_hostname': "https://dav.box.com/dav",
    'webdav_login': "your_box_email@example.com",
    'webdav_password': "your_box_password"
}

# 4shared configuration
fourshared_config = {
    'webdav_hostname': "https://webdav.4shared.com",
    'webdav_login': "your_4shared_login",
    'webdav_password': "your_4shared_password"
}

Configuration Validation

from webdav.connection import WebDAVSettings, ProxySettings
from webdav.exceptions import OptionNotValid

def validate_config(options):
    """Validate configuration before creating client"""
    try:
        # Validate WebDAV settings
        webdav_settings = WebDAVSettings(options)
        webdav_settings.is_valid()
        print("WebDAV configuration is valid")
        
        # Validate proxy settings if present
        proxy_keys = [key for key in options.keys() if key.startswith('proxy_')]
        if proxy_keys:
            proxy_settings = ProxySettings(options)  
            proxy_settings.is_valid()
            print("Proxy configuration is valid")
        
        return True
        
    except OptionNotValid as e:
        print(f"Configuration error: {e}")
        return False

# Test configuration validation
config = {
    'webdav_hostname': "https://webdav.example.com",
    'webdav_login': "user",
    'webdav_password': "pass"
}

if validate_config(config):
    client = wc.Client(config)
    print("Client created successfully")

Environment-Based Configuration

import os

def create_client_from_env():
    """Create client using environment variables"""
    config = {
        'webdav_hostname': os.getenv('WEBDAV_HOSTNAME'),
        'webdav_login': os.getenv('WEBDAV_LOGIN'),
        'webdav_password': os.getenv('WEBDAV_PASSWORD'),
        'webdav_token': os.getenv('WEBDAV_TOKEN'),  # Optional
    }
    
    # Add proxy settings if available
    if os.getenv('PROXY_HOSTNAME'):
        config.update({
            'proxy_hostname': os.getenv('PROXY_HOSTNAME'),
            'proxy_login': os.getenv('PROXY_LOGIN'),
            'proxy_password': os.getenv('PROXY_PASSWORD'),
        })
    
    # Add SSL settings if available
    if os.getenv('WEBDAV_CERT_PATH'):
        config.update({
            'cert_path': os.getenv('WEBDAV_CERT_PATH'),
            'key_path': os.getenv('WEBDAV_KEY_PATH'),
        })
    
    # Remove None values
    config = {k: v for k, v in config.items() if v is not None}
    
    return wc.Client(config)

# Usage: Set environment variables first
# export WEBDAV_HOSTNAME="https://webdav.example.com"
# export WEBDAV_LOGIN="username"
# export WEBDAV_PASSWORD="password"

client = create_client_from_env()

Configuration Templates

class WebDAVConfigurator:
    """Helper class for common WebDAV configurations"""
    
    @staticmethod
    def yandex_disk(token):
        """Yandex.Disk configuration template"""
        return {
            'webdav_hostname': "https://webdav.yandex.ru",
            'webdav_token': token
        }
    
    @staticmethod
    def box_com(email, password):
        """Box.com configuration template"""
        return {
            'webdav_hostname': "https://dav.box.com/dav", 
            'webdav_login': email,
            'webdav_password': password
        }
    
    @staticmethod 
    def custom_server(hostname, username, password, **kwargs):
        """Custom WebDAV server configuration template"""
        config = {
            'webdav_hostname': hostname,
            'webdav_login': username,
            'webdav_password': password
        }
        config.update(kwargs)  # Add any additional options
        return config
    
    @staticmethod
    def with_proxy(base_config, proxy_host, proxy_user=None, proxy_pass=None):
        """Add proxy settings to existing configuration"""
        proxy_config = base_config.copy()
        proxy_config['proxy_hostname'] = proxy_host
        if proxy_user:
            proxy_config['proxy_login'] = proxy_user
        if proxy_pass:
            proxy_config['proxy_password'] = proxy_pass
        return proxy_config

# Use configuration templates
configurator = WebDAVConfigurator()

# Create Yandex.Disk client
yandex_client = wc.Client(configurator.yandex_disk("your_token"))

# Create Box.com client with proxy
box_config = configurator.box_com("user@example.com", "password")
box_with_proxy = configurator.with_proxy(box_config, "http://proxy:8080", "proxy_user", "proxy_pass")
box_client = wc.Client(box_with_proxy)

# Create custom server client with speed limits
custom_config = configurator.custom_server(
    "https://mywebdav.com", 
    "username", 
    "password",
    recv_speed=2*1024*1024,  # 2 MB/s
    send_speed=1*1024*1024,  # 1 MB/s
    verbose=True
)
custom_client = wc.Client(custom_config)

Configuration Options Reference

Required Options

  • webdav_hostname: WebDAV server URL (must start with http:// or https://)

Authentication Options (choose one)

  • webdav_login + webdav_password: Basic HTTP authentication
  • webdav_token: OAuth token authentication

Optional WebDAV Options

  • webdav_root: Root directory path (default: "/")
  • cert_path: SSL client certificate file path
  • key_path: SSL private key file path (required if cert_path is set)
  • recv_speed: Download speed limit in bytes/second (default: unlimited)
  • send_speed: Upload speed limit in bytes/second (default: unlimited)
  • verbose: Enable verbose logging (default: False)

Optional Proxy Options

  • proxy_hostname: Proxy server URL
  • proxy_login: Proxy authentication username
  • proxy_password: Proxy authentication password (required if proxy_login is set)

Install with Tessl CLI

npx tessl i tessl/pypi-webdavclient

docs

client-operations.md

configuration.md

file-transfer.md

index.md

resource-management.md

synchronization.md

tile.json