solvedrive 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
solvedrive/__init__.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "0.0.1"
solvedrive/_modidx.py ADDED
@@ -0,0 +1,52 @@
1
+ # Autogenerated by nbdev
2
+
3
+ d = { 'settings': { 'branch': 'main',
4
+ 'doc_baseurl': '/solvedrive',
5
+ 'doc_host': 'https://answerDotAI.github.io',
6
+ 'git_url': 'https://github.com/answerDotAI/solvedrive',
7
+ 'lib_path': 'solvedrive'},
8
+ 'syms': { 'solvedrive.core': { 'solvedrive.core.Drive': ('core.html#drive', 'solvedrive/core.py'),
9
+ 'solvedrive.core.Drive.__init__': ('core.html#drive.__init__', 'solvedrive/core.py'),
10
+ 'solvedrive.core.Drive.about': ('core.html#drive.about', 'solvedrive/core.py'),
11
+ 'solvedrive.core.Drive.create_folder': ('core.html#drive.create_folder', 'solvedrive/core.py'),
12
+ 'solvedrive.core.Drive.init': ('core.html#drive.init', 'solvedrive/core.py'),
13
+ 'solvedrive.core.Drive.search_files': ('core.html#drive.search_files', 'solvedrive/core.py'),
14
+ 'solvedrive.core.Drive.upload': ('core.html#drive.upload', 'solvedrive/core.py'),
15
+ 'solvedrive.core.File': ('core.html#file', 'solvedrive/core.py'),
16
+ 'solvedrive.core.File.__init__': ('core.html#file.__init__', 'solvedrive/core.py'),
17
+ 'solvedrive.core.File.__repr__': ('core.html#file.__repr__', 'solvedrive/core.py'),
18
+ 'solvedrive.core.File._desc': ('core.html#file._desc', 'solvedrive/core.py'),
19
+ 'solvedrive.core.File._repr_markdown_': ('core.html#file._repr_markdown_', 'solvedrive/core.py'),
20
+ 'solvedrive.core.File._set_trashed': ('core.html#file._set_trashed', 'solvedrive/core.py'),
21
+ 'solvedrive.core.File.copy': ('core.html#file.copy', 'solvedrive/core.py'),
22
+ 'solvedrive.core.File.delete': ('core.html#file.delete', 'solvedrive/core.py'),
23
+ 'solvedrive.core.File.download': ('core.html#file.download', 'solvedrive/core.py'),
24
+ 'solvedrive.core.File.fetch': ('core.html#file.fetch', 'solvedrive/core.py'),
25
+ 'solvedrive.core.File.move': ('core.html#file.move', 'solvedrive/core.py'),
26
+ 'solvedrive.core.File.permissions': ('core.html#file.permissions', 'solvedrive/core.py'),
27
+ 'solvedrive.core.File.refresh': ('core.html#file.refresh', 'solvedrive/core.py'),
28
+ 'solvedrive.core.File.rename': ('core.html#file.rename', 'solvedrive/core.py'),
29
+ 'solvedrive.core.File.share': ('core.html#file.share', 'solvedrive/core.py'),
30
+ 'solvedrive.core.File.trash': ('core.html#file.trash', 'solvedrive/core.py'),
31
+ 'solvedrive.core.File.unshare': ('core.html#file.unshare', 'solvedrive/core.py'),
32
+ 'solvedrive.core.File.untrash': ('core.html#file.untrash', 'solvedrive/core.py'),
33
+ 'solvedrive.core.Files': ('core.html#files', 'solvedrive/core.py'),
34
+ 'solvedrive.core.Files.__init__': ('core.html#files.__init__', 'solvedrive/core.py'),
35
+ 'solvedrive.core.Files._gfiles': ('core.html#files._gfiles', 'solvedrive/core.py'),
36
+ 'solvedrive.core.Files._repr_markdown_': ('core.html#files._repr_markdown_', 'solvedrive/core.py'),
37
+ 'solvedrive.core.Files._set_trashed': ('core.html#files._set_trashed', 'solvedrive/core.py'),
38
+ 'solvedrive.core.Files.delete': ('core.html#files.delete', 'solvedrive/core.py'),
39
+ 'solvedrive.core.Files.refresh': ('core.html#files.refresh', 'solvedrive/core.py'),
40
+ 'solvedrive.core.Files.trash': ('core.html#files.trash', 'solvedrive/core.py'),
41
+ 'solvedrive.core.Files.untrash': ('core.html#files.untrash', 'solvedrive/core.py'),
42
+ 'solvedrive.core.Folder': ('core.html#folder', 'solvedrive/core.py'),
43
+ 'solvedrive.core.Folder.ls': ('core.html#folder.ls', 'solvedrive/core.py'),
44
+ 'solvedrive.core.Folder.upload': ('core.html#folder.upload', 'solvedrive/core.py'),
45
+ 'solvedrive.core._fid': ('core.html#_fid', 'solvedrive/core.py'),
46
+ 'solvedrive.core._file_row': ('core.html#_file_row', 'solvedrive/core.py'),
47
+ 'solvedrive.core._link': ('core.html#_link', 'solvedrive/core.py'),
48
+ 'solvedrive.core._mk_file': ('core.html#_mk_file', 'solvedrive/core.py'),
49
+ 'solvedrive.core._mtype': ('core.html#_mtype', 'solvedrive/core.py'),
50
+ 'solvedrive.core._multipart_related': ('core.html#_multipart_related', 'solvedrive/core.py'),
51
+ 'solvedrive.core.hsize': ('core.html#hsize', 'solvedrive/core.py')},
52
+ 'solvedrive.skill': {}}}
solvedrive/core.py ADDED
@@ -0,0 +1,274 @@
1
+ """User facing API for solvedrive
2
+
3
+ Docs: https://answerDotAI.github.io/solvedrive/core.html.md"""
4
+
5
+ # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb.
6
+
7
+ # %% auto #0
8
+ __all__ = ['FIELDS', 'FOLDER_MIME', 'Drive', 'hsize', 'File', 'Folder', 'Files']
9
+
10
+ # %% ../nbs/00_core.ipynb #4d53f263
11
+ from fastcore.all import *
12
+ from fastgws import Drive as GDrive
13
+ from fastgws.auth import *
14
+ from uuid import uuid4
15
+
16
+ import json, mimetypes, sys
17
+
18
+ # %% ../nbs/00_core.ipynb #f4e588b0
19
+ FIELDS = 'id,name,mimeType,size,modifiedTime,parents,trashed,webViewLink'
20
+
21
+ class Drive:
22
+ def __init__(self, client): self.client = client
23
+
24
+ @classmethod
25
+ async def init(cls, scopes='readonly', creds=None, redirect_uri='https://oauth.appapis.org/redirect',
26
+ listen=False, port=0, open_url=print):
27
+ if scopes == 'full': scopes = ['https://www.googleapis.com/auth/drive']
28
+ else: scopes = [f'https://www.googleapis.com/auth/drive.{x}' for x in listify(scopes)]
29
+ if creds is None: creds = await oauth_creds(scopes=scopes, redirect_uri=redirect_uri, listen=listen, port=port, open_url=open_url)
30
+ return cls(GDrive(creds=creds))
31
+
32
+ async def about(self):
33
+ "User resource with `email` attribute"
34
+ d = await self.client.about.get(fields='user')
35
+ return AttrDict(d.user, email=d.user.emailAddress)
36
+
37
+ # %% ../nbs/00_core.ipynb #fe25d3be
38
+ FOLDER_MIME = 'application/vnd.google-apps.folder'
39
+
40
+ def hsize(n):
41
+ "Human-readable byte size"
42
+ for u in ' KMGT':
43
+ if n < 1024: return f'{n:.0f}{u.strip()}B' if u==' ' else f'{n:.1f}{u}B'
44
+ n /= 1024
45
+ return f'{n:.1f}PB'
46
+
47
+ def _mtype(m): return m.split('.')[-1] if m.startswith('application/vnd.google-apps') else m
48
+
49
+ def _link(f):
50
+ "File name as an anchor opening it in Drive in a new tab"
51
+ nm = f.get('name') or ''
52
+ return f'<a href="{url}" target="_blank">{nm}</a>' if (url:=f.get('webViewLink')) else nm
53
+
54
+ class File(AttrDict):
55
+ def __init__(self, drive, d):
56
+ super().__init__(d)
57
+ self.drive = drive
58
+
59
+ def _desc(self, nm):
60
+ sz = f', {hsize(int(self.size))}' if self.get('size') else ''
61
+ trash = '🗑' if self.get('trashed') else ''
62
+ return f'{type(self).__name__}({self.id}: {trash}{nm} ({_mtype(self.get("mimeType", ""))}{sz}) {self.get("modifiedTime", "")})'
63
+
64
+ def __repr__(self): return self._desc(self.get('name', ''))
65
+ def _repr_markdown_(self): return self._desc(_link(self))
66
+
67
+ async def refresh(self, fields=FIELDS):
68
+ self.update(await self.drive.client.files.get(file_id=self.id, fields=fields))
69
+ return self
70
+
71
+ @classmethod
72
+ async def fetch(cls, drive, id): return await cls(drive, dict(id=id)).refresh()
73
+
74
+ class Folder(File): pass
75
+
76
+ def _fid(f): return f.id if isinstance(f, File) else f
77
+
78
+ def _mk_file(drive, d):
79
+ cls = Folder if d.get('mimeType')==FOLDER_MIME else File
80
+ return cls(drive, d)
81
+
82
+ # %% ../nbs/00_core.ipynb #a5cc3392
83
+ _upload_url = 'https://www.googleapis.com/upload/drive/v3/files'
84
+
85
+ def _multipart_related(meta, data, mime):
86
+ b = uuid4().hex
87
+ body = (f'--{b}\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n{json.dumps(meta)}\r\n'
88
+ f'--{b}\r\nContent-Type: {mime}\r\n\r\n').encode() + data + f'\r\n--{b}--'.encode()
89
+ return body, {'Content-Type': f'multipart/related; boundary={b}'}
90
+
91
+ @patch
92
+ async def upload(self:Drive,
93
+ path=None, # File to upload
94
+ name=None, # Name in Drive (defaults to `path`'s name)
95
+ data=None, # Content bytes, as an alternative to `path`
96
+ mime=None, # Content type (guessed from `name` if not given)
97
+ folder=None, # Destination `Folder` or folder id (default: My Drive root)
98
+ ):
99
+ "Upload a file to Drive, returning the new `File`"
100
+ if path:
101
+ p = Path(path)
102
+ name, data = name or p.name, p.read_bytes()
103
+ mime = mime or mimetypes.guess_type(name)[0] or 'application/octet-stream'
104
+ meta = dict(name=name)
105
+ if folder: meta['parents'] = [_fid(folder)]
106
+ body, hdrs = _multipart_related(meta, data, mime)
107
+ r = await self.client.transport.request('POST', _upload_url, content=body, headers=hdrs,
108
+ params=dict(uploadType='multipart', fields=FIELDS))
109
+ return _mk_file(self, r)
110
+
111
+ # %% ../nbs/00_core.ipynb #d7fe7a99
112
+ def _file_row(f):
113
+ sz = hsize(int(f.size)) if f.get('size') else ''
114
+ return f'| {f.id} | {"🗑" if f.get("trashed") else ""}{_link(f)} | {_mtype(f.get("mimeType") or "")} | {sz} | {(f.get("modifiedTime") or "")[:10]} |'
115
+
116
+ _file_hdr = '| id | name | type | size | modified |\n|-|-|-|-|-|\n'
117
+ class Files(L):
118
+ def __init__(self, d, *rest, drive=None, **kwargs):
119
+ super().__init__(d, *rest, **kwargs)
120
+ self.drive = drive
121
+
122
+ def _repr_markdown_(self): return _file_hdr + '\n'.join(self.map(_file_row))
123
+
124
+ @patch
125
+ async def search_files(self:Drive, q=None, max_results=20, fields=FIELDS, **kwargs):
126
+ r = await self.client.files.list(q=q, page_size=max_results, fields=f'files({fields})', **kwargs)
127
+ return Files(L(r.get('files') or []).map(lambda o: _mk_file(self, o)), drive=self)
128
+
129
+ # %% ../nbs/00_core.ipynb #c5cc0e5e
130
+ _exports = {'application/vnd.google-apps.document': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
131
+ 'application/vnd.google-apps.spreadsheet': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
132
+ 'application/vnd.google-apps.presentation': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
133
+ 'application/vnd.google-apps.drawing': 'image/png'}
134
+
135
+ @patch
136
+ async def download(self:File,
137
+ save=None, # Optional path to also write the bytes to (a directory uses the file's name)
138
+ mime=None, # Export format for Google-native files
139
+ ):
140
+ "File content as bytes; Google-native files are exported (docx/xlsx/pptx by default)"
141
+ native = self.mimeType.startswith('application/vnd.google-apps')
142
+ if not native:
143
+ if mime: raise ValueError(f'`mime` is for exporting Google-native files; {self.name} is {self.mimeType}')
144
+ r = await self.drive.client.files.get(file_id=self.id, alt='media', raw=True)
145
+ else: r = await self.drive.client.files.export(file_id=self.id, mime_type=mime or _exports[self.mimeType], raw=True)
146
+ data = r.content
147
+ if save:
148
+ p = Path(save)
149
+ if p.is_dir(): p = p/self.name
150
+ p.write_bytes(data)
151
+ return data
152
+
153
+ # %% ../nbs/00_core.ipynb #52081533
154
+ @patch
155
+ async def create_folder(self:Drive, name, parent=None):
156
+ "Create a folder, returning the new `Folder`"
157
+ meta = dict(name=name, mime_type=FOLDER_MIME, fields=FIELDS)
158
+ if parent: meta['parents'] = [_fid(parent)]
159
+ return Folder(self, await self.client.files.create(**meta))
160
+
161
+ @patch
162
+ async def ls(self:Folder, q=None, **kwargs):
163
+ "Search within this folder"
164
+ qs = f"'{self.id}' in parents and trashed=false"
165
+ if q: qs = f'{qs} and ({q})'
166
+ return await self.drive.search_files(qs, **kwargs)
167
+
168
+ @patch
169
+ @delegates(Drive.upload)
170
+ async def upload(self:Folder, path=None, **kwargs):
171
+ "Upload into this folder"
172
+ return await self.drive.upload(path, folder=self, **kwargs)
173
+
174
+ # %% ../nbs/00_core.ipynb #859523ef
175
+ @patch
176
+ async def rename(self:File, name):
177
+ "Rename to `name`"
178
+ return self.update(await self.drive.client.files.update(file_id=self.id, name=name, fields=FIELDS))
179
+
180
+ @patch
181
+ async def move(self:File, folder):
182
+ "Move into `folder` (a `Folder` or folder id)"
183
+ return self.update(await self.drive.client.files.update(file_id=self.id, add_parents=_fid(folder),
184
+ remove_parents=','.join(self.get('parents') or []), fields=FIELDS))
185
+
186
+ @patch
187
+ async def copy(self:File, name=None, folder=None):
188
+ "Server-side copy, optionally renamed into `folder`; returns the new `File`"
189
+ meta = dict(file_id=self.id, fields=FIELDS)
190
+ if name: meta['name'] = name
191
+ if folder: meta['parents'] = [_fid(folder)]
192
+ return _mk_file(self.drive, await self.drive.client.files.copy(**meta))
193
+
194
+ # %% ../nbs/00_core.ipynb #01e0b545
195
+ @patch
196
+ async def _set_trashed(self:File, trashed):
197
+ return self.update(await self.drive.client.files.update(file_id=self.id, trashed=trashed, fields=FIELDS))
198
+
199
+ @patch
200
+ async def trash(self:File):
201
+ "Move to the trash (recoverable for 30 days)"
202
+ sys.audit('solvedrive.File.trash')
203
+ return await self._set_trashed(True)
204
+
205
+ @patch
206
+ async def untrash(self:File):
207
+ "Restore from the trash"
208
+ return await self._set_trashed(False)
209
+
210
+ @patch
211
+ async def delete(self:File):
212
+ "Delete permanently, skipping the trash"
213
+ sys.audit('solvedrive.File.delete')
214
+ return await self.drive.client.files.delete(file_id=self.id)
215
+
216
+ # %% ../nbs/00_core.ipynb #72defcd0
217
+ @patch
218
+ def _gfiles(self:Files): return self.drive.client._gservice.files()
219
+
220
+ @patch
221
+ async def refresh(self:Files, fields=FIELDS):
222
+ "Batch re-fetch metadata for all files"
223
+ if not self: return self
224
+ res = self.drive.client.batch_get([(f.id, self._gfiles().get(fileId=f.id, fields=fields)) for f in self])
225
+ for f in self: f.update(dict2obj(res[f.id]))
226
+ return self
227
+
228
+ @patch
229
+ async def _set_trashed(self:Files, trashed):
230
+ if not self: return self
231
+ res = self.drive.client.batch_get([(f.id, self._gfiles().update(fileId=f.id, body=dict(trashed=trashed), fields=FIELDS)) for f in self])
232
+ for f in self: f.update(dict2obj(res[f.id]))
233
+ return self
234
+
235
+ @patch
236
+ async def trash(self:Files):
237
+ "Batch move all files to the trash"
238
+ sys.audit('solvedrive.Files.trash')
239
+ return await self._set_trashed(True)
240
+
241
+ @patch
242
+ async def untrash(self:Files):
243
+ "Batch restore all files from the trash"
244
+ return await self._set_trashed(False)
245
+
246
+ @patch
247
+ async def delete(self:Files):
248
+ "Batch delete all files permanently"
249
+ sys.audit('solvedrive.Files.delete')
250
+ if self: self.drive.client.batch_get([(f.id, self._gfiles().delete(fileId=f.id)) for f in self])
251
+
252
+ # %% ../nbs/00_core.ipynb #6d5ec299
253
+ @patch
254
+ async def share(self:File,
255
+ email=None, # User or group to share with (anyone-with-the-link if None)
256
+ role='reader', # 'reader', 'commenter', 'writer', or 'owner'
257
+ notify=False, # Send the grantee a notification email?
258
+ ):
259
+ "Grant access, returning the new permission"
260
+ sys.audit('solvedrive.File.share')
261
+ meta = dict(file_id=self.id, role=role, send_notification_email=notify)
262
+ if email: meta.update(type='user', email_address=email)
263
+ else: meta['type'] = 'anyone'
264
+ return await self.drive.client.permissions.create(**meta)
265
+
266
+ @patch(as_prop=True)
267
+ async def permissions(self:File):
268
+ r = await self.drive.client.permissions.list(file_id=self.id, fields='permissions(id,type,role,emailAddress)')
269
+ return r.permissions
270
+
271
+ @patch
272
+ async def unshare(self:File, permission_id):
273
+ "Revoke a permission by id"
274
+ return await self.drive.client.permissions.delete(file_id=self.id, permission_id=permission_id)
solvedrive/skill.py ADDED
@@ -0,0 +1,80 @@
1
+ """Load this skill when an agent needs to search, download, and upload Google Drive files using solvedrive. It covers connecting to Drive, searching with Drive's query syntax, downloading file content and exporting Google Docs, and uploading files and creating folders. Organizing, trash, deletion, and sharing are documented for reference but are not enabled by default.
2
+
3
+ Connections use the `Drive` client: `drive = await Drive.init(scopes='readonly')`. Scopes control what the underlying OAuth token may do: `'readonly'` to search and download, `'file'` to also manage the files the app created, or `'full'` for everything. The first connection opens a browser to authorize, then caches the token so later runs don't re-prompt. `await drive.about()` returns the signed-in account, with the address on its `email` attribute.
4
+
5
+ Everything in Drive is a **file**: documents, images, even folders (a folder is a file with a special `mimeType`). solvedrive wraps them in three types:
6
+
7
+ - **File**: id plus metadata, with content accessed via `download`. The API returns partial resources, so a `File` carries our default fields (`name`, `mimeType`, `size`, `modifiedTime`, `parents`, `trashed`, `webViewLink`); anything else needs `fields=` at search time or `await f.refresh(fields=...)`.
8
+ - **Folder**: a `File` subclass adding `ls` and `upload` into itself.
9
+ - **Files**: a collection of the above with a table repr and batch operations.
10
+
11
+ Reprs render file names as links opening the file in Drive, so include them when reporting results to the user.
12
+
13
+ All solvedrive methods are async, so `await` them.
14
+
15
+ # Searching
16
+
17
+ Search uses Drive's own query syntax. Common operators: `name = 'report.pdf'`, `name contains 'report'`, `fullText contains 'budget'`, `mimeType = 'application/pdf'`, `mimeType contains 'google-apps'` (Google-native files), `'<folder-id>' in parents`, `'user@example.com' in owners`, and date filters like `modifiedTime > '2026-01-01'`. Combine them with `and`/`or`/`not`.
18
+
19
+ fs = await drive.search_files("name contains 'report' and trashed=false", max_results=20)
20
+
21
+ Trashed files match too unless you exclude them, so almost every query wants `and trashed=false`.
22
+
23
+ `folder.ls(q=None)` searches within a folder (already excluding trashed), and `File.fetch(drive, id)` gets one file when its id is already known.
24
+
25
+ Search is keyword-driven and is not proof of absence. If a query comes back empty, try alternate terms (partial names, `fullText contains`, owners, likely parent folders) before concluding something isn't there.
26
+
27
+ # Downloading
28
+
29
+ `await f.download()` returns the file's bytes; pass `save=` a directory or filename to also write them to disk. Google-native files (Docs, Sheets, Slides, Drawings) have no bytes of their own, so `download` exports them instead: docx for Docs, xlsx for Sheets, pptx for Slides, png for Drawings, or any supported `mime=` you ask for. Exports are capped at 10MB by the API.
30
+
31
+ data = await f.download()
32
+ await f.download(save='~/Downloads')
33
+ pdf = await doc.download(mime='application/pdf')
34
+
35
+ `mime=` is only for Google-native files; a regular file's bytes are returned as-is, and asking to convert one raises an error.
36
+
37
+ # Uploading and folders
38
+
39
+ `upload` sends a local path (or bytes plus a `name`) to Drive, returning the new `File`. The content type is guessed from the name unless `mime=` is given, and `folder=` targets a destination (default: My Drive root). Uploads are capped at 5MB.
40
+
41
+ f = await drive.upload('report.pdf', folder=folder)
42
+ f = await drive.upload(data=b'...', name='notes.txt')
43
+
44
+ `await drive.create_folder(name, parent=None)` makes a folder, and `await folder.upload(...)` drops files straight into one. Drive allows duplicate names, so uploading twice makes two files rather than overwriting.
45
+
46
+ # Organizing (not enabled by default)
47
+
48
+ These modify the user's existing files, so ask the user to enable them if the task requires it. `await f.rename(name)` renames; `await f.move(folder)` reparents; `await f.copy(name=None, folder=None)` is a server-side copy returning the new `File` (no bytes travel through your machine).
49
+
50
+ # Trash and deleting (not enabled by default)
51
+
52
+ Drive treats these differently: `await f.trash()` flips the `trashed` flag, recoverable via `await f.untrash()` for 30 days before Drive purges it; `await f.delete()` is permanent and immediate, skipping the trash. Deleting a folder deletes everything inside it.
53
+
54
+ # Sharing (not enabled by default)
55
+
56
+ `await f.share(email=None, role='reader', notify=False)` grants access, either to an email address or to anyone-with-the-link when no email is given, after which `f.webViewLink` is shareable. `await f.permissions` (a property, no parens) lists the current grants, and `await f.unshare(permission_id)` revokes one. Sharing exposes the user's data outward, so treat it as strictly opt-in.
57
+
58
+ # Batch operations
59
+
60
+ Operating on many files one request at a time is slow. A `Files` collection batches: `await fs.refresh()` re-fetches metadata for every file in one round trip, and `trash`/`untrash`/`delete` (not enabled by default) act on the whole collection the same way, so a search result can be acted on as a unit.
61
+
62
+ # Gotchas
63
+
64
+ All solvedrive methods are async, so `await` them, including the `permissions` property (`await f.permissions`).
65
+
66
+ The API returns partial resources: only the default fields are present unless asked for. An unexpectedly missing attribute usually means the field wasn't requested rather than empty. `await f.refresh(fields=...)` fills it in.
67
+
68
+ `size` is a string, and is absent for folders and Google-native files.
69
+
70
+ Searches match trashed files unless the query excludes them with `trashed=false`.
71
+
72
+ Scopes gate what you can do: `'readonly'` can't upload or modify. A permission error usually means the client was created with too narrow a scope.
73
+ """
74
+ from pyskills.core import allow
75
+ from solvedrive.core import Drive, File, Folder, Files
76
+
77
+ __all__ = ['Drive', 'File', 'Folder', 'Files']
78
+
79
+ allow({Drive: ['about', 'search_files', 'upload', 'create_folder'], File: ['refresh', 'fetch', 'download'],
80
+ Folder: ['ls', 'upload'], Files: ['refresh']})
@@ -0,0 +1,114 @@
1
+ Metadata-Version: 2.4
2
+ Name: solvedrive
3
+ Version: 0.0.1
4
+ Summary: Google Drive client built on the Drive API
5
+ Author-email: Nathan Cooper <nathanacooper@proton.me>
6
+ License: Apache-2.0
7
+ Project-URL: Repository, https://github.com/answerDotAI/solvedrive
8
+ Project-URL: Documentation, https://answerDotAI.github.io/solvedrive/
9
+ Keywords: nbdev
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: fastcore
16
+ Requires-Dist: fastgws>=0.2.5
17
+ Requires-Dist: fastspec>=0.1.3
18
+ Dynamic: license-file
19
+
20
+ # solvedrive
21
+
22
+
23
+ <!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
24
+
25
+ solvedrive is an async Python client for Google Drive. It wraps the Drive REST API in a few small classes ([`Drive`](https://answerDotAI.github.io/solvedrive/core.html#drive), [`File`](https://answerDotAI.github.io/solvedrive/core.html#file), [`Folder`](https://answerDotAI.github.io/solvedrive/core.html#folder), and the [`Files`](https://answerDotAI.github.io/solvedrive/core.html#files) collection), so you can upload and download files, search with Drive’s query syntax, export Google Docs, organize with folders, and share, all with plain method calls.
26
+
27
+ It is built on [fastgws](https://github.com/AnswerDotAI/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.
28
+
29
+ ## Installation
30
+
31
+ Install latest from [pypi](https://pypi.org/project/solvedrive/)
32
+
33
+ ``` sh
34
+ $ pip install solvedrive
35
+ ```
36
+
37
+ ## How to use
38
+
39
+ solvedrive signs in with OAuth 2.0 through [fastgws](https://github.com/AnswerDotAI/fastgws), which expects an OAuth client secret at `~/.config/fastgws/credentials.json`. The fastgws docs cover how to create that file from a Google Cloud project. The first connection opens a browser to authorize the scopes you asked for, then caches the token so later runs don’t prompt again.
40
+
41
+ Create a [`Drive`](https://answerDotAI.github.io/solvedrive/core.html#drive) client with the scopes you need: `readonly` to search and download, `file` to also manage the files your app created, or `full` for everything. `about()` returns the signed-in account, with the address on its `email` attribute.
42
+
43
+ ``` python
44
+ drive = await Drive.init(scopes='full')
45
+ about = await drive.about()
46
+ about.email
47
+ ```
48
+
49
+ 'nc@answer.ai'
50
+
51
+ ### Uploading
52
+
53
+ `upload` sends bytes or a local path to Drive, returning the new [`File`](https://answerDotAI.github.io/solvedrive/core.html#file). Its repr shows the essentials, with the name linking to the file in Drive.
54
+
55
+ ``` python
56
+ f = await drive.upload(data=b'hello from solvedrive!', name='solvedrive_hello.txt')
57
+ f
58
+ ```
59
+
60
+ File(1q7Ki1z40Q2Ec5Xl9eEHMDwMfx4lwGw3Q: <a href="https://drive.google.com/file/d/1q7Ki1z40Q2Ec5Xl9eEHMDwMfx4lwGw3Q/view?usp=drivesdk" target="_blank">solvedrive_hello.txt</a> (text/plain, 22B) 2026-07-28T13:48:55.654Z)
61
+
62
+ ### Searching
63
+
64
+ `search_files` takes Drive’s own [query syntax](https://developers.google.com/workspace/drive/api/guides/search-files), the same operators the Drive search box uses, and returns a [`Files`](https://answerDotAI.github.io/solvedrive/core.html#files) collection with a table repr.
65
+
66
+ ``` python
67
+ fs = await drive.search_files("name = 'solvedrive_hello.txt' and trashed=false")
68
+ fs
69
+ ```
70
+
71
+ | id | name | type | size | modified |
72
+ |----|----|----|----|----|
73
+ | 1q7Ki1z40Q2Ec5Xl9eEHMDwMfx4lwGw3Q | <a href="https://drive.google.com/file/d/1q7Ki1z40Q2Ec5Xl9eEHMDwMfx4lwGw3Q/view?usp=drivesdk" target="_blank">solvedrive_hello.txt</a> | text/plain | 22B | 2026-07-28 |
74
+
75
+ ### Downloading
76
+
77
+ `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.
78
+
79
+ ``` python
80
+ await f.download()
81
+ ```
82
+
83
+ b'hello from solvedrive!'
84
+
85
+ ### Folders
86
+
87
+ A folder is a file with a special `mimeType`. `create_folder` makes one, `move` puts files in it, and `ls` lists what it holds.
88
+
89
+ ``` python
90
+ folder = await drive.create_folder('solvedrive demo')
91
+ await f.move(folder)
92
+ await folder.ls()
93
+ ```
94
+
95
+ | id | name | type | size | modified |
96
+ |----|----|----|----|----|
97
+ | 1q7Ki1z40Q2Ec5Xl9eEHMDwMfx4lwGw3Q | <a href="https://drive.google.com/file/d/1q7Ki1z40Q2Ec5Xl9eEHMDwMfx4lwGw3Q/view?usp=drivesdk" target="_blank">solvedrive_hello.txt</a> | text/plain | 22B | 2026-07-28 |
98
+
99
+ ### Sharing
100
+
101
+ `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.
102
+
103
+ ``` python
104
+ p = await f.share()
105
+ await f.permissions
106
+ ```
107
+
108
+ [{'id': 'anyoneWithLink', 'type': 'anyone', 'role': 'reader'}, {'id': '12635610242443046038', 'type': 'user', 'emailAddress': 'nc@answer.ai', 'role': 'owner'}]
109
+
110
+ There’s more in `solvedrive.core`: renaming and copying, trash versus permanent deletion, and operating on a whole [`Files`](https://answerDotAI.github.io/solvedrive/core.html#files) collection at once through Google’s batch protocol. See the [docs](https://answerDotAI.github.io/solvedrive/) for the full tour.
111
+
112
+ ### Use as an LLM skill
113
+
114
+ solvedrive registers a [pyskills](https://github.com/AnswerDotAI/pyskills) skill, so an LLM host such as solveit can load it and use the safe API (searching, downloading, uploading, creating folders) by default. Renaming, moving, trash, deletion, and sharing are documented in the skill but are not enabled, so you turn them on when a task needs them.
@@ -0,0 +1,10 @@
1
+ solvedrive/__init__.py,sha256=sXLh7g3KC4QCFxcZGBTpG2scR7hmmBsMjq6LqRptkRg,22
2
+ solvedrive/_modidx.py,sha256=4GA_0iIhsPkY2NFVvg4mDqdVYFxnpS4s_KGzJLD9OCk,5336
3
+ solvedrive/core.py,sha256=RZj_6QrXl6ByMI-UKHtbtVtfCeR2p0Aj4keM_YxaNAM,10732
4
+ solvedrive/skill.py,sha256=QsSRjVZWaBpsrZR3VbEaTbPCUnuIJkcc5VgMBgfMOJw,6127
5
+ solvedrive-0.0.1.dist-info/licenses/LICENSE,sha256=xV8xoN4VOL0uw9X8RSs2IMuD_Ss_a9yAbtGNeBWZwnw,11337
6
+ solvedrive-0.0.1.dist-info/METADATA,sha256=o9y65c0WCDHrwNrMn9JAAYcB-v4J6gKwhjLd76LZkaA,5731
7
+ solvedrive-0.0.1.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
8
+ solvedrive-0.0.1.dist-info/entry_points.txt,sha256=JcP-X8YEZC_Dru6vbOHproNdoQ6BR1mWvm2HrEYAaVo,90
9
+ solvedrive-0.0.1.dist-info/top_level.txt,sha256=2yrO4YJH_AKf1WtZGbC8cacG08BmcJgNNjcQmQUu2-w,11
10
+ solvedrive-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (83.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,5 @@
1
+ [nbdev]
2
+ solvedrive = solvedrive._modidx:d
3
+
4
+ [pyskills]
5
+ solvedrive.skill = solvedrive.skill
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2022, fastai
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1 @@
1
+ solvedrive