diff --git a/examples/copy_dashboard.py b/examples/copy_dashboard.py new file mode 100644 index 0000000..2d464f5 --- /dev/null +++ b/examples/copy_dashboard.py @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 7c1ee09..6d4c9e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] 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" @@ -45,7 +43,7 @@ exclude = [ "dist", "site-packages", "venv", - "tests" + "tests", ] line-length = 88 indent-width = 4 @@ -53,24 +51,24 @@ 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 = [] diff --git a/supersetapiclient/dashboards.py b/supersetapiclient/dashboards.py index d01e5ea..83f1020 100644 --- a/supersetapiclient/dashboards.py +++ b/supersetapiclient/dashboards.py @@ -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.""" @@ -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):