Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ ipython_config.py
# pyenv
.python-version

# IDE
.idea/

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
Expand Down
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ dashboards = client.dashboards.find()
dashboard = client.dashboards.find(dashboard_title="Example")[0]
```

To delete a dashboard:
```python3
dashboard.delete()
```

Update dashboard colors, some properties and save changes to server:
```python3
# Update label_colors mapping
Expand All @@ -65,6 +70,15 @@ Create the embed configuration for a dashboard:
embed = dashboard.create_embed(allowed_domains=[])
```

Copy a dashboard:
```python3
dashboard_copy = dashboard.copy_dashboard(dashboard_payload={
"css": "",
"dashboard_title": "your-new-dashboard-title",
"duplicate_slices": False,
"json_metadata": "{}",
})
```

### Export one ore more dashboard

Expand All @@ -90,11 +104,23 @@ dashboard.export(
This functionality is also available in the same manner for datasets


### CSS Templates

```python3
# Get all CSS Templates
css_templates = client.css_templates.find()

# Get a CSS Template by name
css_template = client.css_templates.find(template_name="Flat")[0]

# Retrieve the CSS of a CSS Template
css = css_template.css
```

### Retrieve a Guest Token

You can retrieve a guest token using the `guest_token` method. This method requires the UUID of the resource (e.g., dashboard) and uses the user's first name, last name, and username from the client instance.

#### Example Usage:
```python3
# Retrieve a guest token
guest_token = client.guest_token(uuid="your-example-uuid")
Expand Down
3 changes: 3 additions & 0 deletions supersetapiclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from supersetapiclient.datasets import Datasets
from supersetapiclient.exceptions import QueryLimitReached
from supersetapiclient.saved_queries import SavedQueries
from supersetapiclient.css_templates import CssTemplates

logger = logging.getLogger(__name__)

Expand All @@ -33,6 +34,7 @@ class SupersetClient:
datasets_cls = Datasets
databases_cls = Databases
saved_queries_cls = SavedQueries
css_templates_cls = CssTemplates
http_adapter_cls = None

def __init__(
Expand Down Expand Up @@ -63,6 +65,7 @@ def __init__(
self.datasets = self.datasets_cls(self)
self.databases = self.databases_cls(self)
self.saved_queries = self.saved_queries_cls(self)
self.css_templates = self.css_templates_cls(self)

@cached_property
def _token(self):
Expand Down
17 changes: 17 additions & 0 deletions supersetapiclient/css_templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""CSS Templates."""
from dataclasses import dataclass
from typing import Optional

from supersetapiclient.base import Object, ObjectFactories, default_string, raise_for_status


@dataclass
class CssTemplate(Object):
template_name: str
id: Optional[int] = None
css: str = default_string()


class CssTemplates(ObjectFactories):
endpoint = "css_template/"
base_object = CssTemplate
17 changes: 12 additions & 5 deletions supersetapiclient/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from supersetapiclient.base import Object, ObjectFactories, default_string, json_field, raise_for_status


@dataclass
class DashboardEmbed(Object):
allowed_domains: List[str] = field(default_factory=list)
Expand Down Expand Up @@ -54,20 +55,26 @@ def get_charts(self) -> List[int]:
def get_embed(self) -> DashboardEmbed:
"""Get the dashboard's embedded configuration"""
client = self._parent.client
embed_url = client.join_urls(self.base_url,"embedded")
response = client.get(embed_url)
embed_dashboard_url = client.join_urls(self.base_url,"embedded")
response = client.get(embed_dashboard_url)
if response.status_code == 404:
return None
return DashboardEmbed().from_json(response.json().get("result"))

def create_embed(self, allowed_domains: List[str]) -> DashboardEmbed:
"""Set a dashboard's embedded configuration"""
client = self._parent.client
embed_url = client.join_urls(self.base_url,"embedded")
response = client.post(embed_url, json={ "allowed_domains": allowed_domains })
embed_dashboard_url = client.join_urls(self.base_url,"embedded")
response = client.post(embed_dashboard_url, json={ "allowed_domains": allowed_domains })
raise_for_status(response)
return DashboardEmbed().from_json(response.json().get("result"))


def copy_dashboard(self, dashboard_payload: dict) -> None:
"""Copy the dashboard with the given payload"""
client = self._parent.client
copy_dashboard_url = client.join_urls(self.base_url,"copy")
response = client.post(copy_dashboard_url, json=dashboard_payload)
raise_for_status(response)

class Dashboards(ObjectFactories):
endpoint = "dashboard/"
Expand Down