Skip to main content

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 JSON
  • file_id: Optional file ID for existing file
  • file_name: Optional file name (finds or creates)
  • folder_id: Optional folder ID to work within
  • folder_name: Optional folder name (finds or creates)
  • clear_cache: Clear existing cache
  • ttl: Cache time-to-live in days

Methods:

  • async initialize(): Initialize and authenticate
  • async upload(local_path): Upload file to Drive
  • async update(local_path): Update/replace file content
  • async download(local_path): Download file from Drive
  • async rename(new_name): Rename the file
  • async move(folder_id=None, folder_name=None): Move to different folder
  • async 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 users
  • async set_anyone_access(role='reader'): Make publicly accessible
  • async list_permissions(): List all permissions
  • async remove_permission(email_address): Revoke user access

Properties:

  • url: Shareable view URL
  • download_url: Direct download URL
  • file_id: Google Drive file ID
  • file_name: File name
  • size: File size in bytes
  • mime_type: MIME type
  • created_time: Creation timestamp
  • modified_time: Last modified timestamp

License

MIT License

Project details


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)

Uploaded Source

Built Distribution

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

driverator-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

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

Hashes for driverator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6b9cf046391ba0c5713fcd552fc75092af0a063cce8cca540200a5b8b02840ac
MD5 ec7f417f758c16a5cd5dcb413da4a1b9
BLAKE2b-256 69d2cd3ef5401bda3b50b672274e0dcc7e8b8ca2e2b7f691a2cfdc6ac640690a

See more details on using hashes here.

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

Hashes for driverator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9fc3ce878d1c585296d984ebf3cd83d3684cdc737de133a0c830bffd8ff9714a
MD5 fc17648c73ec22de147d492e7bd55abc
BLAKE2b-256 673dbf7f559931fd91b6a6b7faf576867968a4dd797e9a7d332f021a4fbaa2ad

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