Skip to main content

Drive-in

Minimalistic Google Drive Library for Python.

PyPI - Version PyPI - Python Version
Code style: black License: MIT
su6 checks

Table of Contents

Features

  • Authentication: Easily authenticate with Google Drive using OAuth 2.0, and store the access token for future use. Drive-In provides a CLI authentication process, guiding you through token creation.

  • File Upload: Seamlessly upload files to your Google Drive, with support for multi-part uploads. You can specify the file's name and the destination folder.

  • File Download: Download files from Google Drive, also with multipart support. *

  • API Interaction: Interact with the Google Drive API through a simplified interface, making it effortless to perform operations like creating, updating, and deleting files or folders. *

  • Error Handling: Drive-In includes error handling to help you handle unexpected situations, such as failed API requests.

* Due to Authentication Limitations, you can only view and edit files that were created using this tool.

Installation

pip install drive-in

Usage

First, import the library and create an instance of the Drive class:

from drive_in import Drive

drive = Drive()

This will prompt the user for authentication.

Checking Authentication Status

# Check if the authentication token is valid
if drive.ping():
    print("Authentication is successful and server responds well.")
else:
    print("Authentication failed.")

Uploading a File

# Upload a file to Google Drive
file_path = "example.txt"
drive.upload(file_path)

Downloading a File

# Download a file from Google Drive 
file_id = "your_file_id_here"
downloaded_file = drive.download(file_id)
# if no output target is passed, it is saved to the same name as it has on drive. 
# A reference to the file handle is returned.

Accessing other Drive API Endpoints

Other than upload and download, you can access REST resources with the HTTP verbs (GET, POST, PATCH, DELETE):

drive.get("files")  # perform GET /drive/v3/files
# returns a Result object which has .success (bool) and .data (dict) properties.
# _response and _url internal properties are available if you need access to this raw info.

drive.post("files/123/comments", data=dict(content="...")) # perform POST to create a new comment.

drive.delete("files/123")  # perform DELETE /drive/v3/files/123

resource = drive.resource("files") / 123  # dynamically build up the resource string
drive.delete(resource)  # also performs DELETE /drive/v3/files/123

See the Google Drive API page for information about available resources.

Authentication

This library works only a public OAuth Client ID. Since it is open source, a secret config or key can not be shared. This leads to some limitations with how much the app can access. Unfortunately, you can only access files created by this app (i.e. uploaded by it).

OAuth Callback

Since oauth requires a callback URL, you're redirected to "https://oauth.trialandsuccess.nl/callback" after logging in. This page simply echoes the access token from the request parameters using oauth-echoer.

You can also provide you own Client ID and callback URL when initializing a Drive instance:

custom_clientid = "123-abc.apps.googleusercontent.com"
custom_url = "https://yoursite.com/callback"

drive = Drive(
    client_id=custom_clientid,
    redirect_uri=custom_url,
  )

License

drive-in is distributed under the terms of the MIT license.

Disclaimer: This library is not officially affiliated with Google Drive or Google LLC. It is an open-source project created to simplify interactions with Google Drive's API.

Metadata

Release files for drive-in 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drive-in 0.1.5
File Size Uploaded
drive_in-0.1.5.tar.gz 13.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for drive-in 0.1.5
File Interpreter ABI Platform
drive_in-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 24.7 kB

Release files / drive_in-0.1.5.tar.gz

Download URL drive_in-0.1.5.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3188f990ee044a4ddbb658a86d7a8f046341d4d0c6924c8644d807f901f16ad8
BLAKE2b-256 checksum
How to use checksums
6bfc92e0cf541aa77e0b7e90513649ac7261414ed7961e994c281bea38d09557
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.25.0

Release files / drive_in-0.1.5-py3-none-any.whl

Download URL drive_in-0.1.5-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
70e49a8d1fb0a4b4adff8c167e22a1db3369f4557d76562a9596031f074bb904
BLAKE2b-256 checksum
How to use checksums
a74ac5f96a5586caeaad4d476e4d25db85f5e32563ae2e5f83f45f11c1957538
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.25.0

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page