Skip to main content

A Simplified Google Drive API.

Project description

📦️ EGDrive

Issues pypi

A simplified Google Drive API wrapper for Python.

EGDrive is a built on top of PyDrive2, it simplifies management of Google Drive using Python, it has a high level interface emulating Linux file management commands in an intuitive way.

🧑‍💻 Installation

Install EGDrive with pip

pip install EGDrive

📌 Features

  • Intuitive Unix-like commands (ls, mkdir, rm ...) to manage Google Drive
  • Access any file with it's absolute path, no more Google Drive ID's headaches.
  • Built on top of PyDrive2, access GoogleDrive and GoogleAuth instances for more options.
  • Lightweight.

🚀 Usage/Examples

Authentication with Google Drive

Create a new project in Google's APIs Console, for that follow this guide in here. To make the authentication automatic follow this guide.

Initiate an EGDrive instance.
from EGDrive import EGDrive

gdrive = EGDrive()
List files

The files that will be listed are the ones that your Google Project has access to, other files won't be managed by EGDrive.

files = [file['title'] for file in gdrive.ls('root')]
for file in files:
    print(file)
Create a directory

If you try to create a directory that already exists, this function won't create a new directory with the same name and different id, instead it'll return the GoogleDriveFile instance for the existing directory in the drive, and if there are more than one, it'll return GoogleDriveFile for the first one that matches the name of the new directory.

gdrive.mkdir("/Books")
Create even more directories

You can create as many directories as you want using mkdir , this works the same as the command mkdir -p in Linux. Please note that you should always use absolute paths!

gdrive.mkdir("/Books/Science") # equivalent to `mkdir -p Books/Science`
gdrive.mkdir("/Books/Litterature")
gdrive.mkdir("/Books/Science/Programming/JAVA")
gdrive.mkdir("/Books/Science/Programming/Python/3/")
Create an empty file

Creates a new file and returns it's GoogleDriveFile instance. if the file already exists it'll return the GoogleDriveFile instance of the existing file.

gdrive.touch("/Documents/empty.txt")
Check if a file exists
if gdrive.exists("/path/to/file"): print("File exists!")
else: print("File not found!")
Remove files and directories

Removing files by default moves them to Trash where they'll be permanently deleted after 30 days.

# move to Trash
gdrive.rm("/Books/Science/Programming/JAVA")
# delete permanently
gdrive.rm("/Books/Litterature", permanently=True)
Download a file
gdrive.download("/Books/Science/physics.pdf", "/home/user/Downloads/physics.pdf")
Upload a file
gdrive.upload("/home/user/Videos/mrbean.mp4", "/Videos/mrbean.mp4")
Copy a file to a directory
gdrive.cp("Books/Science/Programming/gravity.pdf", "/Books/Science/")
Copy a file to a directory and rename it
gdrive.cp("/Books/Science/Programming/gravity.pdf", "/Books/Science/physics.pdf")
Get the id of a file or folder from it's path
gdrive.path_to_id("/Books/Science/Programming/gravity.pdf")
Get the path of a file or folder by it's id
gdrive.id_to_path("XX-XXXXXXXXXXX-XXXXXXX")
Get access to PyDrive2 GoogleDrive and GoogleAuth instances
gdrive.drive # GoogleDrive instance
gdrive.gauth # GoogleAuth instance

📝 TODO

  • Add progress info for uploading/downloading files.
  • Add support for file operations: copy, move.
  • Implement support for relative paths.
  • ...

🩹 Known Issues

You tell me 👽️.

🔧 Contributing

Contributions are always welcome!

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

EGDrive-0.1.3-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file EGDrive-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: EGDrive-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for EGDrive-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bea023de198739ff0f390cb9a98eb2ff5fecd22e542ff243f95d866546c2ca03
MD5 ceff18a8671cd5fc3b11ca3f64468e08
BLAKE2b-256 044f598c3ab01a47c7b9dab897df62e32d88ed029e38b768a6bb4aaf1b654417

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