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
5. # Install external dependencies
6. pip install -r requirements/testing.txt
8. # Install Superset in editable (development) mode
9. pip install -e .
11. # Initialize the database
12. superset db upgrade
14. # Create an admin user in your metadata database (use `admin` as username to be able to load the examples)
15. superset fab create-admin
17. # Create default roles and permissions
18. superset init
20. # Load some data to play with.
21. # Note: you MUST have previously created an admin user with the username `admin` for this command to work.
22. superset load-examples
24. # Start the Flask dev web server from inside your virtualenv.
25. # Note that your page may not have CSS at this point.
26. 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
5. # install pip packages + pre-commit
6. make install
8. # Install superset pip packages and setup env only
9. make superset
11. # Setup pre-commit only
12. 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
3. def FLASK_APP_MUTATOR(app):
4. 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)
