user362953
user362953

Reputation: 435

Google AppEngine: Use python library only in Local Development. Identifying environment

My App used python libraries provided by the AppEngine Standard Environment. For including the library in my Local Development I followed the instructions on https://cloud.google.com/appengine/docs/python/tools/using-libraries-python-27.

# appengine_config.py
from google.appengine.ext import vendor

# Add any libraries install in the "lib" folder.
vendor.add('lib')

I pip installed the libraries to a folder 'lib' and in appengine_config.py added vendor.add('lib') I would like "vendor.add('lib')" to be effective/run only when the application is in Local and not in Google Cloud.

What is the right way to identify the environment? How about the below in appengine_config.py?

if 'localhost' in os.environ['SERVER_NAME']:
    vendor.add('lib')

Upvotes: 2

Views: 512

Answers (3)

Dan Cornilescu
Dan Cornilescu

Reputation: 39814

If your app uses a GAE provided library then you're not including it properly (you're vendoring it in, which is what you do with libraries not provided by GAE). From Requesting a library:

You can request a library by using the libraries: directive in app.yaml.

libraries:
- name: PIL
  version: "1.1.7"
- name: webob
  version: "1.1.1"

Note that: The library must be one of the supported runtime-provided third-party libraries.

When deployed, App Engine will provide the requested libraries to the runtime environment. Some libraries must be installed locally.

Upvotes: 2

Aaron
Aaron

Reputation: 821

Similar to the answer given by @mgilson I tend to use

DEBUG = os.environ.get('SERVER_SOFTWARE','').startswith('Dev')

If DEBUG is True then you're running in the local environment, otherwise it's live.

Upvotes: 1

mgilson
mgilson

Reputation: 309821

According to the official documentation, you should probably look in the SERVER_SOFTWARE environment variable:

To find out whether your code is running in production or in the local development server, check if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/'). When this is True, you're running in production; otherwise, you're running in the local development server.

Upvotes: 1

Related Questions