Python 2.7은 지원이 종료되었으며 2026년 1월 31일에 지원 중단됩니다. 지원 중단 후에는 조직에서 이전에 조직 정책을 사용하여 레거시 런타임의 배포를 다시 사용 설정한 경우에도 Python 2.7 애플리케이션을 배포할 수 없습니다. 기존 Python 2.7 애플리케이션은 지원 중단 날짜 이후에도 계속 실행되고 트래픽을 수신합니다. 지원되는 최신 Python 버전으로 마이그레이션하는 것이 좋습니다.
몇 가지 도구와 API를 사용하여 애플리케이션의 저장된 데이터를 보다 쉽게 관리할 수 있습니다.
Google Cloud 콘솔
Google Cloud console콘솔을 사용할 경우 NDB는 Datastore 및 memcache를 통해 구현된다는 점을 기억해야 합니다. NDB는 값을 '읽을' 때 먼저 Memcache를 확인합니다. Memcache에서 값을 찾을 수 없는 경우에만 Datastore에서 읽습니다.
따라서 Google Cloud 콘솔을 사용하여 Datastore의 항목을 편집할 경우 값이 Memcache에 있으면 애플리케이션은 여전히 '이전' 값을 사용할 가능성이 있습니다. memcache를 삭제하면 이 문제를 해결할 수 있습니다. 하지만 이 방법은 다소 부정적인 영향이 있습니다. 종종 '수동으로' 값을 수정해야 하는 경우 이를 위해 애플리케이션에 NDB 클라이언트 라이브러리를 통해 값을 쓰는 UI를 설정할 수 있습니다. NDB를 통해 값을 쓸 경우에는 Cloud Datastore와 memcache가 동기화 상태로 유지됩니다.
메타데이터 쿼리
NDB는 메타데이터 쿼리 API를 지원합니다. 이 API를 사용하면 애플리케이션이 Datastore 사용에 대한 일반적인 정보를 얻을 수 있습니다. 이 API는 google.appengine.ext.ndb.metadata 모듈에 있습니다. 이 API의 함수는 다음과 같습니다.
get_namespaces(start=None, end=None): 네임 스페이스 이름 목록을 반환합니다.
get_kinds(start=None, end=None): 종류 이름 목록을 반환합니다.
get_properties_of_kind(kind, start=None,
end=None): 지정된 종류 이름의 속성 이름 목록을 반환합니다.
get_representations_of_kind(kind, start=None,
end=None): 지정된 종류 이름의 속성 이름을 'STRING', 'BOOLEAN' 또는 'INT64'와 같은 표현 이름 목록에 매핑하는 사전을 반환합니다.
이러한 함수에는 쿼리를 특정 범위로 제한하는 데 사용할 수 있는 선택적 인수 start와 end가 있습니다. start는 지정된 값을 포함하며 end는 지정된 값을 제외합니다. 둘 다 기본값은 None입니다. 예를 들어 소문자로 시작하는 모든 네임스페이스를 가져오려면 get_namespaces('a', chr(ord('z') + 1))를 호출하면 됩니다.
get_namespaces()를 제외한 모든 함수는 암시적으로 현재 네임스페이스로 제한됩니다. 메타데이터 가져오기 및 쿼리는 Datastore 가져오기 및 쿼리와 동일한 방식으로 청구됩니다.
통계 쿼리
Datastore는 지정된 종류의 항목 수 또는 지정된 유형의 속성 값에서 사용된 공간 등 애플리케이션에 저장된 데이터에 대한 통계를 유지관리합니다. Google Cloud 콘솔의 대시보드 페이지에서 이러한 통계를 볼 수 있습니다.
또한 Datastore API를 사용하여 항목의 특정 이름을 쿼리하면 애플리케이션 내부에서 프로그래매틱 방식으로 이러한 값에 액세스할 수도 있습니다.
각 통계는 종류 이름이 밑줄 2개로 시작하고 끝나는 형식의 항목으로 액세스할 수 있습니다. 예를 들어 각 앱에는 Datastore의 모든 항목 총계에 대한 통계를 나타내는 __Stat_Total__ 종류 항목이 정확히 한 개 있습니다. 각 통계 항목에는 다음과 같은 속성이 있습니다.
count: 통계에서 인식된 항목 수(긴 정수)
bytes: 이 통계 항목의 총 크기(긴 정수)
timestamp: 통계가 최근 업데이트된 시간(날짜-시간 값)
일부 통계 종류에는 아래에 나열된 추가 속성도 포함됩니다.
애플리케이션은 google.appengine.ext.ndb.stats 패키지에서 제공한 모델링 클래스를 사용하여 통계 항목에 액세스할 수 있습니다.
통계 시스템이 새로운 통계 항목을 만들면 기존 통계 항목이 즉시 삭제되지 않습니다. 통계 보기의 일관성을 유지하는 가장 좋은 방법은 최신 timestamp로 GlobalStat 항목을 쿼리한 후 다른 통계 항목을 가져올 때 이 타임스탬프 값을 필터로 사용하는 것입니다.
통계 항목은 계산된 통계 값에 포함됩니다.
통계 항목은 애플리케이션에서 사용되는 고유한 종류와 속성 이름 수만큼 공간을 사용합니다.
통계 시스템은 각 네임스페이스별 통계도 만듭니다. 애플리케이션이 Datastore 네임스페이스를 사용하지 않으면 네임스페이스별 통계가 생성되지 않습니다. 네임스페이스별 통계는 통계가 지정된 네임스페이스에서 확인할 수 있습니다. 네임스페이스별 통계의 종류 이름은 프리픽스 __Stat_Ns_로 시작하고 애플리케이션 전반의 통계 종류에 해당되는 동일한 서픽스로 끝납니다.
수천 개의 네임스페이스, 종류 또는 속성 이름이 포함된 애플리케이션에는 수많은 통계 항목이 필요합니다. 통계 저장 및 업데이트의 오버헤드를 합리적인 수준으로 유지하도록 Datastore는 다음 순서에 따라 통계 항목을 점진적으로 삭제합니다.
• entity_bytes: 바이트 단위로 측정된 항목 테이블의 저장용량 • builtin_index_bytes: 바이트 단위로 측정된 내장 색인 항목의 저장용량 • builtin_index_count: 내장 색인 항목 수 • composite_index_bytes: 바이트 단위로 측정된 복합 색인 항목의 저장용량 • composite_index_count: 복합 색인 항목 수
네임스페이스의 모든 항목
__Stat_Namespace__ Python 클래스: NamespaceStat __Stat_Namespace__ 항목은 각 네임스페이스에 대해 생성되며 비어 있는 문자열 네임스페이스에서만 확인됩니다.
네임스페이스의 모든 항목
• subject_namespace: 나타내는 네임스페이스(문자열) • entity_bytes바이트 단위로 측정된 항목 테이블의 저장용량 • builtin_index_bytes: 바이트 단위로 측정된 내장 색인 항목의 저장용량 • builtin_index_count: 내장 색인 항목 수 • composite_index_bytes: 바이트 단위로 측정된 복합 색인 항목의 저장용량 • composite_index_count: 복합 색인 항목 수
• kind_name, 나타내는 종류 이름(문자열) • entity_bytes: 바이트 단위로 측정된 항목 테이블의 저장용량 • builtin_index_bytes: 바이트 단위로 측정된 내장 색인 항목의 저장용량 • builtin_index_count: 내장 색인 항목 수 • composite_index_bytes: 바이트 단위로 측정된 복합 색인 항목의 저장용량 • composite_index_count: 복합 색인 항목 수
특정 종류 항목 전반에 적용되는 값 유형 속성(값 유형 및 종류 조합당 하나의 통계 항목). 추가 속성:
• property_type, 값 유형 이름(문자열) • kind_name: 나타내는 종류 이름(문자열) • entity_bytes: 바이트 단위로 측정된 항목 테이블의 저장용량 • builtin_index_bytes: 바이트 단위로 측정된 내장 색인의 저장용량 • builtin_index_count: 내장 색인 항목 수
특정 종류의 항목 전반에 이름을 지정하는 속성(고유한 속성 이름 및 종류 조합당 하나의 통계 항목). 추가 속성:
• property_name, 속성 이름(문자열) • kind_name: 나타내는 종류 이름(문자열) • entity_bytes: 바이트 단위로 측정된 항목 테이블의 저장용량 • builtin_index_bytes: 바이트 단위로 측정된 내장 색인 항목의 저장용량 • builtin_index_count: 내장 색인 항목 수
[[["이해하기 쉬움","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\u003eThis API supports first-generation runtimes and can be used when upgrading to corresponding second-generation runtimes, with a migration guide available for the App Engine Python 3 runtime.\u003c/p\u003e\n"],["\u003cp\u003eNDB, utilizing both Datastore and memcache, prioritizes memcache for read operations, so edits made directly in the Google Cloud console may not be immediately reflected in the application unless memcache is purged or changes are written via NDB.\u003c/p\u003e\n"],["\u003cp\u003eThe metadata query API in \u003ccode\u003egoogle.appengine.ext.ndb.metadata\u003c/code\u003e provides functions like \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 to retrieve general information about Datastore usage.\u003c/p\u003e\n"],["\u003cp\u003eDatastore statistics, accessible through the Google Cloud console and programmatically using the \u003ccode\u003egoogle.appengine.ext.ndb.stats\u003c/code\u003e package, offer insights into data storage, entity counts, and space used by property values.\u003c/p\u003e\n"],["\u003cp\u003eDatastore's statistics system progressively drops statistics entities in a specific order, starting with the most granular (per-namespace, per-kind, and per-property) to maintain reasonable storage and update overhead.\u003c/p\u003e\n"]]],[],null,["# NDB Administration\n\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| python3\n|\n| /services/access). If you are updating to the App Engine Python 3 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/python-differences) to learn about your migration options for legacy bundled services.\n\nThere are tools and APIs to make it easier to administer an application's stored\ndata.\n\nGoogle Cloud console\n--------------------\n\nWhen using the [Google Cloud console](https://console.cloud.google.com/), remember that NDB is implemented by\nmeans of Datastore *and* memcache. When NDB \"reads\" a value, it\nchecks memcache first; it only reads from Datastore if it\ndoesn't find the value in memcache.\n\nThus, if you use the Google Cloud console to edit an entity in\nDatastore, the application might still use the \"old\" value if\nthat value is in memcache. You might work around this by purging memcache. This\nis rather disruptive, however; if you need to tweak values \"by hand\" often, you\nmight want to set up a UI for this in your application that writes values via\nthe NDB client library; writing via NDB keeps Datastore and\nmemcache in sync.\n\nMetadata queries\n----------------\n\nNDB supports a metadata query API. This allows an application to get some\ngeneral information about its use of Datastore. This API is in\nthe [`google.appengine.ext.ndb.metadata`](/appengine/docs/legacy/standard/python/ndb/metadata)\nmodule. It has functions:\n\n- `get_namespaces(`\u003cvar translate=\"no\"\u003estart\u003c/var\u003e`=None, `\u003cvar translate=\"no\"\u003eend\u003c/var\u003e`=None)`: return a list of namespace names\n- `get_kinds(`\u003cvar translate=\"no\"\u003estart\u003c/var\u003e`=None, `\u003cvar translate=\"no\"\u003eend\u003c/var\u003e`=None)`: return a list of kind names\n- `get_properties_of_kind(`\u003cvar translate=\"no\"\u003ekind\u003c/var\u003e`, `\u003cvar translate=\"no\"\u003estart\u003c/var\u003e`=None,\n `\u003cvar translate=\"no\"\u003eend\u003c/var\u003e`=None)`: return a list of property names for the given *kind* name\n- `get_representations_of_kind(`\u003cvar translate=\"no\"\u003ekind\u003c/var\u003e`, `\u003cvar translate=\"no\"\u003estart\u003c/var\u003e`=None,\n `\u003cvar translate=\"no\"\u003eend\u003c/var\u003e`=None)`: return a dict mapping property names for the given kind name to lists of representation names such as 'STRING', 'BOOLEAN' or 'INT64'.\n\nThese functions have optional *start* and *end* arguments that can be used to\nrestrict the query to a certain range. Here, *start* is inclusive and *end* is\nexclusive. Both default to `None`. For example, to get all namespaces starting\nwith a lowercase letter you could call `get_namespaces('a', chr(ord('z') + 1))`.\nAll of these except `get_namespaces()` are implicitly restricted to the current\nnamespace. Metadata gets and queries are [billed in the same way as\nDatastore gets and queries](/appengine/docs/pricing).\n\nStatistics queries\n------------------\n\nDatastore maintains statistics about the data stored for an\napplication, such as how many entities there are of a given kind, or how much\nspace is used by property values of a given type. You can view these statistics\nin the Google Cloud console, in the\n[Dashboard](https://console.cloud.google.com/datastore/stats) page.\n\nYou can also access these values programmatically within the application by\nquerying for specially named entities using the Datastore API.\nEach statistic is accessible as an entity whose kind name begins and ends with\ntwo underscores. For example, each app has exactly one entity of the kind\n`__Stat_Total__` that represents statistics about all of the entities in\nDatastore in total. Each statistic entity has the following\nproperties:\n\n- `count`, the number of items considered by the statistic (a long integer)\n- `bytes`, the total size of the items for this statistic (a long integer)\n- `timestamp`, the time of the most recent update to the statistic (a date-time value)\n\nSome statistic kinds also have additional properties, listed below.\n\nAn application can use model classes provided by the package\n`google.appengine.ext.ndb.stats` to access statistic entities. \n\n from google.appengine.ext.ndb import stats\n\n global_stat = stats.GlobalStat.query().get()\n print 'Total bytes stored: %d' % global_stat.bytes\n print 'Total entities stored: %d' % global_stat.count\n\nWhen the statistics system creates new statistic entities, it does not delete\nthe old ones right away. The best way to get a consistent view of the\nstatistics is to query for the\n`GlobalStat`\n\nentity with the most recent\n`timestamp`, then use that timestamp value as a filter when fetching other\nstatistic entities.\n\nThe statistic entities are included in the calculated statistic values.\nStatistic entities take up space relative to the number of unique kinds and\nproperty names used by the application.\n\nThe statistics system will also create statistics specific to each\n[namespace](/appengine/docs/legacy/standard/python/multitenancy)\nNote that if an application does not use Datastore namespaces\nthen namespace specific statistics will not be created. Namespace specific stats\nare found in the namespace that they're specific to. The kind names for\nnamespace specific stats are prefixed with `__Stat_Ns_` and have the same\ncorresponding suffix as application wide statistics kinds.\n\nApplications with thousands of namespaces, kinds, or property names require a\nvery large number of statistics entities. To keep the overhead of storing and\nupdating the statistics reasonable, Datastore progressively\ndrops statistics entities, in the following order:\n\n- per-namespace, per-kind, and per-property statistics: `__Stat_Ns_PropertyName_Kind__`, `__Stat_Ns_PropertyType_PropertyName_Kind__`\n- per-kind and per-property statistics: `__Stat_PropertyName_Kind__`, `__Stat_PropertyType_PropertyName_Kind__`\n- per-namespace and per-kind statistics: `__Stat_Ns_Kind__`, `__Stat_Ns_Kind_IsRootEntity__`, `__Stat_Ns_Kind_NotRootEntity__`, `__Stat_Ns_PropertyType_Kind__`\n- per-kind statistics: `__Stat_Kind__`, `__Stat_Kind_IsRootEntity__`, `__Stat_Kind_NotRootEntity__`, `__Stat_PropertyType_Kind__`\n- per-namespace statistics: `__Stat_Namespace__`, `__Stat_Ns_Kind_CompositeIndex__`, `__Stat_Ns_PropertyType__`, `__Stat_Ns_Total__`\n\nThe summary statistics entities (`__Stat_Kind_CompositeIndex__`,\n`__Stat_PropertyType__`, `__Stat_Total__`) are never dropped.\n\nThe complete list of available statistics is as follows:\n\nSome statistics refer to Datastore property value types by\nname, as strings. These names are as follows:\n\n- `\"Blob\"`\n- `\"BlobKey\"`\n- `\"Boolean\"`\n- `\"Category\"`\n- `\"Date/Time\"`\n- `\"Email\"`\n- `\"Float\"`\n- `\"GeoPt\"`\n- `\"IM\"`\n- `\"Integer\"`\n- `\"Key\"`\n- `\"Link\"`\n- `\"NULL\"`\n- `\"PhoneNumber\"`\n- `\"PostalAddress\"`\n- `\"Rating\"`\n- `\"ShortBlob\"`\n- `\"String\"`\n- `\"Text\"`\n- `\"User\"`\n\n| **Note:** `__Stat_Namespace__` entities contain the same information found in `__Stat_Ns_Total__` records. `__Stat_Namespace__` entities are stored in the empty namespace and contain a `subject_namespace` field describing the namespace to which they belong. `__Stat_Ns_Total__` records are stored in the namespace to which they refer, and thus do not contain a `subject_namespace` field. Hence, a query on kind `__Stat_Namespace__` (from the empty string namespace) ordered descending by `bytes` will list the namespaces that consume the largest storage first. Because queries across namespaces are not possible, any query for `__Stat_Ns_Total__` entities will only ever produce at most a single record."]]