title: How can I access the flask application configuration outside of the application?
body: <p>I'm not sure if this is a flask specific issue or if I simply lack an understanding of the python import mechanism, but I'm having some problems with a flask web application. Here's the layout of my application:</p>
  
  <pre><code>/myapp
    /INSTALL
    /TODO
    /run.py
    /instance
      /application.cfg
    /myapp
      /static
      /templates
      /__init__.py
      /config.py
      /service.py
  </code></pre>
  
  <p>The config.py file stores the default application configuration, and application.cfg stores instance configuration. They both look like this:</p>
  
  <pre><code>DEBUG = False
  TESTING = False
  SECRET_KEY = "please_replace_me"
  </code></pre>
  
  <p>This is how I set up the application in <strong>init</strong>.py:</p>
  
  <pre><code>import flask
  app = Flask(__name__, instance_relative_config=True)
  app.config.from_object("myapp.config")
  app.config.from_pyfyle("application.cfg", silent=True)
  </code></pre>
  
  <p>Now what I want is to access the app.config object from service.py, which is not included by <strong>init</strong>.py or any of the other modules that are part of the web application. I.e. this is how I want my service.py file to read:</p>
  
  <pre><code>from somewhere.somehow import app
  
  def run():
    do_stuff(app.config["CONFIG_OPTION"])
  </code></pre>
  
  <p>The problem is the service.py file has to be inside the package, so I can't move it one folder up and just import myapp. How do I do this?</p>