Skip to main content

A Django app to integrate Apache Superset dashboards into a Django application

Project description

django-superset-integration

PyPI - Version GitHub Issues or Pull Requests

Monthly Downloads Total Downloads

django-superset-integration is a Django app to integration Apache Superset dashboards into a Django application.

Quick start

  1. Add django_superset_integration to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [
    ...,
    "django_superset_integration",
    ...,
]
  1. Include the superset-integration URLconf in your project urls.py like this:
path("superset_integration/", include("django_superset_integration.urls")),
  1. You will need a cryptography Fernet key, so you need to install cryptography:
pip install cryptography
  1. Generate a Fernet key in a python terminal:
from cryptography.fernet import Fernet
FERNET_KEY = Fernet.generate_key()
  1. The result is a bytestring like b'jozEHFGLKJHEFUIHEZ4'. Copy ONLY the content of the string, not the b nor the quotation marks

  2. In your env variables, create a variable FERNET_KEY with the copied content as value

  3. Add a variable ENCRYPTION_KEY in your settings.py referencing your env variable FERNET_KEY:

ENCRYPTION_KEY = os.environ.get("FERNET_KEY", "").encode()
  1. 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

  1. Make sure that your Superset instance parameter GUEST_TOKEN_JWT_EXP_SECONDS is more than 300 (5 minutes). Otherwise it will expire before it can be refreshed. For example, set it to 600 (10 minutes).

  2. 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" %}
  1. Run python manage.py migrate to create the models.

  2. Start the development server and visit the admin site to create a SupersetInstance object.

    • 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.
  3. After you have created a SupersetInstance object, create a SupersetDashboard object.

    • 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
  4. 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
  1. 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
  1. That should be it!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_superset_integration-0.1.17.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_superset_integration-0.1.17-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file django_superset_integration-0.1.17.tar.gz.

File metadata

  • Download URL: django_superset_integration-0.1.17.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.10.18 Linux/6.11.0-1018-azure

File hashes

Hashes for django_superset_integration-0.1.17.tar.gz
Algorithm Hash digest
SHA256 173842ac1801edfa2b4149c03f79ddf5e75c925e6777cceb3731e34d14237f9f
MD5 848d84368914f3a08cd82ea4bceb600e
BLAKE2b-256 920a4c0f59a9bc090300c1dd5ff1b9ab17ea3334d27b3ed08e32d992fcc300e8

See more details on using hashes here.

File details

Details for the file django_superset_integration-0.1.17-py3-none-any.whl.

File metadata

File hashes

Hashes for django_superset_integration-0.1.17-py3-none-any.whl
Algorithm Hash digest
SHA256 28747f7d1a6189ba583256a0b3bef1506dfeee632af03cd5969899cd7384e7e8
MD5 b243a36b63e206b882453fc9cae81fcd
BLAKE2b-256 03661151460692f1c27b54a831248f2d23bd018bb49a5fc03ce2c04626c7bd21

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page