code: def get_credentials_from_env():
    
    if os.getenv(_DATASTORE_USE_STUB_CREDENTIAL_FOR_TEST_ENV):
      logging.info('connecting without credentials because %s is set.',
                   _DATASTORE_USE_STUB_CREDENTIAL_FOR_TEST_ENV)
      return None
    if os.getenv(_DATASTORE_EMULATOR_HOST_ENV):
      logging.info('connecting without credentials because %s is set.',
                   _DATASTORE_EMULATOR_HOST_ENV)
      return None
    if (os.getenv(_DATASTORE_SERVICE_ACCOUNT_ENV)
        and os.getenv(_DATASTORE_PRIVATE_KEY_FILE_ENV)):
      with open(os.getenv(_DATASTORE_PRIVATE_KEY_FILE_ENV), 'rb') as f:
        key = f.read()
      credentials = client.SignedJwtAssertionCredentials(
          os.getenv(_DATASTORE_SERVICE_ACCOUNT_ENV), key, SCOPE)
      logging.info('connecting using private key file.')
      return credentials
    try:
      credentials = client.GoogleCredentials.get_application_default()
      credentials = credentials.create_scoped(SCOPE)
      logging.info('connecting using Google Application Default Credentials.')
      return credentials
    except client.ApplicationDefaultCredentialsError, e:
      logging.error('Unable to find any credentials to use. '
                    'If you are running locally, make sure to set the '
                    '%s environment variable.', _DATASTORE_EMULATOR_HOST_ENV)
      raise e
docs: Get credentials from environment variables.
  
    Preference of credentials is:
    - No credentials if DATASTORE_EMULATOR_HOST is set.
    - Google APIs Signed JWT credentials based on
    DATASTORE_SERVICE_ACCOUNT and DATASTORE_PRIVATE_KEY_FILE
    environments variables
    - Google Application Default
    https://developers.google.com/identity/protocols/application-default-credentials
  
    Returns:
      credentials or None.