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_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__
鍵。
引數
-
命名空間
-
要求傳回其金鑰的命名空間。
-
key_to_namespace(key)
-
傳回特定 __namespace__
金鑰指定的命名空間。
引數
-
key
-
要求傳回其名稱的金鑰。
Kind 類別
Kind
類別代表特殊種類 __kind__
的中繼資料實體,以
種類查詢結果傳回。實體金鑰為實體種類名稱。
屬性
Kind
類別的執行個體具有下列屬性:
-
kind_name
-
傳回此實體金鑰指定的種類名稱。
類別方法
Kind
類別具有下列類別方法:
-
key_for_kind(kind)
-
傳回指定類型的 __kind__
鍵。
引數
-
kind
-
金鑰受到要求的種類。
-
key_to_kind(key)
-
傳回特定 __kind__
鍵指定的類型。
引數
-
key
-
種類受到要求的金鑰。
Property 類別
Property
類別代表特殊種類 __property__
的中繼資料實體,以
屬性查詢結果傳回。代表「K」種類的「P」屬性實體建構方式如下:
- 實體的索引鍵具有種類
__property__
及索引鍵名稱「P」。
- 父系實體的金鑰具有種類
__kind__
及金鑰名稱「K」。
屬性
Property
類別的例項具有下列屬性:
-
kind_name
-
傳回此實體金鑰指定的種類名稱。
-
property_name
-
傳回此實體金鑰指定的屬性名稱。
類別方法
Property
類別具有下列類別方法:
-
key_for_kind(kind)
-
傳回指定類型的 __property__
鍵的父項鍵。
引數
-
kind
-
父項金鑰受到要求的種類。
-
key_for_property(kind, property)
-
傳回指定屬性和類別的 __property__
金鑰。
引數
-
kind
-
金鑰受到要求的種類。
-
property
-
金鑰受到要求的屬性。
-
key_to_kind(key)
-
傳回特定 __property__
鍵指定的類型。
引數
-
key
-
要求傳回其類型名稱的金鑰。
-
key_to_property(key)
-
傳回特定 __property__
金鑰指定的屬性,若金鑰僅由單一種類指定,則傳回 None
。
引數
-
鍵
-
要求傳回其屬性名稱的金鑰。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-09-04 (世界標準時間)。
[[["容易理解","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 (世界標準時間)。"],[[["\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."]]