概览
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Python 客户端库托管在 GitHub 上,并且该软件包可在 PyPI 上获取。
要求
该库需要 Python 3.8 或更高版本。
前提条件
在安装该库之前,您需要准备好开发者令牌和客户客户 ID。有关如何获取这些文件的说明,请参阅前提条件部分。
请注意,您将在后续步骤中生成其他必需的 OAuth2 令牌。
运行时和依赖项兼容性
Python 客户端库与 Python 软件基金会发布的支持的版本部分中的 Python 运行时保持兼容,但状态为“功能”或“预发布”的版本除外。
在采用新版 Python 运行时时,我们力求在发布后一个季度结束前发布与最新运行时兼容的新版 Python 客户端库。例如,如果 10 月份发布了新的运行时,那么到次年 3 月底,就会提供兼容的 Python 客户端库版本。
达到生命周期结束 (EOL) 的 Python 运行时在 python.org 的不受支持的版本部分中列出的生命周期结束日期之后不受支持。
在不受支持的 Python 运行时达到 EOL 后,我们随时可能会发布与这些运行时不兼容的 Python 客户端库版本。
对于依赖项(尤其是 Python 客户端库列为必需的任何由 Google 维护的软件包),我们将保持与由 Google 维护且根据 Google 的 OSS 破坏性变更政策被视为“受支持”的软件包的兼容性。
如需查看受支持的 Python 运行时和依赖项的完整列表,请参阅依赖项页面。
安装
按照我们的安装文档中的说明从 PyPi 安装该库,然后返回此页面。
配置
安装库后,您需要为其设置配置。您可以通过多种方式配置该库,详情请参阅我们的配置文档。
身份验证
选择配置类型后,您可以继续生成向 API 发出请求所需的其余 OAuth2 令牌。系统支持多种 OAuth2 流程,如下面的列表所示。如需详细了解这些流程之间的区别,以及如何确定哪种流程最适合您的应用,请参阅我们的 OAuth 文档。
发出 API 请求
将 OAuth2 令牌纳入配置后,您就可以发出 API 请求了。如需了解如何简单地测试库是否已正确配置以发出 API 请求,请参阅 get campaigns 示例。
如需运行 get_campaigns.py
示例,请在本地安装的 googleads-python
客户端库的根目录中运行以下命令:
$ python examples/basic_operations/get_campaigns.py -c \
INSERT_YOUR_CUSTOMER_ID_HERE
其他资源
在能够发出 API 请求后,请继续了解客户端库的以下用途:
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-26。
[null,null,["最后更新时间 (UTC):2025-08-26。"],[[["\u003cp\u003eThe Google Ads Python client library requires Python 3.8 or later and is compatible with supported Python runtimes, with new runtime support added by the end of the quarter following a new runtime's release.\u003c/p\u003e\n"],["\u003cp\u003eYou need a developer token and client customer ID before installation, and OAuth2 tokens are generated during the authentication process.\u003c/p\u003e\n"],["\u003cp\u003eConfiguration options are provided, along with guidance on OAuth flows for desktop/web and service accounts to authenticate API requests.\u003c/p\u003e\n"],["\u003cp\u003eA sample \u003ccode\u003eget_campaigns.py\u003c/code\u003e script helps test API request functionality, and resources on logging, field masks, and other library features are available.\u003c/p\u003e\n"],["\u003cp\u003eThe library is hosted on GitHub and available on PyPI for installation.\u003c/p\u003e\n"]]],[],null,["# Overview\n\nThe Python client library is hosted [on GitHub](https://github.com/googleads/google-ads-python),\nand the package is available on [PyPI](//pypi.org/project/google-ads/).\n\n### Requirements\n\nThe library requires Python 3.8 or later.\n\n### Prerequisites\n\nBefore installing the library, you will need a developer token and\nclient customer ID. Instructions on how to obtain them are outlined in the\n[prerequisites](/google-ads/api/docs/get-started/introduction) section.\nNote that you will generate the other required OAuth2 tokens in later steps.\n\n### Runtime and dependency compatibility\n\nThe Python client library maintains compatibility with the Python runtimes in\nthe\n[Supported Versions](https://devguide.python.org/versions/#supported-versions)\nsection published by the\n[Python Software Foundation](https://www.python.org/psf-landing/), except for\nversions with a status of \"feature\" or \"prerelease\".\n\nWhen adopting new versions of the Python runtime, we aim to release a new\nversion of the Python client library that is compatible with the latest runtime\nby the end of the quarter following its release. For example, if a new runtime\nis released in October, a compatible version of the Python client library will\nbe available by the end of March in the following year.\n\nPython runtimes that have reached End of Life (EOL) are not supported past the\nEnd of Life date in the\n[Unsupported Versions](https://www.python.org/psf-landing/) section of\n[python.org](https://www.python.org/).\n\nWe may release a version of the Python client library that is incompatible with\nunsupported Python runtimes at any point after they reach EOL.\n\nFor dependencies, (specifically, any Google-maintained packages that are\n[listed as required](//github.com/googleads/google-ads-python/blob/ef62b42152781ee6dc9081222dca49a758760544/setup.py#L18)\nby the Python client library), we will maintain compatibility with packages that\nare Google-maintained, and considered \"supported\" according to Google's\n[OSS Breaking Change Policy](https://opensource.google/documentation/policies/library-breaking-change).\n\nFor a complete list of supported Python runtimes and dependencies, see the\n[Dependencies](/google-ads/api/docs/client-libs/python/dependencies) page.\n\n### Installation\n\nFollow the instructions in our [installation](/google-ads/api/docs/client-libs/python/installation#install_the_module_from_pypi)\ndocumentation to install the library from PyPi and return to this page.\n\n### Configuration\n\nOnce you have installed the library you will need to set up a configuration for\nit. There are multiple ways to configure the library, which are described in our\n[configuration](/google-ads/api/docs/client-libs/python/configuration) documentation.\n\n### Authentication\n\nOnce you've chosen a configuration type you can proceed with generating the\nremaining OAuth2 tokens needed to make requests to the API. There are multiple\nsupported OAuth2 flows, which are documented in the list below. For details on\nthe differences between the flows and help deciding which is best for your\napplication, see our [OAuth](/google-ads/api/docs/oauth/overview) documentation.\n\n- [OAuth desktop and web application flows](/google-ads/api/docs/client-libs/python/oauth-web)\n- [OAuth service account flow](/google-ads/api/docs/client-libs/python/oauth-service)\n\n### Making an API request\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nOnce you've incorporated your OAuth2 tokens into your configuration, you're\nready to make an API request. Refer to the\n[get campaigns](/google-ads/api/samples/get-campaigns#python) example for\na simple way to test that the library is properly configured to make API\nrequests.\n\nTo run the `get_campaigns.py` sample, in the root directory of your locally\ninstalled `googleads-python` client library, run the following command: \n\n $ python examples/basic_operations/get_campaigns.py -c \\\n INSERT_YOUR_CUSTOMER_ID_HERE\n\n### Additional resources\n\nAfter you're able to make an API request, proceed to these uses of the client\nlibrary:\n\n- [Logging](/google-ads/api/docs/client-libs/python/logging)\n- [Field Masks](/google-ads/api/docs/client-libs/python/field-masks)\n- [Resource Names](/google-ads/api/docs/client-libs/python/resource-names)\n- [Proto Getters](/google-ads/api/docs/client-libs/python/proto-getters)\n- [Setting Empty Message Fields](/google-ads/api/docs/client-libs/python/empty-message-fields)"]]