Python 2.7 has reached end of support
and will be deprecated
on January 31, 2026. After deprecation, you won't be able to deploy Python 2.7
applications, even if your organization previously used an organization policy to
re-enable deployments of legacy runtimes. Your existing Python
2.7 applications will continue to run and receive traffic after their
deprecation date. We recommend that
you migrate to the latest supported version of Python.
Stay organized with collections
Save and categorize content based on your preferences.
google.appengine.api.lib_config module
Summary
A mechanism for library configuration.
Whenever App Engine library code needs a user-configurable value, it should use
the following protocol:
Pick a prefix unique to the library module, for example: mylib.
Call lib_config.register(prefix, mapping) with that prefix as the first
argument and a dict mapping suffixes to default functions as the second.
The register() function returns a configuration handle that is unique
to this prefix. The configuration handle object has attributes that
correspond to each of the suffixes given in the mapping. Call these
functions to access the user’s configuration value. If the user didn’t
configure a function, the default function from the mapping is called
instead.
Document the function name and its signature and semantics.
Users that want to provide configuration values should create a module named
appengine_config.py in the top-level directory of their application and define
functions as documented by various App Engine library components in that module.
To change the configuration, edit the file and re-deploy the application. When
using the SDK, no redeployment is required; the development server will pick up
the changes the next time it handles a request.
Third party libraries can also use this mechanism. For casual use, calling the
register() method with a unique prefix is acceptable. For more complex
libraries, however, you should instantiate a new LibConfigRegistry instance
that uses a different module name.
Tries to import the configuration module if it is not already imported.
This function always sets self._module to a value that is not None;
either the imported module (if it was imported successfully) or a dummy
object() instance (if an ImportError was raised) is used. Other
exceptions are not caught.
When a dummy instance is used, the instance is also put in sys.modules.
This usage allows us to detect when sys.modules was changed (as
dev_appserver.py does when it notices source code changes) and retries the
import_module in that case, while skipping it (for speed) if nothing has
changed.
If the configuration module has not been imported, no operation occurs, and
the next operation takes place.
class google.appengine.api.lib_config.ConfigHandle(prefix, registry)source
Bases: object
A set of configuration for a single library module or package.
Public attributes of instances of this class are configuration values.
Attributes are dynamically computed (in __getattr__()) and cached as regular
instance attributes.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-16 UTC."],[[["\u003cp\u003eThe \u003ccode\u003elib_config\u003c/code\u003e module provides a mechanism for App Engine libraries to manage user-configurable values through a defined protocol.\u003c/p\u003e\n"],["\u003cp\u003eLibraries use \u003ccode\u003elib_config.register()\u003c/code\u003e to define configuration prefixes and default settings, receiving a \u003ccode\u003eConfigHandle\u003c/code\u003e for accessing these values.\u003c/p\u003e\n"],["\u003cp\u003eUsers can customize library configurations by creating an \u003ccode\u003eappengine_config.py\u003c/code\u003e file, defining functions matching library-specified names and signatures.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eLibConfigRegistry\u003c/code\u003e class manages configuration values and allows for module registration, merging, and resetting of configurations.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eConfigHandle\u003c/code\u003e class represents a set of configurations for a specific library, dynamically retrieving and caching configuration values.\u003c/p\u003e\n"]]],[],null,["# google.appengine.api.lib_config module\n======================================\n\nSummary\n-------\n\nA mechanism for library configuration.\n\nWhenever App Engine library code needs a user-configurable value, it should use\nthe following protocol:\n\n1. Pick a prefix unique to the library module, for example: `mylib`.\n\n2. Call `lib_config.register(prefix, mapping)` with that prefix as the first\n argument and a dict mapping suffixes to default functions as the second.\n\n3. The `register()` function returns a configuration handle that is unique\n to this prefix. The configuration handle object has attributes that\n correspond to each of the suffixes given in the mapping. Call these\n functions to access the user's configuration value. If the user didn't\n configure a function, the default function from the mapping is called\n instead.\n\n4. Document the function name and its signature and semantics.\n\nUsers that want to provide configuration values should create a module named\n`appengine_config.py` in the top-level directory of their application and define\nfunctions as documented by various App Engine library components in that module.\nTo change the configuration, edit the file and re-deploy the application. When\nusing the SDK, no redeployment is required; the development server will pick up\nthe changes the next time it handles a request.\n\nThird party libraries can also use this mechanism. For casual use, calling the\n`register()` method with a unique prefix is acceptable. For more complex\nlibraries, however, you should instantiate a new `LibConfigRegistry` instance\nthat uses a different module name.\n\nExample `appengine_config.py` file: \n\n from somewhere import MyMiddleWareClass\n\n def mylib_add_middleware(app):\n app = MyMiddleWareClass(app)\n return app\n\nExample library use: \n\n from google.appengine.api import lib_config\n\n config_handle = lib_config.register(\n 'mylib',\n {'add_middleware': lambda app: app})\n\n def add_middleware(app):\n return config_handle.add_middleware(app)\n\nContents\n--------\n\n*class* google.appengine.api.lib_config.LibConfigRegistry(modname)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/lib_config#LibConfigRegistry)\n\n: Bases: object\n\n A registry containing library configuration values. \n\n initialize(import_func=import_module)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/lib_config#LibConfigRegistry.initialize)\n\n : Tries to import the configuration module if it is not already imported.\n\n This function always sets `self._module` to a value that is not `None`;\n either the imported module (if it was imported successfully) or a dummy\n `object()` instance (if an `ImportError` was raised) is used. Other\n exceptions are not caught.\n\n When a dummy instance is used, the instance is also put in `sys.modules`.\n This usage allows us to detect when `sys.modules` was changed (as\n `dev_appserver.py` does when it notices source code changes) and retries the\n `import_module` in that case, while skipping it (for speed) if nothing has\n changed.\n Parameters\n\n import_func -- Used for dependency injection. \n\n register(prefix, mapping)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/lib_config#LibConfigRegistry.register)\n\n : Registers a set of configuration names.\n\n Parameters\n\n - prefix -- A shared prefix for the configuration names being registered.\n If the prefix doesn't end in `_`, that character is appended.\n\n - mapping -- A dict that maps suffix strings to default values.\n\n Returns\n\n A `ConfigHandle` instance.\n\n You can re-register the same prefix: the mappings are merged, and for\n duplicate suffixes, the most recent registration is used. \n\n reset()[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/lib_config#LibConfigRegistry.reset)\n\n : Drops the imported configuration module.\n\n If the configuration module has not been imported, no operation occurs, and\nthe next operation takes place. \n\n*class* google.appengine.api.lib_config.ConfigHandle(prefix, registry)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/lib_config#ConfigHandle)\n\n: Bases: object\n\n A set of configuration for a single library module or package.\n\n Public attributes of instances of this class are configuration values.\n Attributes are dynamically computed (in `__getattr__()`) and cached as regular\ninstance attributes. \n\ngoogle.appengine.api.lib_config.register(prefix, mapping)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/lib_config#register)\n\n: Register a set of configurations with the default config module.\n\n Parameters\n\n - prefix -- A shared prefix for the configuration names being registered.\n If the prefix doesn't end in `_`, that character is appended.\n\n - mapping -- A dict mapping suffix strings to default values.\n\n Returns\n\nA `ConfigHandle` instance. \n\ngoogle.appengine.api.lib_config.main()[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/lib_config#main)\n\n: Dumps the configuration, using a CGI-style request handler.\n\n Put this in your `app.yaml` file to enable (you can pick any URL): \n\n - url: /lib_config\n script: $PYTHON_LIB/google/appengine/api/lib_config.py\n\n | **Note:**\n |\n | Unless you are using the SDK, you must be an administrator to use this\n | function."]]