Skip to main content

A typed interface for rclone.

Project description


A typed rClone interface for python.

Written to more easily express awkward logic, that would be a pain or not (easily) possible on the command line.

A short example, to tidy up and half the number of backups is shown below. The logic can be trivially expanded to instead say, parse the time stamp of the backup out of the folder name, to allow different logic to be applied depending on the age of a backup (do nothing if 1 month old, half is 2 months old, remove every other after a year old etc).

import json
import logging
import os
import sys

from pyrclone import Rclone, RcloneError

def main():

    # Setup rclone runner, and have it run in verbose and dry run mode.
    rclone: Rclone = Rclone()
    rclone.verbose_mode = True
    rclone.dry_run_mode = True

    # Attach a logger, for more immediate output, rather than just on command completion.
    handler: logging.StreamHandler = logging.StreamHandler(sys.stdout)
    formatter: logging.Formatter = logging.Formatter(
        "%(asctime)s - %(name)s - %(levelname)s - %(message)s"

    # List all folders in backup directory to iterate over them.
    remote_path: str = "drive:PC/Backups"
    output = rclone.lsd(remote_path)

    # If we failed to run, stop.
    if output.return_code is not RcloneError.SUCCESS:

    # lsd (and all other ls commands) will default to using lsjson.
    # Lets decode the JSON, and get a list of all our folders.
    backup_folders = []
    for folder in json.loads("".join(files)):

    # With our list of folders, lets delete every other folder, excluding these
    # useful ones.
    # This could also be more indepth logic, such as using the modified timestamp
    # or the timestamp in the folder name to do logic to different backups of
    # varying age. This is allows the ease of scripting in Python to help, versus
    # confusing/verbose command line options and shell scripts.
    ignore_list = [

    # Iterate over every other folder and delete if not in the ignore.
    # Of course, right now we are in dry_run mode, so this won't do anything
    # except list what it would have done.
    for folder in backup_folders[1::2]:
        if folder in ignore_list:

if __name__ == "__main__":

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrclone-1.0.1.tar.gz (17.5 kB view hashes)

Uploaded source

Built Distribution

pyRclone-1.0.1-py3-none-any.whl (18.1 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page