Flask server

OS Dependencies

Make sure your machine meets the OS dependencies before following these steps. You also need to install MySQL or MariaDB.

Ensure that you are using Python version 3.8 or 3.9, then proceed with:

  1. # Create a virtual environment and activate it (recommended)
  2. python3 -m venv venv # setup a python3 virtualenv
  3. source venv/bin/activate
  4. # Install external dependencies
  5. pip install -r requirements/testing.txt
  6. # Install Superset in editable (development) mode
  7. pip install -e .
  8. # Initialize the database
  9. superset db upgrade
  10. # Create an admin user in your metadata database (use `admin` as username to be able to load the examples)
  11. superset fab create-admin
  12. # Create default roles and permissions
  13. superset init
  14. # Load some data to play with.
  15. # Note: you MUST have previously created an admin user with the username `admin` for this command to work.
  16. superset load-examples
  17. # Start the Flask dev web server from inside your virtualenv.
  18. # Note that your page may not have CSS at this point.
  19. FLASK_ENV=development superset run -p 8088 --with-threads --reload --debugger

Or you can install via our Makefile

  1. # Create a virtual environment and activate it (recommended)
  2. python3 -m venv venv # setup a python3 virtualenv
  3. source venv/bin/activate
  4. # install pip packages + pre-commit
  5. make install
  6. # Install superset pip packages and setup env only
  7. make superset
  8. # Setup pre-commit only
  9. make pre-commit

Note: the FLASK_APP env var should not need to be set, as it’s currently controlled via .flaskenv, however if needed, it should be set to superset.app:create_app()

If you have made changes to the FAB-managed templates, which are not built the same way as the newer, React-powered front-end assets, you need to start the app without the --with-threads argument like so: FLASK_ENV=development superset run -p 8088 --reload --debugger

Dependencies

If you add a new requirement or update an existing requirement (per the install_requires section in setup.py) you must recompile (freeze) the Python dependencies to ensure that for CI, testing, etc. the build is deterministic. This can be achieved via,

  1. $ python3 -m venv venv
  2. $ source venv/bin/activate
  3. $ python3 -m pip install -r requirements/integration.txt
  4. $ pip-compile-multi --no-upgrade

Logging to the browser console

This feature is only available on Python 3. When debugging your application, you can have the server logs sent directly to the browser console using the ConsoleLog package. You need to mutate the app, by adding the following to your config.py or superset_config.py:

  1. from console_log import ConsoleLog
  2. def FLASK_APP_MUTATOR(app):
  3. app.wsgi_app = ConsoleLog(app.wsgi_app, app.logger)

Then make sure you run your WSGI server using the right worker type:

  1. FLASK_ENV=development gunicorn "superset.app:create_app()" -k "geventwebsocket.gunicorn.workers.GeventWebSocketWorker" -b 127.0.0.1:8088 --reload

You can log anything to the browser console, including objects:

  1. from superset import app
  2. app.logger.error('An exception occurred!')
  3. app.logger.info(form_data)

Frontend Assets

See Building Frontend Assets Locally