Skip to main content

cloudsync enables simple cloud file-level sync with a variety of cloud providers

Project description

Build Status Code Coverage

cloudsync README

Python Cloud Synchronization Library

Installation

pip install cloudsync

# install provider support
pip install cloudsync-gdrive

Links

Command-line Example

cloudsync sync --help

cloudsync sync file:c:/users/me/documents gdrive:/mydocs

# on linux you can pass -D for 'daemon mode', which will detatch and run in the background

Example of a single cloud provider integration

import cloudsync

# Get a generic client_id and client_secret. Do not use this in production code.
# For more information on getting your own client_id and client_secret, see README_OAUTH.md
oauth_config = cloudsync.command.utils.generic_oauth_config('gdrive')

# get an instance of the gdrive provider class
provider = cloudsync.create_provider('gdrive', oauth_config=oauth_config)

# Start the oauth process to login in to the cloud provider
creds = provider.authenticate()

# Use the credentials to connect to the cloud provider
provider.connect(creds)

# Perform cloud operations
for entry in provider.listdir_path("/"):
    print(entry.path)

Example of a syncronization between two cloud providers

import cloudsync
import tempfile
import time

# a little setup
local_root = tempfile.mkdtemp()
remote_root = "/cloudsync_test/" + time.strftime("%Y%m%d%H%M")
provider_name = 'gdrive'
print("syncronizing between %s locally and %s on %s" % (local_root, remote_root, provider_name))

# Get a generic client_id and client_secret. Do not use this in production code.
# For more information on getting your own client_id and client_secret, see README_OAUTH.md
cloud_oauth_config = cloudsync.command.utils.generic_oauth_config(provider_name)

# get instances of the local file provider and cloud provider from the provider factory
local = cloudsync.create_provider("filesystem")
remote = cloudsync.create_provider(provider_name, oauth_config=cloud_oauth_config)

# Authenticate with the remote provider using OAuth
creds = remote.authenticate()

# Connect with the credentials acquired by authenticating with the provider
local.namespace = local_root  # filesystem provider wants to know the root namespace before connecting
local.connect(None)
remote.connect(creds)

# Create the folder on google drive to syncronize locally
print("Creating folder %s on %s" % (remote_root, provider_name))
remote.mkdirs(remote_root)  # provider.mkdirs() will automatically create any necessary parent folders

# Specify which folders to syncronize
sync_roots = (local_root, remote_root)

# instantiate a new sync engine and start syncing
sync = cloudsync.CloudSync((local, remote), roots=sync_roots)
sync.start()

# should sync this file as soon as it's noticed by watchdog
local_hello_path = local.join(local_root, "hello.txt")
print("Creating local file %s" % local_hello_path)
with open(local_hello_path, "w") as f:
    f.write("hello")

# note remote.join, NOT os.path.join... Gets the path separator correct
remote_hello_path = remote.join(remote_root, "hello.txt")

# wait for sync to upload the new file to the cloud
while not remote.exists_path(remote_hello_path):
    time.sleep(1)

remote_hello_info = remote.info_path(remote_hello_path)

# rename in the cloud
local_goodbye_path = local.join(local_root, "goodbye.txt")
remote_goodbye_path = remote.join(remote_root, "goodbye.txt")
print("renaming %s to %s on %s" % (remote_hello_path, remote_goodbye_path, provider_name))
remote.rename(remote_hello_info.oid, remote_goodbye_path)  # rename refers to the file to rename by oid

# wait for sync to cause the file to get renamed locally
while not local.exists_path(local_goodbye_path):
    time.sleep(1)

print("synced")

sync.stop(forever=True)
local.disconnect()
remote.disconnect()

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

cloudsync-3.0.5a1.tar.gz (248.3 kB view details)

Uploaded Source

Built Distribution

cloudsync-3.0.5a1-py3-none-any.whl (212.8 kB view details)

Uploaded Python 3

File details

Details for the file cloudsync-3.0.5a1.tar.gz.

File metadata

  • Download URL: cloudsync-3.0.5a1.tar.gz
  • Upload date:
  • Size: 248.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for cloudsync-3.0.5a1.tar.gz
Algorithm Hash digest
SHA256 b3274d24000618d6d91a4a8ab52444d3f4fe18272016b218f870ffd49b884045
MD5 e88e8d24aa547c35b139c2459ed08a95
BLAKE2b-256 25dece5e4a625588f0ca3d9c6acc16f1b1f3581605a4a1a3fae47886f722d057

See more details on using hashes here.

File details

Details for the file cloudsync-3.0.5a1-py3-none-any.whl.

File metadata

  • Download URL: cloudsync-3.0.5a1-py3-none-any.whl
  • Upload date:
  • Size: 212.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for cloudsync-3.0.5a1-py3-none-any.whl
Algorithm Hash digest
SHA256 db702c019806120dcf53a0f34fe51c3b668ac30fbb5e84c5990dd982a57c8a95
MD5 4e645237dbd9d828cb9e1abed8eca5d5
BLAKE2b-256 7d65d30e139ce53bad9b8d77c304d14e310a6844ae124b1263a5b78e8e3a2303

See more details on using hashes here.

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