Python 2.7 はサポートが終了しており、2026 年 1 月 31 日に
非推奨になります。非推奨になると、過去に組織のポリシーを使用して以前のランタイムのデプロイを再度有効にしていた場合でも、Python 2.7 アプリケーションをデプロイできなくなります。既存の Python 2.7 アプリケーションは、
非推奨日以降も引き続き実行され、トラフィックを受信します。
サポートされている最新バージョンの Python に移行することをおすすめします。
メタデータ エンティティ Python リファレンス
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
注: 新しいアプリケーションを作成する際は、NDB クライアント ライブラリを使用することを強くおすすめします。NDB クライアント ライブラリには、Memcache API によるエンティティの自動キャッシュをはじめ、このクライアント ライブラリにはないメリットがあります。古い DB クライアント ライブラリを現在使用している場合は、DB から NDB への移行ガイドをお読みください。
モデルクラス EntityGroup
、Namespace
、Kind
、Property
は、メタデータの種類の取得またはクエリを実行した結果を表します。上記のクラスはすべて、google.appengine.ext.db.metadata
パッケージで定義されています。これらのクラスの詳細と使用例については、メタデータをご覧ください。
ヘルパー関数
明示的にクエリまたは get を発行しなくても、次のヘルパー関数を使用してメタデータ情報を取得できます。
-
get_entity_group_version(entity_or_key)
-
entity_or_key
を含むエンティティ グループのバージョンを返します。このバージョンは、エンティティ グループに変更が加えられるたびに増分することが保証されています。ユーザーが認識できる変更がエンティティ グループに加えられていない場合でも、バージョンが増分することがあります。エンティティ グループの書き込みが一度も行われたことがなければ、None
が返されます。
警告: 現在のエンティティ グループのメタデータの動作は以前と異なります。エンティティ グループのバージョンは、ユーザーによる更新とは別に増加させることができます。以前は、エンティティ グループのバージョンはユーザーによる更新時にのみ増加しました。従来の動作を維持するには、エンティティ グループのバージョンの回避策を使用します。
引数:
- entity_or_key
- バージョンを取得するキーまたはエンティティ。
-
get_namespaces(start=None, end=None)
-
名前空間名のリストを返します。
引数
-
start
-
None
でない場合、指定された値以上の名前空間名のみを返します。
-
end
-
None
でない場合は、指定された値より小さい名前空間名のみを返します。
-
get_kinds(start=None, end=None)
-
エンティティの種類名のリストを返します。
引数
-
start
-
None
でない場合は、指定された値以上の種類名のみを返します。
-
end
-
None
でない場合は、指定された値より小さい種類名のみを返します。
-
get_properties_of_kind(kind, start=None, end=None)
-
指定された種類のインデックスありのプロパティ名のリストを返します。インデックスなしのプロパティは含まれません。
引数
-
kind
-
プロパティ名を要求する種類。
-
start
-
None
でない場合は、指定された値以上のプロパティ名のみを返します。
-
end
-
None
でない場合は、指定された値より小さいプロパティ名のみを返します。
-
get_representations_of_kind(kind, start=None, end=None)
-
指定された種類のインデックスありの各プロパティ名とその表現のリストをマッピングするディクショナリを返します。インデックスなしのプロパティは含まれません。
引数
-
kind
-
プロパティの表現を要求する種類。
-
start
-
None
でない場合は、指定された値以上の名前を持つプロパティの表現のみを返します。
-
end
-
None
でない場合は、指定された値より小さい名前を持つプロパティの表現のみを返します。
EntityGroup クラス
__entity_group__
メタデータのモデル(HR データストアでのみ使用可能)。
このメタデータには、数値の __version__
プロパティが含まれます。これは、エンティティ グループに変更が加えられるたびに増分することが保証されています。ユーザーが認識できる変更がエンティティ グループに加えられていない場合でも、バージョンが増分することがあります。エンティティ グループが一度も書き込まれていない場合は、__entity_group__
エンティティは存在しません。
プロパティ
- version
- バージョン番号
クラスメソッド
- key_for_entity(entity_or_key)
entity_or_key
が含まれているエンティティ グループのメタデータキーを返します。このキーを引数として get()
に渡すと、entity_or_key が含まれているエンティティ グループの __entity_group__
メタデータ エンティティを取得できます。引数:
- entity_or_key
__entity_group__
キーを取得するキーまたはエンティティ。
Namespace クラス
Namespace
クラスは、名前空間クエリの結果として返される __namespace__
という特殊な種類のメタデータ エンティティを表します。このエンティティのキーは、名前空間の名前です(空の文字列 ""
で示されるデフォルトの名前空間は例外です。空の文字列は有効なキー名ではないため、デフォルトの名前空間は数値 ID 1
が設定されたキーで表されます)。
プロパティ
Namespace
クラスのインスタンスには次のメソッドがあります。
-
namespace_name
-
このエンティティのキーが指す名前空間の名前を返します。
クラスメソッド
Namespace
クラスには次のクラスメソッドがあります。
-
key_for_namespace(namespace)
-
指定された名前空間の __namespace__
キーを返します。
引数
-
namespace
-
キーを要求する名前空間。
-
key_to_namespace(key)
-
指定した __namespace__
キーが指す名前空間を返します。
引数
-
キー
-
名前空間を要求するキー。
Kind クラス
Kind
クラスは、種類のクエリの結果として返される __kind__
という特殊な種類のメタデータ エンティティを表します。このエンティティのキーは、エンティティの種類の名前です。
プロパティ
Kind
クラスのインスタンスには次のメソッドがあります。
-
kind_name
-
このエンティティのキーが指す種類の名前を返します。
クラスメソッド
Kind
クラスには次のクラスメソッドがあります。
-
key_for_kind(kind)
-
指定された種類の __kind__
キーを返します。
引数
-
kind
-
キーを要求する種類。
-
key_to_kind(key)
-
指定された __kind__
キーが指す種類を返します。
引数
-
キー
-
種類を要求するキー。
Property クラス
Property
クラスは、プロパティ クエリの結果として返される __property__
という特殊な種類のメタデータ エンティティを表します。プロパティが P、種類が K で表現されるエンティティは次のように構築されます。
- エンティティのキーの種類は
__property__
で、キー名は P です。
- 親エンティティのキーの種類は
__kind__
で、キー名は K です。
プロパティ
Property
クラスのインスタンスには次のメソッドがあります。
-
kind_name
-
このエンティティのキーが指す種類の名前を返します。
-
property_name
-
このエンティティのキーが指す種類の名前を返します。
クラスメソッド
Property
クラスには次のクラスメソッドがあります。
-
key_for_kind(kind)
-
指定された種類の __property__
キーの親キーを返します。
引数
-
kind
-
親キーを要求する種類。
-
key_for_property(kind, property)
-
指定されたプロパティと種類の __property__
キーを返します。
引数
-
kind
-
キーを要求する種類。
-
プロパティ
-
キーを要求するプロパティ。
-
key_to_kind(key)
-
指定された __property__
キーが指す種類を返します。
引数
-
キー
-
種類の名前を要求するキー。
-
key_to_property(key)
-
指定された __property__
キーが指すプロパティを返します。キーが種類だけを指している場合は None
を返します。
引数
-
キー
-
プロパティの名前を要求するキー。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 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\u003eDevelopers should use the NDB Client Library for new applications due to its advantages, such as automatic entity caching, over the older DB Client Library.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egoogle.appengine.ext.db.metadata\u003c/code\u003e package contains model classes like EntityGroup, Namespace, Kind, and Property, which represent the results of metadata queries.\u003c/p\u003e\n"],["\u003cp\u003eHelper functions are available to get metadata without explicit queries, including \u003ccode\u003eget_entity_group_version\u003c/code\u003e, \u003ccode\u003eget_namespaces\u003c/code\u003e, \u003ccode\u003eget_kinds\u003c/code\u003e, \u003ccode\u003eget_properties_of_kind\u003c/code\u003e, and \u003ccode\u003eget_representations_of_kind\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eget_entity_group_version\u003c/code\u003e function returns the version of an entity group, which now may increase even without user updates, a change from its previous behavior.\u003c/p\u003e\n"],["\u003cp\u003eFunctions such as \u003ccode\u003eget_namespaces\u003c/code\u003e, \u003ccode\u003eget_kinds\u003c/code\u003e, \u003ccode\u003eget_properties_of_kind\u003c/code\u003e, and \u003ccode\u003eget_representations_of_kind\u003c/code\u003e allow to filter their results based on start and end values provided.\u003c/p\u003e\n"]]],[],null,["# Metadata Entities Python Reference\n\n**Note:**\nDevelopers building new applications are **strongly encouraged** to use the\n[NDB Client Library](/appengine/docs/legacy/standard/python/ndb), which has several benefits\ncompared to this client library, such as automatic entity caching via the Memcache\nAPI. If you are currently using the older DB Client Library, read the\n[DB to NDB Migration Guide](/appengine/docs/legacy/standard/python/ndb/db_to_ndb)\n\nThe model classes\n[EntityGroup](#EntityGroup),\n[Namespace](#The_Namespace_Class),\n[Kind](#The_Kind_Class),\nand\n[Property](#The_Property_Class)\nrepresent the results of getting or querying metadata kinds.\nThese classes are all defined in the package\n`google.appengine.ext.db.metadata`. See the page\n[Metadata](/appengine/docs/legacy/standard/python/datastore/metadataqueries)\nfor more information and examples of their use.\n\nHelper Functions\n----------------\n\nThe following helper functions are available for obtaining metadata\ninformation without issuing an explicit query or get:\n\n\nget_entity_group_version(entity_or_key)\n\n: Returns the version of the entity group containing\n `entity_or_key`. This\n version is guaranteed to increase on every change to the entity\n group. The version may increase even in the absence of user-visible\n changes to the entity group.\n May return `None` if the entity group was\n never written to.\n\n **Warning** : The behavior of entity group metadata is now different. The entity\n group version can increase independently of user updates. Previously, the entity\n group version increased only on user update. To maintain legacy behavior, use the\n [entity group version workaround](https://support.google.com/cloud/answer/9133787#zippy=python-db).\n\n **Arguments:**\n\n entity_or_key\n : a key or entity whose version you want.\n\n\nget_namespaces(start=None, end=None)\n\n: Returns a list of namespace names.\n\n Arguments\n\n\n start\n\n : If not `None`, return only namespace names greater than or equal to the specified value.\n\n\n end\n\n : If not `None`, return only namespace names less than the specified value.\n\n\nget_kinds(start=None, end=None)\n\n: Returns a list of entity kind names.\n\n Arguments\n\n\n start\n\n : If not `None`, return only kind names greater than or equal to the specified value.\n\n\n end\n\n : If not `None`, return only kind names less than the specified value.\n\n\nget_properties_of_kind(kind, start=None, end=None)\n\n: Returns a list of indexed property names for a specified kind. Unindexed properties are not included.\n\n Arguments\n\n\n kind\n\n : The kind whose property names are requested.\n\n\n start\n\n : If not `None`, return only property names greater than or equal to the specified value.\n\n\n end\n\n : If not `None`, return only property names less than the specified value.\n\n\nget_representations_of_kind(kind, start=None, end=None)\n\n: Returns a dictionary mapping each indexed property name for a specified kind to a list of its representations. Unindexed properties are not included.\n\n Arguments\n\n\n kind\n\n : The kind whose property representations are requested.\n\n\n start\n\n : If not `None`, return only representations for properties whose names are greater than or equal to the specified value.\n\n\n end\n\n : If not `None`, return only representations for properties whose names are less than the specified value."]]