title: APScheduler in flask with blueprints
body: <p>I am really struggling to work out how to get APScheduler running in my flask application.</p>
  <p>App structure:</p>
  <pre><code>/app
  ├── project/
  │   ├── __init__.py
  │   ├── main.py
  ├── app.py
  </code></pre>
  <p>app.py:</p>
  <pre><code>from project import app
  app.run(host='0.0.0.0', port=80, debug=True)
  </code></pre>
  <p><strong>init</strong>.py:</p>
  <pre><code>from flask import Flask
  
  app = Flask(__name__)
  
  # set up blueprints
  from .main import main as main_blueprint
  app.register_blueprint(main_blueprint)
  
  # set up apscheduler
  from apscheduler.schedulers.background import BackgroundScheduler
  scheduler = BackgroundScheduler(daemon=True)
  scheduler.start()
  </code></pre>
  <p>main.py:</p>
  <pre><code>from flask import Blueprint, render_template, Flask
  from . import scheduler
  import time
  
  main = Blueprint('main', __name__)
  
  @main.route('/schedule_test')
  def schedule_test():
      scheduler.add_job(func=print_date_time, trigger=&quot;interval&quot;, seconds=3)
  
  def print_date_time():
      print(time.strftime(&quot;%A, %d. %B %Y %I:%M:%S %p&quot;))
  </code></pre>
  <p>When I run this I get the error:</p>
  <pre><code>ImportError: cannot import name 'scheduler' from 'project' (/app/project/__init__.py)
  </code></pre>
  <p>I'm sure I'm doing something simple wrong, but I can't work it out.</p>
  <p>Edit: to be clear, the flask app runs fine when I remove the references to scheduler.</p>