只要使用 Namespaces API,為每個用戶群指定不重複的命名空間字串,即可輕鬆劃分各個用戶群的資料。使用命名空間管理員就能直接為每個用戶群全域設定命名空間 (而不針對特定要求明確進行設定)。啟用命名空間的 API 預設會使用這個目前的命名空間。
Namespaces API 已與 Google Workspace 整合,因此您可以使用 Google Workspace 網域做為目前的命名空間。您可以使用 Google Workspace 將應用程式部署至自己擁有的任何網域,因此可以輕鬆為連結至 Google Workspace 帳戶的所有網域設定專屬命名空間。
[[["容易理解","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\u003eThe Namespaces API in Google App Engine allows for data compartmentalization through a namespace manager, which is incorporated into specific namespace-enabled APIs, primarily for first-generation runtimes.\u003c/p\u003e\n"],["\u003cp\u003eMultitenancy, a software architecture where a single application instance serves multiple client organizations, is a key use case for the Namespaces API, enabling simplified administration, a customized user experience, and better scalability.\u003c/p\u003e\n"],["\u003cp\u003eUsing the Namespaces API, you can partition data across tenants by assigning a unique namespace string to each, which is set globally via the namespace manager and used by namespace-enabled APIs by default.\u003c/p\u003e\n"],["\u003cp\u003eThe Namespaces API integrates with Google Workspace, allowing the use of Google Workspace domains as current namespaces, and the supported APIs with this include Datastore, Memcache, Task Queue, and Search.\u003c/p\u003e\n"],["\u003cp\u003eThe Namespaces API has other uses beyond multitenancy, such as compartmentalizing user information, separating admin and app data, and creating separate data stores for testing and production.\u003c/p\u003e\n"]]],[],null,["# Namespaces API for legacy bundled services\n\nThe Namespaces API in Google App Engine makes it easy to compartmentalize your Google App Engine data. This API is implemented via a new package called the [namespace manager](/appengine/docs/legacy/standard/python/refdocs/google.appengine.api.namespace_manager.namespace_manager), and is incorporated in certain [namespace-enabled APIs](#App_Engine_APIs_that_use_namespaces).\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\nWhen you set a namespace in the namespace manager, these APIs get the current namespace and use it globally. You can explicitly declare a namespace locally, but you need to exercise caution when explicitly declaring namespaces, because you could inadvertently create data leaks and other bugs. Any App Engine request can access any namespace, leaving the application to enforce an access control policy across namespaces.\n\nYou can use the Namespaces API to build a wide range of applications. One of the most compelling uses of this API is for multitenant applications, as described below.\n\nAbout multitenancy\n------------------\n\n*Multitenancy* is the name given to a software architecture in which one instance of an application, running on a remote server, serves many client organizations (also known as *tenants*).\n\nUsing a multitenant architecture simplifies administration and provisioning of tenants. You can provide a more streamlined, customized user experience, and also aggregate different silos of data under a single database schema. As a result, your applications become more scalable as well as more cost-effective as you scale. Data becomes easier to segregate and analyze across tenants because all tenants share the same database schema. Different user groups see custom content wrapped within a more efficient application.\n\nBuilding a multitenant application with the Namespaces API\n----------------------------------------------------------\n\nUsing the Namespaces API, you can easily partition data across tenants simply by specifying a unique namespace string for each tenant. You simply [set the namespace](/appengine/docs/legacy/standard/python/multitenancy/multitenancy#Setting_the_current_namespace) for each tenant globally using the namespace manager (as opposed to setting it explicitly for a specific request). The [namespace-enabled APIs](#App_Engine_APIs_that_use_namespaces) always use this current namespace by default.\n\nThe Namespaces API is integrated with Google Workspace, allowing you to use your Google Workspace domain as the current namespace. Because Google Workspace lets you deploy your app to any domain that you own, you can easily [set unique namespaces](/appengine/docs/legacy/standard/python/multitenancy/multitenancy#Setting_the_current_namespace) for all domains linked to your Google Workspace account.\n\nWhen designing multitenant applications, you need to prevent data from leaking across namespaces. For more information, please see [Avoiding Data Leaks](/appengine/docs/legacy/standard/python/multitenancy/multitenancy#Avoiding_data_leaks).\n\nApp Engine APIs that use namespaces\n-----------------------------------\n\nApp Engine currently supports namespaces in the following APIs:\n\n- [Datastore](/appengine/docs/legacy/standard/python/multitenancy/multitenancy#Using_namespaces_with_the_Datastore)\n- [Memcache](/appengine/docs/legacy/standard/python/multitenancy/multitenancy#Using_namespaces_with_the_Memcache)\n- [Task Queue](/appengine/docs/legacy/standard/python/multitenancy/multitenancy#Using_namespaces_with_the_Task_Queue)\n- [Search](/appengine/docs/legacy/standard/python/multitenancy/multitenancy#Using_namespaces_with_Search)\n\nSample projects using namespaces\n--------------------------------\n\nTwo sample guestbook applications using namespaces are provided:\n\n- Python App Engine: [appengine-multitenancy](https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/standard/multitenancy) -- A namespace-aware sample guestbook application.\n- Java App Engine: [appengine-gwtguestbook-namespaces-java](https://github.com/GoogleCloudPlatform/appengine-gwtguestbook-namespaces-java) -- A namespace-aware sample guestbook application using GWT.\n\nOther uses for the Namespace API\n--------------------------------\n\nWhile the Namespaces API enables multitenancy on App Engine, it has a number of other uses, including:\n\n- Compartmentalizing user information\n- Separating admin data from application data\n- Creating separate datastore instances for testing and production\n- Running multiple apps on a single App Engine instance"]]