Skip to main content

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 a parameter dashboard (SupersetDashboard object) 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. 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")
  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!

Metadata

Release files for django-superset-integration 0.1.43

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-superset-integration 0.1.43
File Size Uploaded Provenance Actions
django_superset_integration-0.1.43.tar.gz 14.2 kB Without provenance Details for django_superset_integration-0.1.43.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-superset-integration 0.1.43
File Interpreter ABI Platform Actions
django_superset_integration-0.1.43-py3-none-any.whl Python 3 none any Details for django_superset_integration-0.1.43-py3-none-any.whl

Total release size: 30.4 kB

Release files / django_superset_integration-0.1.43.tar.gz

Download URL django_superset_integration-0.1.43.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
92f5fc20721868d4e34d5ed72239f245f8b5dd2a8371205f19682da2787da50e
BLAKE2b-256 checksum
How to use checksums
0cc33856d42456f9196c1210336743652185c262b0abdc38bb7764a15163c4b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.10.22 Linux/7.0.0-1017-azure

Release files / django_superset_integration-0.1.43-py3-none-any.whl

Download URL django_superset_integration-0.1.43-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
42d83b7427108a86f0622de011b181496ede6a30ec8d22f157595b9fed828257
BLAKE2b-256 checksum
How to use checksums
490ba68ca5013d805180570c93e301904b2ba09421153b7c85b70029d6775807
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.10.22 Linux/7.0.0-1017-azure

Security for django-superset-integration 0.1.43

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page