Skip to content

Latest commit

 

History

History
114 lines (75 loc) · 5.99 KB

README.md

File metadata and controls

114 lines (75 loc) · 5.99 KB

solvedrive

Google Drive client built on the Drive API

solvedrive is an async Python client for Google Drive. It wraps the Drive REST API in a few small classes (GDrive, Drive, File, Folder, and their collections), so you can upload and download files, search across My Drive and shared drives, export Google Docs, organize with folders, and share, all with plain method calls.

It is built on fastgws for OAuth and API access, and runs every call asynchronously, so you await each one. Searches come back with the useful fields (name, mimeType, size, parents, trashed, webViewLink) already populated in one request, and reprs render file names as links that open the file in Drive.

Installation

Install latest from pypi

$ pip install solvedrive

How to use

solvedrive signs in with OAuth 2.0 through fastgws, using the OAuth client and tokens that gclientid creates. Run gclientid once to provision a Google Cloud project and OAuth client, then gclientid-auth you@example.com to authorize an account; the default google-apps preset includes full Drive access. oauth_creds(account='you@example.com') loads the saved token, refreshes it when it expires, and runs the browser authorization again when it is missing.

Create a GDrive client from those credentials. about() returns the signed-in account, with the address on its email attribute.

creds = await oauth_creds(account='nc@answer.ai')
gd = GDrive(creds)
about = await gd.about()
about.email
'nc@answer.ai'

Uploading

upload sends bytes or a local path to Drive, returning the new File. Its repr shows the essentials, with the name linking to the file in Drive.

f = await gd.upload(data=b'hello from solvedrive!', name='solvedrive_hello.txt')
f

File(1X0jjggHSWBTQbxaLxtsSNqcDW9uIJpQh: solvedrive_hello.txt (text/plain, 22B) 2026-07-28T21:08:32.734Z)

Searching

search_files takes Drive's own query syntax, the same operators the Drive search box uses, and searches every drive you can see: My Drive, files shared with you, and all shared drives. Results are a Files collection with a table repr.

fs = await gd.search_files("name = 'solvedrive_hello.txt' and trashed=false")
fs
id name type size modified
1X0jjggHSWBTQbxaLxtsSNqcDW9uIJpQh solvedrive_hello.txt text/plain 22B 2026-07-28

Downloading

download returns a file's bytes. Google-native files (Docs, Sheets, Slides) have no bytes of their own, so they are exported to a regular format instead: docx for Docs, xlsx for Sheets, pptx for Slides, or any supported mime= you ask for.

await f.download()
b'hello from solvedrive!'

Folders

A folder is a file with a special mimeType. create_folder makes one, move puts files in it, and ls lists what it holds.

folder = await gd.create_folder('solvedrive demo')
await f.move(folder)
await folder.ls()
id name type size modified
1X0jjggHSWBTQbxaLxtsSNqcDW9uIJpQh solvedrive_hello.txt text/plain 22B 2026-07-28

Drives

Every file lives in a drive: your My Drive, or a shared drive owned by an organization. list_drives returns them as a Drives table, and each Drive knows your role on it and scopes search_files to its contents. drive.root is an ordinary Folder, so uploading into and listing a shared drive works like any folder, and every file method sends supportsAllDrives, so a File behaves the same wherever it lives.

ds = await gd.list_drives()
ds[0]

Drive(root: My Drive, owner)

Sharing

share grants access, either to an email address or to anyone with the link when none is given. permissions lists the current grants, and unshare revokes one.

p = await f.share()
await f.permissions
[{'id': 'anyoneWithLink', 'type': 'anyone', 'role': 'reader'}, {'id': '12635610242443046038', 'type': 'user', 'emailAddress': 'nc@answer.ai', 'role': 'owner'}]

There's more in solvedrive.core: working inside shared drives, replacing content, renaming and copying, trash versus permanent deletion, and operating on a whole Files collection concurrently. See the docs for the full tour.

Use as an LLM skill

solvedrive registers a pyskills skill, so an LLM host such as solveit can load it and use the non-destructive API (searching, downloading, uploading, replacing content, creating folders, renaming, moving, and copying) by default. Trash, permanent deletion, and sharing are documented in the skill but are not enabled, so you turn them on when a task needs them.