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
26 changes: 26 additions & 0 deletions examples/copy_dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Copy a dashboard."""

# Uncomment to run locally
# import os
# os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"

from supersetapiclient.client import SupersetClient

client = SupersetClient(
host="http://localhost:8088",
username="admin",
password="admin",
)
# Get a dashboard by name
dashboard = client.dashboards.find(slug="local-landing-supplier")[0]

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

print(dashboard_copy)
32 changes: 15 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "superset-python-client"
version = "1.1.2"
version = "1.1.3"
description = "A simple REST API Client for Apache-Superset in Python"
authors = ["Shahroz Ahmad <ishahrozahmad90@gmail.com>"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/ishahroz/superset-python-client"
packages = [
{ include = "supersetapiclient" }
]
packages = [{ include = "supersetapiclient" }]

[tool.poetry.dependencies]
python = ">=3.12,<3.13"
Expand Down Expand Up @@ -45,32 +43,32 @@ exclude = [
"dist",
"site-packages",
"venv",
"tests"
"tests",
]
line-length = 88
indent-width = 4
target-version = "py312"

[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"F", # Pyflakes
"W", # pycodestyle warnings
"E", # pycodestyle errors
"F", # Pyflakes
"W", # pycodestyle warnings
"C90", # McCabe complexity
"I", # isort
"N", # pep8-naming
"D", # pydocstyle
"UP", # pyupgrade
"B", # flake8-bugbear
"A", # flake8-builtins
"I", # isort
"N", # pep8-naming
"D", # pydocstyle
"UP", # pyupgrade
"B", # flake8-bugbear
"A", # flake8-builtins
]
ignore = [
"D105", # Missing docstring in public function
"D107", # Missing docstring in public _init__ method definitions
"N818", # Custom exception definitions that omit the Error suffix
"B904", # Raise in except
"D203", # Ignore 'one-blank-line-before-class' in favor of 'no-blank-line-before-class'
"D213", # Ignore 'multi-line-summary-second-line' in favor of 'multi-line-summary-first-line'
"B904", # Raise in except
"D203", # Ignore 'one-blank-line-before-class' in favor of 'no-blank-line-before-class'
"D213", # Ignore 'multi-line-summary-second-line' in favor of 'multi-line-summary-first-line'
]
fixable = ["ALL"]
unfixable = []
Expand Down
10 changes: 9 additions & 1 deletion supersetapiclient/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class DashboardEmbed(Object):
uuid: str = None


@dataclass
class DashboardCopy(Object):
"""Dashboard copy."""

id: int | None = None


@dataclass
class Dashboard(Object):
"""Dashboard."""
Expand Down Expand Up @@ -81,12 +88,13 @@ def create_embed(self, allowed_domains: list[str]) -> DashboardEmbed:
raise_for_status(response)
return DashboardEmbed().from_json(response.json().get("result"))

def copy_dashboard(self, dashboard_payload: dict) -> None:
def copy_dashboard(self, dashboard_payload: dict) -> DashboardCopy:
"""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)
return DashboardCopy().from_json(response.json().get("result"))


class Dashboards(ObjectFactories):
Expand Down