A Django app to integrate Apache Superset dashboards into a Django application
Project description
django-superset-integration
django-superset-integration is a Django app to integration Apache Superset dashboards into a Django application.
Quick start
- Add
django_superset_integrationto yourINSTALLED_APPSsetting like this:
INSTALLED_APPS = [
...,
"django_superset_integration",
...,
]
- Include the superset-integration URLconf in your project
urls.pylike this:
path("superset_integration/", include("django_superset_integration.urls")),
- You will need a cryptography Fernet key, so you need to install cryptography:
pip install cryptography
- Generate a Fernet key in a python terminal:
from cryptography.fernet import Fernet
FERNET_KEY = Fernet.generate_key()
-
The result is a bytestring like
b'jozEHFGLKJHEFUIHEZ4'. Copy ONLY the content of the string, not the b nor the quotation marks -
In your env variables, create a variable
FERNET_KEYwith the copied content as value -
Add a variable
ENCRYPTION_KEYin yoursettings.pyreferencing your env variableFERNET_KEY:
ENCRYPTION_KEY = os.environ.get("FERNET_KEY", "").encode()
- By default, all dashboard data will be displayed. You can override this by creating your own filtering function and adding it in your
settings.py:
RLS_FUNCTION = "my_app.my_module.create_rls_clause"
Your function must take a parameter user and return a SQL rls clause like this : [{"clause": "1=1"}]
(where you replace 1=1 by the clause you want).
See Superset documentation for more information
-
Make sure that your Superset instance parameter
GUEST_TOKEN_JWT_EXP_SECONDSis more than 300 (5 minutes). Otherwise it will expire before it can be refreshed. For example, set it to 600 (10 minutes). -
In the template where you want to integrate the dashboard, add the following at the emplacement where you want the dashboard:
{% load static %}
...
{% include "django_superset_integration/superset-integration.html" %}
-
Run
python manage.py migrateto create the models. -
Start the development server and visit the admin site to create a
SupersetInstanceobject.- address: the address of your Superset instance
- username: the username that allows to connect via api to your instance. By default : superset_api You need to have a service account with minimal permissions to embed dashboards. See Superset documentation for more info.
- password: the password that allows to connect via api to your instance.
-
After you have created a
SupersetInstanceobject, create aSupersetDashboardobject.- integration_id: the integration id given by Superset to integrate your dashboard
- name: a name for your dashboard
- domain: (foreign key) the SupersetInstance object corresponding to the instance where the dashboard is
- comment: (optional) a plain text comment
- superset_link: (optional) the link to your dashboard in Superset
-
In the view where you want to integrate the dashboard, in
get_context_data, add the following:
from django_superset_integration.models import SupersetDashboard
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
...
dashboard_name = "THE NAME OF YOUR DASHBOARD FROM STEP 13"
dashboard = SupersetDashboard.objects.get(name__iexact=dashboard_name)
context["dashboard_integration_id"] = dashboard.integration_id
context["dashboard_id"] = dashboard.id
context["superset_domain"] = dashboard.domain.address
...
return context
- If you want to use the "app_name" attribute of SupersetDashboard object, you have to provide your own logic, for example in the view where you want to integrate the dashboard
def get(self, request, *args, **kwargs):
dashboard_name = "THE NAME OF YOUR DASHBOARD FROM STEP 13"
dashboard = SupersetDashboard.objects.get(name__iexact=dashboard_name)
# If the SupersetDashboard object has a 'app_name' attribute
# it can be displayed only in the corresponding app
if dashboard.app_name:
app_name = request.resolver_match.func.__module__.split(".")[0]
if app_name.lower() != dashboard.app_name.lower():
# If not in the right app, the dashboard is not displayed and the user
# is redirected to the index page
return redirect("index")
- You can personalize the buttons "Fullscreen" and "Quit fullscreen" by giving class names in your view's
get_context_data:
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
...
context["button_fullscreen_classes"] = "myClass1 myClass2"
context["button_quit_fullscreen_classes"] = "myClass1 myClass2"
...
return context
- That should be it!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_superset_integration-0.1.31.tar.gz.
File metadata
- Download URL: django_superset_integration-0.1.31.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.10.20 Linux/6.17.0-1013-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8fd213d489fa5486a1c430c6d0c7a1a6a0ff71c271959c8b42c82990dcde835
|
|
| MD5 |
0bd2f4f4b549f2b6b8c8427b0cf0d01b
|
|
| BLAKE2b-256 |
e524596a73b688dc75ae60a4d9da07fc4ceed9e9cb1e5ab244968f19f584f048
|
File details
Details for the file django_superset_integration-0.1.31-py3-none-any.whl.
File metadata
- Download URL: django_superset_integration-0.1.31-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.10.20 Linux/6.17.0-1013-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb04fb24c148590e44cd100e583361a2fb453d9e90e9ddf3f8968aba3cab423a
|
|
| MD5 |
4c3e12cdc274166c903d411687f89ca7
|
|
| BLAKE2b-256 |
33467a8d96c4315b809ac30757ed691cd65f943d367f0e17541631cb3819d2eb
|