Vertex AI SDK for Python は、Vertex AI でデータの取り込みの自動化、モデルのトレーニング、予測の取得を行ううえで役立ちます。Vertex AI SDK では、Python コードを使用して Vertex AI API にアクセスするため、 Google Cloud コンソールでできるほとんどの操作をプログラムで行うことができます。
Vertex AI SDK for Python は、経験豊富な機械学習(ML)と人工知能(AI)のエンジニアや、プログラムでワークフローを自動化するデータ サイエンティストにおすすめです。Vertex AI SDK for Python は、Vertex AI Python クライアント ライブラリに類似していますが、より高いレベルで粒度が粗くなる点が異なります。詳細については、SDK とクライアント ライブラリの違いについてをご覧ください。
Vertex AI SDK for Python を使用してコードを記述する
Vertex AI SDK for Python を使用するには:
仮想環境で次のコマンドを実行して google-cloud-aiplatform パッケージをインストールします。このパッケージには、Vertex AI SDK for Python と Vertex AI Python クライアント ライブラリの両方が含まれています。
pipinstall--upgradegoogle-cloud-aiplatform
次のコードを使用して google.cloud.aiplatform 名前空間をインポートします。
fromgoogle.cloudimportaiplatform
If you're using a local shell, then create local authentication credentials for your user
account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
Vertex AI 用の Python のリファレンス: Vertex AI SDK、Vertex AI SDK のプレビュー、Vertex AI クライアント ライブラリなどが含まれる google-cloud-aiplatform パッケージのすべての名前空間、クラス、メソッド、プロパティに関するリファレンス ドキュメントです。
コードサンプルとチュートリアルを試す
ノートブック チュートリアルでは、大規模なワークフローの一部として Vertex AI SDK for Python を使用する方法を説明しています。詳細については、Vertex AI ノートブック チュートリアルをご覧ください。
Vertex AI SDK for Python をインストールすると、Vertex AI Python クライアント ライブラリもインストールされます。Vertex AI SDK と Vertex AI Python クライアント ライブラリは、同様の機能を異なる粒度で提供します。Vertex AI SDK は、クライアント ライブラリよりも高い抽象化レベルで動作し、最も一般的なデータ サイエンス ワークフローに適しています。これよりも低いレベルの機能が必要な場合は、Vertex AI Python クライアント ライブラリを使用します。
Vertex AI SDK は Python で使用できます。Vertex AI クライアント ライブラリは Python、Java、Node.js で使用できます。Java または Node.js クライアント ライブラリをインストールする方法については、Vertex AI クライアント ライブラリをインストールするをご覧ください。目的のプログラミング言語でクライアント ライブラリを使用できない場合は、Vertex AI REST API を使用できます。詳細については、Vertex AI REST リファレンスをご覧ください。
Vertex AI Python クライアント ライブラリと SDK を併用する
Vertex AI SDK for Python を使用していて、より高い柔軟性や制御が必要な場合、または Vertex AI SDK に含まれていないメソッドが必要な場合は、同じワークフローで Vertex AI Python クライアント ライブラリを使用できます。Vertex AI Python クライアント ライブラリは、別の名前空間を使用して Vertex AI API にアクセスします。クライアント ライブラリと Vertex AI SDK for Python の名前空間を同じ Python スクリプトで使用するには、名前空間ごとに import 行を Python スクリプトに追加します。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-04 UTC。"],[],[],null,["# Introduction to the Vertex AI SDK for Python\n\nThe Vertex AI SDK for Python helps you automate data ingestion, train models, and\nget predictions on Vertex AI. The Vertex AI SDK uses Python code to\naccess the Vertex AI API so that you can programmatically accomplish most of what\nyou can do in the Google Cloud console.\n\nTo learn how to install or update the Vertex AI SDK for Python, see [Install the\nVertex AI SDK for Python](/vertex-ai/docs/start/install-sdk). For more information, see\nthe [Vertex AI SDK for Python API reference documentation](/python/docs/reference/aiplatform/latest).\n\nWhy use the Vertex AI SDK\n-------------------------\n\nThe Vertex AI SDK for Python is recommended if you're an experienced machine\nlearning (ML) and artificial intelligence (AI) engineer or a data scientist who\nwants to programmatically automate your workflow. The Vertex AI SDK for Python is\nsimilar to the Vertex AI Python client library, except the\nVertex AI SDK is higher-level and less granular. For more information, see\n[Understand the SDK and client library differences](#sdk-vs-client-library).\n\n\u003cbr /\u003e\n\nWrite code with the Vertex AI SDK for Python\n--------------------------------------------\n\nTo use the Vertex AI SDK for Python:\n\n1. Install the `google-cloud-aiplatform` package, which includes both the Vertex AI SDK for Python and the Vertex AI Python client library, by running the following command in your virtual environment:\n\n pip install --upgrade google-cloud-aiplatform\n\n2. Use the following code to import the `google.cloud.aiplatform` namespace:\n\n from google.cloud import aiplatform\n\n | **Preview:** To use features for the Vertex AI SDK for Python that are still in [preview](/products#product-launch-stages), import `vertexai.preview`: \n |\n | ```python\n | import vertexai.preview\n | ```\n\n \u003cbr /\u003e\n\n3.\n\n If you're using a local shell, then create local authentication credentials for your user\n account:\n\n ```bash\n gcloud auth application-default login\n ```\n\n You don't need to do this if you're using Cloud Shell.\n\n\n If an authentication error is returned, and you are using an external identity provider\n (IdP), confirm that you have\n [signed in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n### Learn about the Vertex AI SDK for Python\n\nSee the following documentation:\n\n- [Vertex AI SDK class overview](/vertex-ai/docs/python-sdk/python-sdk-class-overview): introduces the key classes and functionality in the Vertex AI SDK.\n\n- [Python reference for Vertex AI](/python/docs/reference/aiplatform/latest): contains reference documentation for all of the namespaces, classes, methods, and properties in the `google-cloud-aiplatform` package, which includes the Vertex AI SDK, the Vertex AI SDK preview, and the Vertex AI Client libraries.\n\n### Try code samples and tutorials\n\nNotebook tutorials show how to use the Vertex AI SDK for Python as part of a\nlarger workflow. For more information, see\n[Vertex AI notebook tutorials](/vertex-ai/docs/tutorials/jupyter-notebooks).\n\nCode samples in the Vertex AI SDK for Python GitHub repository show you how to\ncomplete individual tasks. For more information, see the\n[Vertex AI SDK for Python GitHub repository](https://github.com/googleapis/python-aiplatform/). \n| To see an example of using the Vertex AI SDK as part of a more comprehensive workflow,\n| run the \"Custom training and online prediction\" notebook in one of the following\n| environments:\n|\n| [Open in Colab](https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/sdk-custom-image-classification-online.ipynb)\n|\n|\n| \\|\n|\n| [Open in Colab Enterprise](https://console.cloud.google.com/vertex-ai/colab/import/https%3A%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fvertex-ai-samples%2Fmain%2Fnotebooks%2Fofficial%2Fcustom%2Fsdk-custom-image-classification-online.ipynb)\n|\n|\n| \\|\n|\n| [Open\n| in Vertex AI Workbench](https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https%3A%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fvertex-ai-samples%2Fmain%2Fnotebooks%2Fofficial%2Fcustom%2Fsdk-custom-image-classification-online.ipynb)\n|\n|\n| \\|\n|\n| [View on GitHub](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/sdk-custom-image-classification-online.ipynb)\n\nUnderstand the Vertex AI SDK and client library differences\n-----------------------------------------------------------\n\nWhen you install the Vertex AI SDK for Python, the Vertex AI Python client\nlibrary is also installed. The Vertex AI SDK and the\nVertex AI Python client library provide similar functionality with\ndifferent levels of granularity. The Vertex AI SDK operates at a\nhigher level of abstraction than the client library and is suitable for most\ncommon data science workflows. If you need lower-level functionality, then use\nthe Vertex AI Python client library.\n\nThe Vertex AI SDK is available for Python and a Vertex AI client\nlibrary is available for Python, Java, and Node.js. To learn how to install the\nJava or Node.js client library, see\n[Install the Vertex AI client libraries](/vertex-ai/docs/start/client-libraries).\nIf a client library isn't available in your preferred programming language, you\ncan use the Vertex AI REST API. For more information, see the\n[Vertex AI REST reference](/vertex-ai/docs/reference/rest).\n\n### Use Vertex AI Python client library and SDK together\n\nIf you use the Vertex AI SDK for Python and discover you need greater flexibility\nor control, or if you need a method not included in the Vertex AI SDK, you\ncan use the Vertex AI Python client library in the same workflow. The\nVertex AI Python client library uses a different namespace to access the\nVertex AI API. The client library and the Vertex AI SDK for Python\nnamespaces can be used in the same Python script by adding an `import` line for\neach in your Python script.\n\n### Import the Vertex AI Python client library namespace\n\nThe Vertex AI Python client library namespace is\n`google.cloud.aiplatform.gapic`. This namespace maps to the\n`google.cloud.aiplatform_v1` namespace. These two namespaces can be used\ninterchangeably. To import the Python client library, include one of the\nfollowing in your Python script: \n\n```\nfrom google.cloud import aiplatform_v1\n``` \n\n```\nfrom google.cloud.aiplatform import gapic\n```\n\nWhat's next\n-----------\n\n- Learn how to [choose a training method](/vertex-ai/docs/start/training-methods)."]]