A Python package for easy interaction with Google Drive, Sheets, and Slides APIs.
- GCP (Google Cloud Platform) account
- GCP project with the Google Drive API enabled
- Service account with enambled permissions for selected Google Drive or Google Drive Folder
You can install the package directly from PyPI:
pip install goopyOr install from source:
git clone https://github.com/yourusername/goopy.git
cd goopy
pip install -e .goopy/
├── src/
│ ├── BaseGoogleServiceAPI.py (Base class for Google API services)
│ ├── DriveServiceAPI.py (Google Drive API wrapper)
│ ├── SheetServiceAPI.py (Google Sheets API wrapper)
│ └── SlidesServiceApi.py (Google Slides API wrapper)
├── examples/
│ └── examples.py (Example usage of the API wrappers)
├── requirements.txt
└── README.md
from goopy import DriveService
drive = DriveService()
file_id = drive.create_file(
file_name="My Document",
file_type="document",
folder_link="https://drive.google.com/drive/folders/your-folder-id"
)For more detailed examples, see the examples directory.
This guide explains how to set up and use the Google API tool with proper authentication.
- Go to the Google Cloud Console.
- Click on the project dropdown near the top of the page.
- Click New Project.
- Enter a project name and click Create.
- Wait for the project to be created and select it from the project dropdown.
- From your project dashboard, navigate to APIs & Services > Library.
- Search for and enable the following APIs:
- Google Drive API
- Google Sheets API (if needed)
- Any other Google APIs your tool requires
- Navigate to APIs & Services > Credentials.
- Click Create Credentials and select the appropriate type:
- OAuth 2.0 Client ID: For applications that access user data
- Service Account: For server-to-server interactions
- API Key: For simple API calls not requiring user data access
- Configure the OAuth consent screen if prompted.
- Select application type (Web application, Desktop app, etc.).
- Add authorized redirect URIs if necessary.
- Click Create.
- Download the JSON file containing your credentials.
- Enter a name and description for the service account.
- Click Create.
- Assign roles to the service account (e.g., Editor, Viewer).
- Create a key (JSON format) and download it.
- Keep this file secure as it grants access to your resources.
- Open your Google Drive.
- Navigate to or create the folder you want to share.
- Right-click on the folder and select Share.
- In the "Add people and groups" field, enter the service account email (found in your JSON credentials file or in the Google Cloud Console).
- Choose the appropriate permission level:
- Viewer: Can only view files
- Commenter: Can view and comment on files
- Editor: Can view, comment, and edit files
- Content manager: Can edit, delete, and add files
- Click Send.
When your application uses OAuth 2.0, users will be prompted to grant the requested permissions the first time they authenticate.
- Place your credentials file in a secure location accessible by the tool.
- Configure the tool to use the credentials file path.
- When running the tool for the first time with OAuth, you'll need to complete the authentication flow in a browser.
- The tool should now have access to the specified Google Drive resources.
- Never commit credentials to version control systems
- Use environment variables or secure secrets management
- Apply the principle of least privilege when assigning roles
- Regularly review and audit access permissions
- Access Denied Errors: Verify the email address has been correctly shared with the resource
- Authentication Errors: Ensure credentials are valid and have not expired
- API Quota Errors: Check your usage limits in the Google Cloud Console
For more detailed information, refer to the Google Cloud Documentation.