A Python library for Google Drive file operations with caching
Project description
Driverator
A Python library for Google Drive file operations with built-in caching and async support.
Features
- File-centric design: each instance represents one file
- Upload, download, and update files
- Rename and move files between folders
- Delete files (trash or permanent)
- Share files with users or make public
- Manage permissions (list and remove)
- Automatic file discovery by name
- Check if file exists
- Persistent caching for metadata and URLs
- Async API
Installation
pip install driverator
Quick Start
import asyncio
from driverator import Driverator
async def main():
# Create file instance and upload
file = Driverator(
'path/to/service-account-key.json',
file_name='report.pdf',
folder_name='My Project'
)
await file.initialize()
await file.upload('local_report.pdf')
# Share file
await file.share('user@example.com', role='writer')
# Access file properties
print(f"File URL: {file.url}")
print(f"File size: {file.size} bytes")
print(f"MIME type: {file.mime_type}")
# Download file
await file.download('downloaded_report.pdf')
asyncio.run(main())
Advanced Usage
Update File Content
# Update existing file with new content
await file.update('updated_report.pdf')
print(f"Updated size: {file.size} bytes")
Rename and Move
# Rename file
await file.rename('Q1_report.pdf')
# Move to different folder
await file.move(folder_name='Archive')
Manage Permissions
# List all permissions
permissions = await file.list_permissions()
for perm in permissions:
print(f"{perm['emailAddress']}: {perm['role']}")
# Remove specific permission
await file.remove_permission('user@example.com')
Delete Files
# Move to trash
await file.delete(permanent=False)
# Permanent delete
await file.delete(permanent=True)
Check File Existence
if await file.exists():
print("File exists and is not trashed")
Working with Existing Files
# By file ID
file = Driverator('service-account-key.json', file_id='abc123...')
await file.initialize()
print(file.file_name) # Loads metadata from Drive
# By file name (searches in folder)
file = Driverator(
'service-account-key.json',
file_name='report.pdf',
folder_name='My Project'
)
await file.initialize() # Finds existing file or ready to upload
API Reference
Driverator
Constructor:
service_account_file: Path to service account JSONfile_id: Optional file ID for existing filefile_name: Optional file name (finds or creates)folder_id: Optional folder ID to work withinfolder_name: Optional folder name (finds or creates)clear_cache: Clear existing cachettl: Cache time-to-live in days
Methods:
async initialize(): Initialize and authenticateasync upload(local_path): Upload file to Driveasync update(local_path): Update/replace file contentasync download(local_path): Download file from Driveasync rename(new_name): Rename the fileasync move(folder_id=None, folder_name=None): Move to different folderasync delete(permanent=False): Delete file (trash or permanent)async exists(): Check if file exists (and not trashed)async share(email_addresses, role='reader'): Share with usersasync set_anyone_access(role='reader'): Make publicly accessibleasync list_permissions(): List all permissionsasync remove_permission(email_address): Revoke user access
Properties:
url: Shareable view URLdownload_url: Direct download URLfile_id: Google Drive file IDfile_name: File namesize: File size in bytesmime_type: MIME typecreated_time: Creation timestampmodified_time: Last modified timestamp
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
driverator-0.1.0.tar.gz
(8.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file driverator-0.1.0.tar.gz.
File metadata
- Download URL: driverator-0.1.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b9cf046391ba0c5713fcd552fc75092af0a063cce8cca540200a5b8b02840ac
|
|
| MD5 |
ec7f417f758c16a5cd5dcb413da4a1b9
|
|
| BLAKE2b-256 |
69d2cd3ef5401bda3b50b672274e0dcc7e8b8ca2e2b7f691a2cfdc6ac640690a
|
File details
Details for the file driverator-0.1.0-py3-none-any.whl.
File metadata
- Download URL: driverator-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fc3ce878d1c585296d984ebf3cd83d3684cdc737de133a0c830bffd8ff9714a
|
|
| MD5 |
fc17648c73ec22de147d492e7bd55abc
|
|
| BLAKE2b-256 |
673dbf7f559931fd91b6a6b7faf576867968a4dd797e9a7d332f021a4fbaa2ad
|