I’ve just released resticpy, a minimal Python wrapper for the restic CLI.
I know some other authors have created Python wrappers, but those solutions all act as wrapper scripts rather than expose an API. I wanted a solution that provided a nice API so that a developer could decide how they wanted to use restic, so that’s what resticpy is.
import restic
restic.repository = '/tmp/backup1'
restic.password_file = 'password.txt'
# Initialize a repo
restic.init()
# Back up a file
restic.backup(paths=['some-file.txt'])
# Restore the backup to a new location
restic.restore(snapshot_id='latest', target_dir='~/restored')
The API semantics closely mirror the CLI semantics, so they should be intuitive to anyone familiar with restic
The code is thoroughly unit tested (95% coverage)
The code includes continuous integration that automatically exercises the code through the unit tests and end-to-end tests against the real restic binaries
The code is open-source, licensed under the permissive MIT license
I’m currently using resticpy for my daily backup script, and I hope it can be useful to others. I’m happy to answer any questions or take any feedback.
If you’re just calling restic backup once in your script, it’s probably simpler to use subprocess.run.
Resticpy becomes a little more handy when you start calling multiple restic commands and want to read restic’s output.
For example, my daily backup script call restic backup, restic prune, and restic stats. Instead of a lot of ugly subprocess calls where I’m translating Python data to and from the command-line, I can write with clean Python APIs, like this: