{"id":6047,"library":"pydrive","title":"PyDrive","description":"PyDrive is a Python wrapper library for the Google Drive API that simplifies common tasks like authentication, file upload, download, and management. The current version is 1.3.1. However, the original PyDrive project is deprecated and no longer maintained. Its last release was in 2016, and the GitHub repository was archived in July 2021. Users are strongly encouraged to consider `PyDrive2` (pypi.org/project/PyDrive2), an actively maintained fork, for ongoing development and support.","status":"abandoned","version":"1.3.1","language":"en","source_language":"en","source_url":"https://github.com/googledrive/PyDrive","tags":["google drive","api client","cloud storage","oauth","deprecated"],"install":[{"cmd":"pip install pydrive","lang":"bash","label":"Install PyDrive"}],"dependencies":[{"reason":"PyDrive is a wrapper around this core Google API client library.","package":"google-api-python-client","optional":false},{"reason":"Used for OAuth 2.0 authentication, but is deprecated and a source of compatibility and security concerns.","package":"oauth2client","optional":false},{"reason":"A dependency of `oauth2client`, which is largely unmaintained and can lead to issues with newer Python environments.","package":"httplib2","optional":false}],"imports":[{"symbol":"GoogleAuth","correct":"from pydrive.auth import GoogleAuth"},{"symbol":"GoogleDrive","correct":"from pydrive.drive import GoogleDrive"}],"quickstart":{"code":"from pydrive.auth import GoogleAuth\nfrom pydrive.drive import GoogleDrive\nimport os\n\n# --- Pre-requisites for Quickstart ---\n# 1. Go to Google API Console (console.developers.google.com/apis/credentials)\n# 2. Create a new project or select an existing one.\n# 3. Enable the 'Google Drive API'.\n# 4. Create 'OAuth client ID' credentials:\n#    - Application type: 'Web application'\n#    - Authorized JavaScript origins: http://localhost:8080\n#    - Authorized redirect URIs: http://localhost:8080/\n# 5. Download the client configuration JSON file and rename it to 'client_secrets.json'.\n# 6. Place 'client_secrets.json' in the same directory as this script.\n# -------------------------------------\n\ngauth = GoogleAuth()\n\n# Try to load saved client credentials (e.g., from 'credentials.json' generated previously)\ngauth.LoadCredentials()\n\nif gauth.credentials is None:\n    # Authenticate if credentials are not found\n    print(\"Performing initial authentication via local webserver...\")\n    gauth.LocalWebserverAuth() # Creates local webserver and auto handles authentication.\nelif gauth.access_token_expired:\n    # Refresh them if expired\n    print(\"Refreshing expired access token...\")\n    gauth.Refresh()\nelse:\n    # Initialize the saved credentials\n    print(\"Using existing credentials.\")\n    gauth.Authorize()\n\n# Save the current credentials to a file for future use\ngauth.SaveCredentials()\n\ndrive = GoogleDrive(gauth)\n\n# --- Create and Upload a File ---\nfile_title = \"PyDrive_Registry_Test_File.txt\"\nfile_content = \"This is a test file uploaded using PyDrive from the registry quickstart. Hello, Google Drive!\"\n\n# Create GoogleDriveFile instance with metadata.\nfile_metadata = {'title': file_title, 'mimeType': 'text/plain'}\nfile1 = drive.CreateFile(file_metadata)\nfile1.SetContentString(file_content) # Set content from a string\nfile1.Upload() # Upload the file to Google Drive\nprint(f\"\\nSuccessfully uploaded file: '{file1['title']}' (ID: {file1['id']})\")\n\n# --- List Files (optional, for demonstration) ---\nprint(f\"\\nSearching for file with title '{file_title}'...\")\nfile_list = drive.ListFile({'q': f\"'me' in owners and title = '{file_title}' and trashed = false\"}).GetList()\nif file_list:\n    print(f\"Found {len(file_list)} file(s) with title '{file_title}':\")\n    for file in file_list:\n        print(f\" - Title: {file['title']}, ID: {file['id']}, MimeType: {file['mimeType']}\")\nelse:\n    print(f\"No file found with title '{file_title}'.\")","lang":"python","description":"This quickstart demonstrates how to authenticate with Google Drive using PyDrive's `LocalWebserverAuth()` flow and then create and upload a simple text file. It also includes basic error handling for token expiration and shows how to list files. Ensure you have a `client_secrets.json` file from the Google API Console in your script's directory before running."},"warnings":[{"fix":"Migrate to `PyDrive2` (`pip install pydrive2`), an actively maintained fork, for continued support, new features, and bug fixes.","message":"The original PyDrive project is explicitly deprecated and no longer maintained. Its GitHub repository has been archived. No further changes or bug fixes will be made, leading to potential future incompatibilities and security vulnerabilities.","severity":"breaking","affected_versions":"1.3.1 and earlier"},{"fix":"The recommended solution is to migrate to `PyDrive2`, which aims to address these underlying dependency issues by migrating to `google-auth`.","message":"PyDrive relies heavily on the `oauth2client` library for authentication, which is deprecated by Google and largely unmaintained. This can lead to security vulnerabilities, lack of thread-safety, and incompatibilities with newer Python versions or related libraries (e.g., `PyOpenSSL` or `httplib2`).","severity":"deprecated","affected_versions":"All versions of PyDrive"},{"fix":"To avoid frequent re-authentication in production or long-running scripts, ensure your OAuth consent screen's publishing status in the Google API Console is set to 'In production'.","message":"Authentication refresh tokens obtained from Google Cloud projects with an 'external user type' and a 'Testing' publishing status will expire after 7 days, requiring manual re-authentication.","severity":"gotcha","affected_versions":"All versions"},{"fix":"To grant broader access, you must manually specify the `oauth_scope` in a `settings.yaml` file (e.g., `oauth_scope: ['https://www.googleapis.com/auth/drive']`) and then re-authenticate to apply the new scopes. Deleting existing `credentials.json` before re-authentication might be necessary.","message":"By default, PyDrive's authentication might only grant access to root-level files and folders on your Google Drive. Accessing subfolders or files outside the default scope requires explicit configuration.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure the downloaded client configuration JSON file is renamed to `client_secrets.json` and resides in the same directory where your Python script is executed. Alternatively, you can explicitly specify the file path via `GoogleAuth.DEFAULT_SETTINGS['client_config_file']` or `gauth.LoadClientConfig(client_config_file='path/to/your/client_secrets.json')`.","message":"The `client_secrets.json` file, required for authentication, must be named exactly `client_secrets.json` and placed in the working directory of your script for PyDrive to find it automatically. Incorrect naming or placement will result in authentication errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}