A python wrapper for rclone that makes rclone's functionality usable in python applications.
—
Core transfer functionality for copying, moving, and synchronizing files and directories between local and remote storage locations. All transfer operations support progress tracking, custom progress bars, event listeners, and comprehensive error handling.
Copy files and directories from source to destination without removing the originals. Supports selective copying with ignore options and comprehensive progress monitoring.
def copy(in_path: str, out_path: str, ignore_existing=False, show_progress=True,
listener: Callable[[Dict], None] = None, args=None, pbar=None):
"""
Copies files or directories from source to destination path.
Parameters:
- in_path (str): Source path. Use 'remote_name:path_on_remote' for remotes
- out_path (str): Destination path. Use 'remote_name:path_on_remote' for remotes
- ignore_existing (bool): If True, skip existing files without overwriting
- show_progress (bool): Display progress bar during transfer
- listener (Callable[[Dict], None]): Event callback for transfer progress updates
- args (List[str]): Additional rclone command flags
- pbar (rich.Progress): Custom progress bar instance
Returns:
None
Raises:
RcloneException: If the copy operation fails
"""
def copyto(in_path: str, out_path: str, ignore_existing=False, show_progress=True,
listener: Callable[[Dict], None] = None, args=None, pbar=None):
"""
Copies with renaming capability, typically used for single file operations.
Parameters:
- in_path (str): Source file path
- out_path (str): Destination file path (may include new filename)
- ignore_existing (bool): If True, skip if destination exists
- show_progress (bool): Display progress bar during transfer
- listener (Callable[[Dict], None]): Event callback for progress updates
- args (List[str]): Additional rclone command flags
- pbar (rich.Progress): Custom progress bar instance
Returns:
None
Raises:
RcloneException: If the copy operation fails
"""Move files and directories from source to destination, removing them from the source location. Like copy operations but with source cleanup.
def move(in_path: str, out_path: str, ignore_existing=False, show_progress=True,
listener: Callable[[Dict], None] = None, args=None, pbar=None):
"""
Moves files or directories from source to destination, removing originals.
Parameters:
- in_path (str): Source path to move from
- out_path (str): Destination path to move to
- ignore_existing (bool): If True, skip existing files without overwriting
- show_progress (bool): Display progress bar during transfer
- listener (Callable[[Dict], None]): Event callback for progress updates
- args (List[str]): Additional rclone command flags
- pbar (rich.Progress): Custom progress bar instance
Returns:
None
Raises:
RcloneException: If the move operation fails
"""
def moveto(in_path: str, out_path: str, ignore_existing=False, show_progress=True,
listener: Callable[[Dict], None] = None, args=None, pbar=None):
"""
Moves with renaming capability for single file operations.
Parameters:
- in_path (str): Source file path
- out_path (str): Destination file path (may include new filename)
- ignore_existing (bool): If True, skip if destination exists
- show_progress (bool): Display progress bar during transfer
- listener (Callable[[Dict], None]): Event callback for progress updates
- args (List[str]): Additional rclone command flags
- pbar (rich.Progress): Custom progress bar instance
Returns:
None
Raises:
RcloneException: If the move operation fails
"""Synchronize source to destination, making destination identical to source. Only transfers files that differ, optimizing for minimal data transfer.
def sync(src_path: str, dest_path: str, show_progress=True,
listener: Callable[[Dict], None] = None, args=None, pbar=None):
"""
Synchronizes source to destination, changing destination only.
Files identical in size and modification time or MD5SUM are not transferred.
Parameters:
- src_path (str): Source path to sync from
- dest_path (str): Destination path to sync to
- show_progress (bool): Display progress bar during sync
- listener (Callable[[Dict], None]): Event callback for progress updates
- args (List[str]): Additional rclone command flags
- pbar (rich.Progress): Custom progress bar instance
Returns:
None
Raises:
RcloneException: If the sync operation fails
"""from rclone_python import rclone
# Copy local directory to OneDrive
rclone.copy('local_folder', 'onedrive:backup_folder')
# Copy with existing file handling
rclone.copy('documents', 'box:documents', ignore_existing=True)from rclone_python import rclone
def progress_callback(update_dict):
"""Handle transfer progress updates"""
total_progress = update_dict['progress'] * 100
transfer_speed = update_dict['transfer_speed']
print(f"Progress: {total_progress:.1f}% at {transfer_speed} bytes/sec")
# Copy with progress listener
rclone.copy('large_files', 'dropbox:backup', listener=progress_callback)from rclone_python import rclone
from rich.progress import Progress, TextColumn, BarColumn, TransferSpeedColumn
# Create custom progress bar
with Progress(
TextColumn("[progress.description]{task.description}"),
BarColumn(),
TransferSpeedColumn(),
) as progress:
rclone.copy('data', 'remote:backup', pbar=progress)from rclone_python import rclone
# Sync with additional rclone flags
rclone.sync(
'local_data',
'onedrive:sync_backup',
args=['--create-empty-src-dirs', '--delete-excluded']
)The listener callback receives a dictionary with the following structure:
{
"tasks": [
{
"name": str, # Individual file name
"total": int, # File size in bytes
"sent": int, # Bytes transferred
"progress": float, # File progress (0.0-1.0)
"transfer_speed": int # File transfer speed (bytes/sec)
}
],
"total": int, # Total transfer size in bytes
"sent": int, # Total bytes transferred
"progress": float, # Overall progress (0.0-1.0)
"transfer_speed": int, # Overall transfer speed (bytes/sec)
"rclone_output": dict # Raw rclone statistics
}Install with Tessl CLI
npx tessl i tessl/pypi-rclone-python