Configs2026年7月15日·1 分钟阅读

google-api-python-client — Official Python Client for Google APIs

The official Python client library for Google's discovery-based APIs, supporting Gmail, Drive, Sheets, Calendar, YouTube, and hundreds more Google services.

Agent 就绪

这个资产会安全暂存

这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。

Stage only · 29/100策略:需暂存
Agent 入口
任意 MCP/CLI Agent
类型
CLI Tool
安装
Single
信任
信任等级:Established
入口
google-api-python-client Overview
安全暂存命令
npx -y tokrepo@latest install 5d4d23f4-808e-11f1-9bc6-00163e2b0d79 --target codex

先暂存文件;激活前需要读取暂存 README 和安装计划。

Introduction

google-api-python-client is Google's official Python library for accessing discovery-based Google APIs. Rather than shipping a separate SDK for each of Google's hundreds of services, it dynamically constructs API client objects from service discovery documents, giving you typed access to Gmail, Google Drive, Sheets, Calendar, YouTube Data, and more through a single library.

What google-api-python-client Does

  • Dynamically builds Python client objects for any Google API using service discovery
  • Handles OAuth 2.0 and service account authentication via the google-auth companion library
  • Supports batch requests to combine multiple API calls into a single HTTP request
  • Manages media upload and download with resumable transfer support
  • Provides automatic retry and exponential backoff for transient errors

Architecture Overview

The library revolves around the build() function, which fetches a JSON discovery document describing an API's endpoints, parameters, and schemas. From this document, it dynamically creates a Resource object with methods matching each API endpoint. Authentication is plugged in via google-auth credentials objects. HTTP transport uses httplib2 or the requests library. Media operations support chunked, resumable uploads for large files.

Self-Hosting & Configuration

  • Requires Python 3.7 or newer
  • Install core library: pip install google-api-python-client
  • Install auth helpers: pip install google-auth-oauthlib google-auth-httplib2
  • Create a project in Google Cloud Console, enable the desired APIs, and download credentials
  • Use OAuth 2.0 for user-facing apps or service accounts for server-to-server access

Key Features

  • Single library covers hundreds of Google APIs (Drive, Gmail, Sheets, Calendar, BigQuery, YouTube, etc.)
  • Discovery-based design means new API features work without library updates
  • Resumable media uploads for files of any size
  • Batch request support to reduce HTTP round trips
  • Compatible with both synchronous and async workflows

Comparison with Similar Tools

  • google-cloud-python — Handwritten client libraries for specific GCP services (Storage, BigQuery); google-api-python-client covers a broader range of consumer and workspace APIs
  • gspread — Specialized Google Sheets library with a simpler API; google-api-python-client is more general
  • PyDrive2 — Wrapper around google-api-python-client focused on Drive operations
  • googleapis/google-api-go-client — Go equivalent with the same discovery-based architecture

FAQ

Q: Which Google APIs does this library support? A: Any API that publishes a discovery document, which includes Gmail, Drive, Sheets, Calendar, YouTube, Cloud services, and many more.

Q: How do I authenticate? A: Use google-auth for OAuth 2.0 flows (desktop, web, service account) and pass the credentials object to the build() function.

Q: Can I use this for Google Cloud services like BigQuery? A: Yes, though Google recommends their dedicated cloud client libraries (google-cloud-bigquery) for GCP services, as those offer better ergonomics.

Q: What license is it under? A: Apache License 2.0.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产