title: Using flask inside class
body: <p>I have an application with many threads. One of them is flask, which is used to implement (auxiliary) API. It's used with low load and never exposed to the Internet, so build-in flask web server is perfectly fine.</p>
  <p>My current code looks like this:</p>
  <pre><code>class API:
      # ... all other stuff here, skipped
      def run():
          app = flask.Flask('API')
  
          @app.route('/cmd1')
          def cmd1():
              self.cmd1()
  
          @app.route('/cmd2')
          def cmd2()
              self.cmd2()
  
          app.run()
  </code></pre>
  <p>I feel I done it wrong, because all docs says 'create flask app at module level'. But I don't want to do this - it messes up with my tests, and API is a small part of the larger application, which has own structure and conventions (each 'application' is a separate class running in one or more threads).</p>
  <p>How can I use Flask inside class?</p>