Python 2.7 はサポートが終了しており、2026 年 1 月 31 日に
非推奨になります。非推奨になると、過去に組織のポリシーを使用して以前のランタイムのデプロイを再度有効にしていた場合でも、Python 2.7 アプリケーションをデプロイできなくなります。既存の Python 2.7 アプリケーションは、
非推奨日以降も引き続き実行され、トラフィックを受信します。
サポートされている最新バージョンの Python に移行することをおすすめします。
Cloud Firestore の Datastore モードでの使用
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Firestore は、自動スケーリングと高性能を実現し、アプリケーション開発を簡素化するように構築された NoSQL ドキュメント データベースです。これは Datastore の最新バージョンで、Datastore のいくつかの点が改善されています。
Datastore モードの Firestore は、サーバーのユースケースと App Engine 用に最適化されているため、主に App Engine アプリで使用されるデータベースには Firestore を Datastore モードで使用することをおすすめします。ネイティブ モードの Firestore は、モバイルとリアルタイムの通知のユースケースに最適です。Firestore モードの詳細については、ネイティブ モードと Datastore モードからの選択をご覧ください。
App Engine での Datastore モードの使用
App Engine で Datastore モードを使用するには:
まだ作成していない場合は、データベースを作成し、Datastore モードの Firestore を選択します。
既存の Datastore データベースは、App Engine アプリで使用できます。その場合、既存の Cloud Datastore データベースは Datastore モードの Firestore に自動的にアップグレードされます。
Cloud NDB を使用して、
Datastore モードのデータベースのエンティティを作成、取得、管理します。
Python 2 アプリを Python 3 にアップグレードすることを計画している場合は、次のオプションがあります。
追加リソースの詳細と、App Engine NDB を使用した Python 2 webapp
アプリから、App Engine NDB を有効にした同等の Python 3 Flask アプリへの移行の例については、Python 3 バンドル サービスのページをご覧ください。
インデックスの構成
Datastore モードでは、アプリケーションが作成するすべてのクエリに対してインデックスを使用します。インデックスはエンティティが変更されるたびに更新されるので、アプリからのクエリに対してすばやく結果を返すことができます。
Datastore モードでは、単純な種類のクエリで使用する単一プロパティのインデックスを自動的に作成します。複数のプロパティを含む複雑なクエリについては、アプリの index.yaml
ファイル内に複合インデックスを構成する必要があります。
App Engine 開発用サーバーは、テストを実行するために必要な複合インデックスを使用して index.yaml
ファイルを更新します。同様に、テストを実行する際は Datastore モード エミュレータでインデックスを生成できます。
ローカルテストを実行しない場合や、テストに複雑なクエリが含まれていない場合は、アプリの index.yaml
ファイルに手動でインデックスを追加することもできます。
データベース権限の設定
デフォルトでは、Google Cloud プロジェクト内の Datastore モードと Firestore データベースに対して読み取り / 書き込みを行うために必要なすべての権限がアプリに付与されます。
これらの権限を管理するために、App Engine アプリのそれぞれがデフォルトのサービス アカウントを使用します。デフォルトのサービス アカウントにより、アプリには同じプロジェクト内にある Datastore モードと Firestore データベースに対して読み取りと書き込みを行うための完全アクセス権が与えられます。デフォルトのサービス アカウントの権限を変更することはできますが、必要な権限を IAM ロールに割り当てなければ、アプリがデータベースにアクセスできなくなる可能性があります。
他のユーザー、アプリ、プロジェクトにデータベースへのアクセスを許可する方法については、データベースへのアクセスをご覧ください。
料金、割り当て、制限
Datastore モードでは、一定の割り当て量を無料で使用できます(1 日の使用量に上限があります)。有料アカウントの場合には、保存、読み取り、書き込みオペレーションを無制限で行うことができます。詳細については、データストアの割り当てをご覧ください。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-09-04 UTC。
[[["わかりやすい","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。"],[[["\u003cp\u003eFirestore, a NoSQL document database, is designed for automatic scaling, high performance, and easy application development, representing an evolution from Datastore.\u003c/p\u003e\n"],["\u003cp\u003eFirestore offers two modes: Datastore mode, which is optimized for server use cases and App Engine, and Native mode, which is tailored for mobile and real-time notifications.\u003c/p\u003e\n"],["\u003cp\u003eApp Engine apps can utilize Firestore in Datastore mode, and existing Datastore databases can be automatically upgraded to this mode, facilitating the management of entities using Cloud NDB.\u003c/p\u003e\n"],["\u003cp\u003eDatastore mode employs indexes for every query, automatically creating single-property indexes, while composite indexes for complex queries need manual configuration in the \u003ccode\u003eindex.yaml\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eBy default, App Engine apps possess full read and write permissions to Datastore mode and Firestore databases via a default service account, but these permissions can be modified, requiring an IAM role with specific permissions to maintain access.\u003c/p\u003e\n"]]],[],null,["# Using Cloud Firestore in Datastore Mode\n\nFirestore is a NoSQL document database built for automatic scaling,\nhigh performance, and ease of application development. It is the newest version\nof Datastore and introduces several improvements over\nDatastore.\n\nBecause Firestore in [Datastore mode](/datastore/docs)\nis optimized for server use cases and for\nApp Engine, we recommend using Firestore in\nDatastore mode for databases that will be used primarily by\nApp Engine apps. Firestore in Native mode is most useful for\nmobile and real-time notification use cases. For more information about\nFirestore modes, see [Choosing between Native Mode and\nDatastore mode](/datastore/docs/firestore-or-datastore).\n\nUsing Datastore mode with App Engine\n------------------------------------\n\nTo use Datastore mode with App Engine:\n\n1. If you haven't already done so,\n [create a database](/datastore/docs/store-query-data#create_a_database)\n and choose Firestore in Datastore mode.\n\n You can use existing Datastore databases with App Engine\n apps. These existing databases [will be automatically upgraded to\n Firestore in Datastore\n mode](/datastore/docs/upgrade-to-firestore).\n2. [Use Cloud NDB](/appengine/migration-center/standard/python/migrate-to-cloud-ndb))\n\n to create, retrieve, and manage entities in your Datastore mode\n database.\n\nIf you are planning to upgrade your Python 2 app to Python 3, you have a few options:\n\n- If your Python 2 app uses [App Engine NDB](/appengine/docs/legacy/standard/python/ndb)\n to interact with Datastore, we recommend\n [migrating to Cloud NDB](/appengine/migration-center/standard/python/migrate-to-cloud-ndb)\n instead of the Datastore mode client library as the former\n provides a much more similar user experience.\n\n- You can also choose to port your Python 2 app that uses App Engine\n NDB to Python 3 first and *then* migrate to Cloud NDB. To learn how to access\n App Engine NDB in Python 3, see the [Accessing App Engine bundled\n services for Python 3 page](/appengine/docs/standard/python3/services/access).\n\nFor additional resources plus an example of migrating from a Python 2 `webapp`\napp using App Engine NDB to an equivalent Python 3 Flask app with App Engine NDB\nenabled, see the [bundled services for Python 3\npage](/appengine/docs/standard/python3/services/access#example_app_engine_ndb).\n\nConfiguring indexes\n-------------------\n\nDatastore mode uses\n[indexes](/datastore/docs/concepts/indexes)\nfor every query your application makes. The indexes are updated whenever an\nentity changes, so the results can be returned quickly when the app makes a\nquery.\n\nDatastore mode automatically creates single-property indexes for use with\nsimple types of queries. For complex queries that include multiple properties,\nyou'll need to configure composite indexes in your app's `index.yaml` file.\n\nThe App Engine development server will update your `index.yaml` file\nwith the composite indexes needed to run your tests. Similarly, the\n[Datastore mode emulator can generate indexes](/datastore/docs/tools)\nwhen you run tests.\n\nYou can also add the indexes to your app's\n`index.yaml` file [manually](/appengine/docs/legacy/standard/python/config/indexref#automatic) if you do not run local\ntests or your tests do not include complex queries.\n\nSetting database permissions\n----------------------------\n\nBy default, your app has all the permissions required to read and write to\nDatastore mode and Firestore databases in your\nGoogle Cloud project.\n\nTo manage these permissions, each App Engine app uses a [default service\naccount](/appengine/docs/legacy/standard/python/service-account)\nthat gives full read and write access to Datastore mode\nand Firestore databases in the same project as the app. You can\n[change the permissions of the default service\naccount](/appengine/docs/legacy/standard/python/access-control#modify-service-account),\nbut your app may lose access unless you assign an IAM role with the\n[required permissions](/datastore/docs/access/iam#required_permissions).\n\nFor information about allowing other users, apps, or projects to access a database, see\n[Accessing your database](/datastore/docs/activate).\n\nPricing, quotas, and limits\n---------------------------\n\nDatastore mode offers a free quota with daily limits. Paid\naccounts offer unlimited storage, read, and write operations. More information\nis available on the [Datastore Quotas](/appengine/docs/legacy/standard/python/quotas#Datastore) page."]]