title: How to access flask config variables outside application context according to my project structure?
body: <p>spinngod.py - flask app starter code</p>
  
  <pre><code>from app import create_app
  import sys
  
  run_profile = str(sys.argv[1]) if len(sys.argv) &gt;= 2 else 'development'
  app = create_app(run_profile)
  
  print("App Root Path:" + app.root_path)
  
  if __name__ == '__main__':
      print sys.path
      app.run(debug=True, host='0.0.0.0')
  </code></pre>
  
  <p>app/<strong>init</strong>.py - creates flask app</p>
  
  <pre><code>def create_app(profile_name):
      print "currently active profile:" + profile_name
      app = Flask(__name__)
  
      ############# configurations ####################
      app.config.from_object(config[profile_name])
      configure_app(app)
      configure_app_logger(app)
  
      #################### blueprint registration and rest_plus namespace additions ###############
      from api_1_0 import api as api_1_0_blueprint
      from api_1_0.restplus import api_restplus
  
      # ************************************************** #
      api_restplus.init_app(api_1_0_blueprint)
      api_restplus.add_namespace(application_namespace)
      api_restplus.add_namespace(pipeline_template_namespace)
      api_restplus.add_namespace(loadbalancer_namespace)
      api_restplus.add_namespace(servergroup_namespace)
      api_restplus.add_namespace(task_namespace)
      # ************************************************** #
  
      app.register_blueprint(api_1_0_blueprint)
  
      ##############################################################
      return app
  </code></pre>
  
  <p>I want to access flask config variables defined in config.py in some other files which are outside application context. The app configuration depends on which profile it is started with (dev,stage or production) which is being passed from command line as an arg.</p>
  
  <p>The only way that I can think of accessing config variables outside app context is to set profile (dev,stage or prod) as an environment variable and 
  then import directly from config file. </p>
  
  <p>The second way that I tried was to move creation of flask app in app/<strong>init</strong>.py outside method.</p>
  
  <p><strong>This is how I am trying to access config variables in another class.</strong></p>
  
  <pre><code>import requests
  
  
  class Client(object):
      def __init__(self):
          from app import app
          print "fjaijflkajsf" + app.config['SPINNAKER_BASE_URL']
          pass
  </code></pre>
  
  <p>Is there a way better of doing this in flask ?</p>