
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
googleapiutils2
Advanced tools
Python wrapper for Google APIs: Drive, Sheets, Gmail, Admin, Groups, Geocoding.
pip install googleapiutils2
uv add googleapiutils2
Requires Python ^3.12
googleapiutils2 provides a unified, Pythonic interface for Google APIs with built-in:
from googleapiutils2 import Drive, GoogleMimeTypes
drive = Drive()
# Upload
drive.upload("file.csv", to_mime_type=GoogleMimeTypes.sheets, parents=["folder_id"])
drive.upload("./folder", recursive=True, update=True)
# List
for file in drive.list(query="name contains 'report'"):
print(f"{file['name']}: {file['id']}")
# Download
drive.download("file_id", "./output.pdf", mime_type=GoogleMimeTypes.pdf)
drive.download("folder_id", "./local_folder", recursive=True)
from googleapiutils2 import Sheets, SheetsValueRange
sheets = Sheets()
Sheet1 = SheetsValueRange(sheets, sheet_url, "Sheet1")
# Slice notation (NumPy-like)
Sheet1[1, "A"].update([["Value"]])
Sheet1[2:5, 1:3].update([[1,2,3], [4,5,6], [7,8,9]])
data = Sheet1[...].read()
# Batch updates
sheets.batch_update(sheet_url, {
Sheet1[1, ...]: [["Header 1", "Header 2"]],
Sheet1[2:4, ...]: [[1, 2], [3, 4]]
})
# DataFrame integration
import pandas as pd
df = Sheet1[...].to_frame()
Sheet1.update(sheets.from_frame(df, include_header=True))
# Formatting
sheets.format(sheet_url, Sheet1[1, ...], bold=True, background_color="#d48686")
from googleapiutils2 import Mail
mail = Mail()
# Send email
mail.send(
sender="me@example.com",
to="user@example.com",
subject="Test",
body="Hello"
)
# List messages
for msg in mail.list_messages(query="from:user@example.com after:2024/01/01"):
print(msg['id'], msg['snippet'])
from googleapiutils2 import Admin
admin = Admin()
# Create user
user = admin.create_user(
primary_email="test@domain.com",
given_name="Test",
family_name="User",
password="temp123"
)
# List users
for user in admin.list_users(query="givenName:John"):
print(user['primaryEmail'])
from googleapiutils2 import Groups
groups = Groups()
# Create group
group = groups.create(
email="team@domain.com",
name="Engineering",
description="All engineers"
)
# Add members
groups.members_insert("team@domain.com", "user@domain.com")
for member in groups.members_list("team@domain.com"):
print(member['email'], member['role'])
from googleapiutils2 import Geocode
geocoder = Geocode(api_key="YOUR_API_KEY")
# Address to coordinates
results = geocoder.geocode("1600 Amphitheatre Parkway, Mountain View, CA")
print(results[0]['geometry']['location']) # {'lat': 37.422, 'lng': -122.084}
# Coordinates to address
results = geocoder.reverse_geocode(lat=37.422, long=-122.084)
from googleapiutils2 import SheetsMonitor
def on_change(data, monitor):
print(f"Sheet updated: {len(data)} rows")
monitor = SheetsMonitor(sheets, drive, sheet_url, on_change, interval=30)
monitor.start()
Two authentication methods supported:
When to use:
Setup:
Usage:
from googleapiutils2 import Drive, get_oauth2_creds
# Basic service account
creds = get_oauth2_creds(client_config="auth/service-account.json")
drive = Drive(creds=creds)
# With domain-wide delegation (Workspace only)
creds = get_oauth2_creds(client_config="auth/service-account.json")
creds = creds.with_subject("user@domain.com") # Impersonate user
drive = Drive(creds=creds)
When to use:
Setup:
Usage:
# First run: opens browser for authorization
# Token saved to auth/token.pickle for reuse
creds = get_oauth2_creds(
client_config="auth/oauth2_credentials.json",
token_path="auth/token.pickle"
)
drive = Drive(creds=creds)
# Auto-discovery checks ./auth/credentials.json or GOOGLE_API_CREDENTIALS env var
drive = Drive()
sheets = Sheets()
Upload:
Download:
Operations:
get, list, create, copy, update, deletesync - Sync local β remote directoriesempty_trash - Empty trashSlice Notation:
Sheet[1, "A"] # Single cell
Sheet[2:5, 1:3] # Range
Sheet[1, ...] # Entire row
Sheet[..., "A"] # Entire column
Sheet[-1, -1] # Last cell
Sheet["A1:B2"] # A1 notation
Operations:
DataFrame Integration:
df = Sheet1[...].to_frame()
Sheet1.update(sheets.from_frame(df, include_header=True))
Messages:
Labels:
User Management:
Group Operations:
Member Operations:
Operations:
Base Class: DriveBase - All API classes inherit (except Geocode)
Exception Hierarchy:
GoogleAPIException
βββ InvalidRequestError
βββ OverQueryLimitError
βββ RequestDeniedError
βββ NotFoundError
βββ UnknownError
Key Patterns:
googleapiutils2/
βββ utils/ # Core: DriveBase, auth, caching, retry, MIME types
βββ drive/ # Google Drive API
βββ sheets/ # Google Sheets API
βββ mail/ # Gmail API
βββ admin/ # Workspace Admin API
βββ groups/ # Google Groups API
βββ geocode/ # Maps Geocoding API
βββ monitor.py # Change detection (DriveMonitor, SheetsMonitor)
pytest test/
Tests use real Google APIs with session-scoped fixtures and automatic cleanup.
See examples/ for more usage patterns:
drive_upload.py - File/folder uploadssheets_crud.py - Sheet operations and formattingmail.py - Email sendingmonitor.py - Change detectionMIT
FAQs
Wrapper for Google's Python API
We found that googleapiutils2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.