Skip to main content

rsync wrapper for python

Project description

rsyncer

rsyncer is a simple rsync wrapper for python.

Prerequisites

You need to have an rsync installation on your system and added to your system's path.

Installation

  1. download this repository
  2. from within this repo run make install
  3. test installation by importing rsyncer in a python shell

Usage

You can choose between the simple One-Function-Call and the more powerful Syncer utility to run rsync commands using rsyncer.

The One-Function-Call

This is the simplest usage of rsyncer. You can just call the rsync function with the necessary arguments to run a rsync command. This function will return a boolean indicating if the process finished successfully or not:

from rsyncer.rsync import rsync

suc = rsync(...)
if suc:
    print("rsync run successfully.")
else:
    print("There was an error running rsync.")

The more powerful Syncer object

With this utility, you get a larger set of functionalities like

  • creating a rsync command
  • running a rsync command
  • get the current progress of a running rsync process
  • ...

Mark: rsyncer.rsync.Syncer creates a temporary files in /tmp where rsync's output is written to. Therefore, a Syncer should be closed when you are done working with it (The rsync subprocess will not be killed).

You can either create a Syncer object and use its close() (or exit(), which will kill the rsync process) method in the end, or you can use a Syncer within a with statement:

from rsyncer import rsync

s = rsync.Syncer(...)
s.run()
s.get_command()
s.progress()
# and/or other operations
s.close() # or s.exit() if you want to kill the rsync process as well
from rsyncer import rsync

with rsync.Syncer(...) as s:
    s.run()
    s.get_command()
    s.progress()
    # and/or other operations

Examples

As far as possible, we provide a One-Function-Call and a Syncer implementation for each example.

Syncing a single file

$ rsync /path/to/file /path/to/destination

One-Function-Call

from rsyncer import rsync

rsync.rsync(source="/path/to/file", dest="/path/to/destination")

Syncer

from rsyncer import rsync

with rsync.Syncer(source="/path/to/file", dest="/path/to/destination") as s:
    s.run()

Syncing a directory

$ rsync /path/to/dir /path/to/destination

One-Function-Call

from rsyncer import rsync

rsync.rsync(source="/path/to/dir", dest="/path/to/destination")

Syncer

from rsyncer import rsync

with rsync.Syncer(source="/path/to/dir", dest="/path/to/destination") as s:
    s.run()

Syncing a directory using a remote source

$ rsync -a user@server.org:/path/to/dir /path/to/destination

One-Function-Call

from rsyncer import rsync

rsync.rsync(source="/path/to/dir", dest="/path/to/destination", source_ssh="user@server.org")

Syncer

from rsyncer import rsync

with rsync.Syncer(source="/path/to/dir", dest="/path/to/destination", source_ssh="user@server.org") as s:
    s.run()

Exclude a file

$ rsync /path/to/dir /path/to/destination --exclude /path/to/dir/tmp.txt

One-Function-Call

from rsyncer import rsync

rsync.rsync(source="/path/to/dir", dest="/path/to/destination", excludes=["/path/to/dir/tmp.txt"])

Syncer

from rsyncer import rsync

with rsync.Syncer(source="/path/to/dir", dest="/path/to/destination", excludes=["/path/to/dir/tmp.txt"]) as s:
    s.run()

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

pyrsyncer-0.0.1.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyrsyncer-0.0.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file pyrsyncer-0.0.1.tar.gz.

File metadata

  • Download URL: pyrsyncer-0.0.1.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.1

File hashes

Hashes for pyrsyncer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 67208c12edfc50ef433c9e3e507b21bd84f5e49c20fc5126e723187e5a7db137
MD5 cebbeb62b6db7bc1373728ffb9914ff3
BLAKE2b-256 dfe8fe172420c7335d18ff7fe071cd2d96e7a8da5b6a2b862dad2ecb93c804af

See more details on using hashes here.

File details

Details for the file pyrsyncer-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pyrsyncer-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.1

File hashes

Hashes for pyrsyncer-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 829de4ffa4a77fb3a4878eff3f3cd5c3fdbd985da2626c5cd0e24fb6fc520ef7
MD5 0970ed9d29e0f5acc74721148316d8df
BLAKE2b-256 d5ff8ba6ea65d8019875e914b5d3e142eb03a8305da9c4d4dea3f506f55177ab

See more details on using hashes here.

Supported by

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