Google-Colab-Transfer

Transfer data between Colab and Drive.


Keywords
google-colab, google-colaboratory, google-drive
License
MIT
Install
pip install Google-Colab-Transfer==0.1.6

Documentation

Colab Transfer: transfer data between Colab & Drive

PyPI status Build status Updates Python 3 Code coverage Code Quality

This repository contains Python code to transfer data between Google Colab and Google Drive.

Disclaimer: If files or folders already exist at the destination, then they will not be overwritten. If you want to force an update, ensure that you delete them first.

Installation

The code is packaged for PyPI, so that the installation consists in running:

pip install colab_transfer

Usage

Get the path to the home folder of the local machine for your session on Colaboratory

import colab_transfer

colab_path = colab_transfer.get_path_to_home_of_local_machine()

Get the path to the home folder on Google Drive

import colab_transfer

drive_path = colab_transfer.get_path_to_home_of_google_drive()

Mount Google Drive

NB: you will have to manually input the authorization code.

import colab_transfer

colab_transfer.mount_google_drive()

Check whether Google Drive is mounted

import colab_transfer

google_drive_is_mounted = colab_transfer.is_google_drive_mounted()

Copy a file from Drive to Colaboratory

import colab_transfer

colab_path = colab_transfer.get_path_to_home_of_local_machine()
drive_path = colab_transfer.get_path_to_home_of_google_drive()

input_file_name = 'dummy_file.txt'

colab_transfer.copy_file(
    file_name=input_file_name,
    source=drive_path,
    destination=colab_path,
)

Copy a file from Colaboratory to Drive

import colab_transfer

colab_path = colab_transfer.get_path_to_home_of_local_machine()
drive_path = colab_transfer.get_path_to_home_of_google_drive()

input_file_name = 'dummy_file.txt'

colab_transfer.copy_file(
    file_name=input_file_name,
    source=colab_path,
    destination=drive_path,
)

Copy a folder structure from Drive to Colaboratory

import colab_transfer

colab_path = colab_transfer.get_path_to_home_of_local_machine()
drive_path = colab_transfer.get_path_to_home_of_google_drive()

input_folder_name = 'dummy_folder/'

colab_transfer.copy_folder_structure(
    source=drive_path + input_folder_name,
    destination=colab_path + input_folder_name,
)

Alternatively:

import colab_transfer

colab_path = colab_transfer.get_path_to_home_of_local_machine()
drive_path = colab_transfer.get_path_to_home_of_google_drive()

input_folder_name = 'dummy_folder/'

colab_transfer.copy_folder(
    folder_name=input_folder_name,
    source=drive_path,
    destination=colab_path,
)

Copy a folder structure from Colaboratory to Drive

import colab_transfer

colab_path = colab_transfer.get_path_to_home_of_local_machine()
drive_path = colab_transfer.get_path_to_home_of_google_drive()

input_folder_name = 'dummy_folder/'

colab_transfer.copy_folder_structure(
    source=colab_path + input_folder_name,
    destination=drive_path + input_folder_name,
)

Alternatively:

import colab_transfer

colab_path = colab_transfer.get_path_to_home_of_local_machine()
drive_path = colab_transfer.get_path_to_home_of_google_drive()

input_folder_name = 'dummy_folder/'

colab_transfer.copy_folder(
    folder_name=input_folder_name,
    source=colab_path,
    destination=drive_path,
)