Python bindings

I'm interested in using rclone in python code and am wondering what the options are for this.

rclone/librclone at master · rclone/rclone ( makes it sound like an official python library might be on the roadmap, but I can't find any issues related to it. Is this something of interest?

There's also python-rclone · PyPI and of course calling a process.

But if an official pypi package is of interest I'd be interested in focusing my team on that where possible.

hello and welcome to the forum,

i use python to script rclone, 7zip, veeam, fastcopy and VSS.

the script creates the commands and runs them using
i find the most flexible way to run rclone, as it can also run any command.

the script reads the particular backup details from an .ini entry.

DoRcloneCopyFiles=--immutable --stats=5h --fast-list --bind= --include="*.{vib,vbk}" --max-age=30d --s3-no-check-bucket=true

the script take that .ini entry and creates the commands, for example.

RcloneCopyFilesCmd=C:\data\rclone\scripts\rclone.exe copy "B:\rclone\vss\en08_wasabi01_veeam_br_en08_20220310.092204\BR_VSERVER03_EN08" "wasabi_vserver03brvserver03en08:/en08/rclone/backup" --immutable --stats=5h --fast-list --bind= --include="*.{vib,vbk}" --max-age=30d --s3-no-check-bucket=true --log-level=DEBUG --log-file=C:\data\rclone\logs\en08_wasabi01_veeam_br_en08\20220310.092204\rclone.log --config=C:\data\rclone\scripts\rclone.conf --ask-password

and the function that runs them

    def DoCmd(self, Text, Cmd, Input='', Env=''):
        Common.Log(self, f'Start DoCmd {Text}={Cmd}')
        if Common.DebugMode:
            Common.Log(self, f'DebugMode: DoCmd: {Text}={Cmd}')
            the_env = {};   the_env = dict(os.environ)
            if Env != '':   the_env.update(Env)
  , cwd=Common.ScriptsDir, capture_output=True, text=True, input=Input, env=the_env)
            if len(x.stdout) != 0:
                xfile = open(f'{Common.BackupLogDir}\\{Text}.stdout.log', "w");   xfile.write(x.stdout); xfile.close()
            if len(x.stderr) != 0:
                xfile = open(f'{Common.BackupLogDir}\\{Text}.stderr.log', "w");   xfile.write(x.stderr); xfile.close()
            if x.returncode==0:
                Common.Log(self, f'DoCmd: End:   {Text}={Cmd}')
                return x
                Common.DoEnd(self, f'DoCmd: End ERROR: {Text}={Cmd} with returncode={x.returncode}')
        except Exception as exception:
            txt=f'DoCmd={Cmd} - {traceback.format_exc()}'
            Common.DoEnd(self, txt)

There is an example of how to use librclone from python here

That should maybe be on pypi...

What it does is give you an in memory interface to rclone's RC API.

This is much more efficient than calling the command line program if you are going to execute multiple commands against the same backend.

Librclone is intended to be a fully supported interface. There are still a few things you can't do with it but it is useful as-is.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.