A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cloud.google.com/appengine/docs/legacy/standard/python/tools/appengineconfig below:

Python 2 Module Configuration | App Engine standard environment for Python 2

Python 2 Module Configuration

Stay organized with collections Save and categorize content based on your preferences.

The appengine_config.py file is a configuration file that provides you the ability to specify the installation folder for libraries and provide your own values for constants and "hook functions" for some of the Python modules in the google.appengine packages. Specifying your own values can change the default behavior of the related App Engine services based on the application's needs. You define this file alongside your app.yaml configuration file and deploy it with the rest of your app's code.

Configuring Python modules with appengine_config.py

Several Python modules in App Engine are configurable using appengine_config.py.

To customize the Python modules of your services, you create a new appengine_config.py file in the root directory of that service. To use this file, you need to define only those constants or hook functions you wish to override. You then run gcloud app deploy from the directory where the app.yaml file is located to redeploy your app along with the new appengine_config.py file. The constants and hook functions that you defined will then be used by those App Engine services internally.

To override a constant, prefix the constant's name with the Python module name and an underscore, then assign a value. For example, to edit overrides in appstats, you can define the value of KEY_PREFIX

appstats_KEY_PREFIX = '__my_custom_prefix__'

Naming of overridden hook functions is similar in other Python modules. For example, in namespace_manager, you can override the hook function default_namespace_for_request in appengine_config.py as follows:

import os
def namespace_manager_default_namespace_for_request():
    return os.environ.get('HTTP_HOST', '')
Configurable Python modules in App Engine

The Python modules listed below are configurable using appengine_config.py. By convention, hook functions are lowercase and constants are uppercase:

namespace_manager appstats datastore_admin remoteapi Configuring your own Python modules with lib_config

App Engine also allows you to configure your own Python modules with constants and hook functions defined in appengine_config.py. The lib_config.register() function allows you to both register the names of the user-overridable constants and hooks, and to define sensible defaults in case the users don't wish to override them. Internally, lib_config.register() attempts to import appengine_config. If successful, it replaces the defaults of the specified Python modules with those defined in appengine_config.py.

Example usage in my_module.py:

from google.appengine.api import lib_config

def _hook_function1_default():
   return 'baz'

_config = lib_config.register('my_module', {'CONSTANT1': 'foo',
                                            'CONSTANT2': 'bar',
                                            'hook_function1': _hook_function1_default})

Now you can access a user's constants as:

_config.CONSTANT1
_config.CONSTANT2

and call their hook function as:

_config.hook_function1()

Some programmers like to group their defaults into a class:

class _ConfigDefaults(object):
  CONSTANT1 = 'foo'
  CONSTANT2 = 'bar'
  def hook_function1():
      return 'baz'

_config = lib_config.register('my_module',  _ConfigDefaults.__dict__)

In order to override your defaults, a user could define in appengine_config.py:

my_module_CONSTANT1 = 'foofoo'
my_module_hook_function1 = lambda: 'bazbaz'

As a result, in my_module.py, the following will be true:

The user overrides are available to my_module.py immediately after lib_config.register() returns.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-07 UTC.

[[["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-08-07 UTC."],[[["The `appengine_config.py` file allows customization of App Engine services by defining constants and hook functions, which override default behaviors."],["You can configure specific Python modules, such as `namespace_manager`, `appstats`, `datastore_admin`, and `remoteapi`, by creating an `appengine_config.py` file in your service's root directory."],["Overriding constants and hook functions involves prefixing their names with the Python module name and an underscore within the `appengine_config.py` file."],["The `lib_config.register()` function enables developers to make their own Python modules configurable, allowing users to override default constants and hook functions through `appengine_config.py`."],["Changes made in `appengine_config.py` are applied after deploying the application with `gcloud app deploy`, ensuring that the customized settings are utilized by the App Engine services."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4