Python 2.7은 지원이 종료되었으며 2026년 1월 31일에
지원 중단됩니다. 지원 중단 후에는 조직에서 이전에 조직 정책을 사용하여 레거시 런타임의 배포를 다시 사용 설정한 경우에도 Python 2.7 애플리케이션을 배포할 수 없습니다. 기존 Python 2.7 애플리케이션은
지원 중단 날짜 이후에도 계속 실행되고 트래픽을 수신합니다.
지원되는 최신 Python 버전으로 마이그레이션하는 것이 좋습니다.
Python 2 모듈 구성
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
appengine_config.py
파일은 구성 파일이며, 여기에 라이브러리용 설치 폴더를 지정하고 google.appengine 패키지에 있는 일부 Python 모듈의 상수 및 '후크 함수' 값을 원하는 대로 제공할 수 있습니다.
고유한 값을 지정하면 애플리케이션의 요구에 따라 관련 App Engine 서비스의 기본 동작이 변경될 수 있습니다. 이 파일을 app.yaml
구성 파일과 함께 정의하고 나머지 앱 코드와 함께 배포합니다.
appengine_config.py로 Python 모듈 구성
appengine_config.py
를 사용하면 App Engine의 Python 모듈을 여러 개 구성할 수 있습니다.
서비스의 Python 모듈을 맞춤설정하려면 새 appengine_config.py
파일을 서비스의 루트 디렉터리에 만듭니다. 이 파일을 사용하려면 재정의하려는 상수나 후크 함수만 정의해야 합니다. 그런 다음 app.yaml
파일이 있는 디렉터리에서 gcloud app
deploy
를 실행하여 새 appengine_config.py
파일과 함께 앱을 다시 배포합니다. 그러면 정의한 상수와 후크 함수가 해당 App Engine 서비스에서 내부적으로 사용됩니다.
상수를 재정의하려면 상수 이름 앞에 Python 모듈 이름과 밑줄을 붙이고 값을 할당합니다. 예를 들어 KEY_PREFIX
의 값을 정의하여 appstats에서 재정의를 편집할 수 있습니다.
appstats_KEY_PREFIX = '__my_custom_prefix__'
재정의된 후크 함수의 명명 방식은 다른 Python 모듈에서도 비슷합니다. 예를 들어
namespace_manager에서 다음과 같이 appengine_config.py
의 후크 함수 default_namespace_for_request
를 재정의할 수 있습니다.
import os
def namespace_manager_default_namespace_for_request():
return os.environ.get('HTTP_HOST', '')
App Engine에서 구성 가능한 Python 모듈
appengine_config.py
를 사용하여 아래에 나와 있는 Python 모듈을 구성할 수 있습니다. 규칙에 따라 후크 함수는 소문자이고 상수는 대문자입니다.
namespace_manager
-
default_namespace_for_request()
(기본값은 None
반환)
appstats
datastore_admin
BASE_PATH
(기본값 '/_ah/datastore_admin'
)
MAPREDUCE_PATH
(기본값 '/_ah/mapreduce'
)
CLEANUP_MAPREDUCE_STATE
(기본값 True
)
remoteapi
lib_config로 고유한 Python 모듈 구성
또한 App Engine에서는 appengine_config.py
에서 정의된 상수와 후크 함수로 고유한 Python 모듈을 구성할 수 있습니다. lib_config.register()
함수를 사용하면 사용자가 재정의할 수 있는 상수와 후크의 이름을 모두 등록하고 사용자가 재정의하지 않으려는 경우 적절한 기본값을 정의할 수 있습니다. 내부적으로 lib_config.register()
는 appengine_config
를 가져오려고 시도합니다. 가져오기에 성공하면 지정한 Python 모듈의 기본값이 appengine_config.py
에서 정의된 모듈로 바뀝니다.
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})
이제 다음과 같이 사용자 상수에 액세스할 수 있습니다.
_config.CONSTANT1
_config.CONSTANT2
그리고 다음과 같이 후크 함수를 호출할 수 있습니다.
_config.hook_function1()
일부 프로그래머는 기본값을 클래스에서 그룹화하려 합니다.
class _ConfigDefaults(object):
CONSTANT1 = 'foo'
CONSTANT2 = 'bar'
def hook_function1():
return 'baz'
_config = lib_config.register('my_module', _ConfigDefaults.__dict__)
기본값을 재정의하기 위해 사용자는 appengine_config.py
에서 정의할 수 있습니다.
my_module_CONSTANT1 = 'foofoo'
my_module_hook_function1 = lambda: 'bazbaz'
따라서 my_module.py
에서는 다음 사항이 적용됩니다.
_config.CONSTANT1
에서 'foofoo'
으로 변경됨
_config.CONSTANT2
는 'bar'
로 남아 있음
_config.hook_function1()
은 'bazbaz'
를 반환함
lib_config.register()
반환 직후 사용자 재정의를 my_module.py
에서 사용할 수 있습니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-09-04(UTC)
[[["이해하기 쉬움","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\u003eThe \u003ccode\u003eappengine_config.py\u003c/code\u003e file allows customization of App Engine services by defining constants and hook functions, which override default behaviors.\u003c/p\u003e\n"],["\u003cp\u003eYou can configure specific Python modules, such as \u003ccode\u003enamespace_manager\u003c/code\u003e, \u003ccode\u003eappstats\u003c/code\u003e, \u003ccode\u003edatastore_admin\u003c/code\u003e, and \u003ccode\u003eremoteapi\u003c/code\u003e, by creating an \u003ccode\u003eappengine_config.py\u003c/code\u003e file in your service's root directory.\u003c/p\u003e\n"],["\u003cp\u003eOverriding constants and hook functions involves prefixing their names with the Python module name and an underscore within the \u003ccode\u003eappengine_config.py\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003elib_config.register()\u003c/code\u003e function enables developers to make their own Python modules configurable, allowing users to override default constants and hook functions through \u003ccode\u003eappengine_config.py\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eChanges made in \u003ccode\u003eappengine_config.py\u003c/code\u003e are applied after deploying the application with \u003ccode\u003egcloud app deploy\u003c/code\u003e, ensuring that the customized settings are utilized by the App Engine services.\u003c/p\u003e\n"]]],[],null,["# Python 2 Module Configuration\n\nThe `appengine_config.py` file is a configuration file that provides you the\nability to specify the [installation folder for libraries](/appengine/docs/legacy/standard/python/tools/using-libraries-python-27#copying_a_third-party_library) and provide your own values for constants and\n\"hook functions\" for some of the Python modules in the [google.appengine](/appengine/docs/legacy/standard/python/refdocs/google.appengine) packages.\nSpecifying your own values can change the default behavior of the\nrelated App Engine services based on the application's needs. You define this file alongside your\n[`app.yaml` configuration\nfile](/appengine/docs/legacy/standard/python/config/appref) and deploy it with the rest of your app's code.\n\nConfiguring Python modules with appengine_config.py\n---------------------------------------------------\n\n\nSeveral [Python modules in\nApp Engine](#Configurable_Python_Modules_In_App_Engine) are configurable using `appengine_config.py`.\n\n\nTo customize the Python modules of your [services](/appengine/docs/legacy/standard/python/an-overview-of-app-engine),\nyou create a new `appengine_config.py` file in the root directory\nof that service. To use this file, you need to define only those constants or\nhook functions you wish to override. You then run `gcloud app\ndeploy` from the directory where the `app.yaml` file is\nlocated to redeploy your app along with the new\n`appengine_config.py` file. The constants and hook functions that\nyou defined will then be used by those App Engine services internally.\n\n\nTo override a constant, prefix the constant's name with the Python module\nname and an underscore, then assign a value. For example, to edit overrides in\n[appstats](/appengine/docs/legacy/standard/python/tools/appstats), you can\ndefine the value of `KEY_PREFIX` \n\n```python\nappstats_KEY_PREFIX = '__my_custom_prefix__'\n```\n\n\nNaming of overridden hook functions is similar in other Python modules. For\nexample, in [namespace_manager](/appengine/docs/legacy/standard/python/multitenancy/multitenancy), you can override the hook function\n`default_namespace_for_request` in `appengine_config.py`\nas follows: \n\n```python\nimport os\ndef namespace_manager_default_namespace_for_request():\n return os.environ.get('HTTP_HOST', '')\n```\n\nConfigurable Python modules in App Engine\n-----------------------------------------\n\n\nThe Python modules listed below are configurable using\n`appengine_config.py`. By convention, hook functions are lowercase\nand constants are uppercase:\n[namespace_manager](/appengine/docs/legacy/standard/python/multitenancy/multitenancy)\n\n- `default_namespace_for_request()` (default returns `None`)\n\n\u003cbr /\u003e\n\n[appstats](/appengine/docs/legacy/standard/python/tools/appstats)\n\n- see `class ConfigDefaults` in [appengine/ext/appstats/recording.py](/appengine/docs/legacy/standard/python/refdocs/google.appengine.ext.appstats.recording#google.appengine.ext.appstats.recording.ConfigDefaults)\n- see example in [appengine/ext/appstats/sample_appengine_config.py](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/ext/appstats/sample_appengine_config)\n\n\u003cbr /\u003e\n\n[datastore_admin](/appengine/docs/python/console/managing-datastore)\n\n- `BASE_PATH` (default `'/_ah/datastore_admin'`)\n- `MAPREDUCE_PATH` (default `'/_ah/mapreduce'`)\n- `CLEANUP_MAPREDUCE_STATE` (default `True`)\n\n\u003cbr /\u003e\n\n[remoteapi](/appengine/docs/legacy/standard/python/tools/remoteapi)\n\n- `CUSTOM_ENVIRONMENT_AUTHENTICATION`\n- see `class ConfigDefaults` in [appengine/ext/remote_api/handler.py](/appengine/docs/legacy/standard/python/refdocs/google.appengine.ext.remote_api.handler#google.appengine.ext.remote_api.handler.ConfigDefaults)\n\n\u003cbr /\u003e\n\nConfiguring your own Python modules with lib_config\n---------------------------------------------------\n\n\nApp Engine also allows you to configure your own Python modules with constants\nand hook functions defined in `appengine_config.py`. The\n[`lib_config.register()` function](/appengine/docs/legacy/standard/python/refdocs/google.appengine.api.lib_config#google.appengine.api.lib_config.LibConfigRegistry.register) allows you to both register the\nnames of the user-overridable constants and hooks, and to define sensible\ndefaults in case the users don't wish to override them. Internally,\n`lib_config.register()` attempts to import\n`appengine_config`. If successful, it replaces the defaults of the\nspecified Python modules with those defined in\n`appengine_config.py`.\n\nExample usage in `my_module.py`: \n\n```python\nfrom google.appengine.api import lib_config\n\ndef _hook_function1_default():\n return 'baz'\n\n_config = lib_config.register('my_module', {'CONSTANT1': 'foo',\n 'CONSTANT2': 'bar',\n 'hook_function1': _hook_function1_default})\n```\n\n\nNow you can access a user's constants as: \n\n```python\n_config.CONSTANT1\n_config.CONSTANT2\n```\n\n\nand call their hook function as: \n\n```python\n_config.hook_function1()\n```\n\nSome programmers like to group their defaults into a class: \n\n```python\nclass _ConfigDefaults(object):\n CONSTANT1 = 'foo'\n CONSTANT2 = 'bar'\n def hook_function1():\n return 'baz'\n\n_config = lib_config.register('my_module', _ConfigDefaults.__dict__)\n```\n\n\nIn order to override your defaults, a user could define in\n`appengine_config.py`: \n\n```python\nmy_module_CONSTANT1 = 'foofoo'\nmy_module_hook_function1 = lambda: 'bazbaz'\n```\n\n\nAs a result, in `my_module.py`, the following will be true:\n\n- `_config.CONSTANT1` is now `'foofoo'`\n- `_config.CONSTANT2` remains `'bar'`\n- `_config.hook_function1()` returns `'bazbaz'`\n\n\nThe user overrides are available to `my_module.py` immediately\nafter `lib_config.register()` returns."]]