Redash API Python Client
python package for interacting with the Redash API
Features
- Complete access to all endpoints in the Redash API.
- Pagination by default.
- Duplicate dashboards.
- Manage users and groups.
- Duplicate queries with different source tables.
Implemented Services
* widgets endpoint does not support GET requests, only update, delete and
create.
Getting Started
an API key is required in addition to the instance's host URL.
Installation
pip install redash-python
Usage
from redash_python import Redash
rd = Redash(base_url="", api_key="")
dashboards = rd.dashboards.get_all()
dash = rd.dashboards.get(1)
query = rd.queries.get_by_name("my-dashboard")
q = rd.queries.get_by_tags(["my-tag"])
dash = rd.dashboards.get_by_tags(["my-tag"], without=True)
ques = rd.queries
ques.duplicate_query_table(
query=ques.get(1),
table_map={"old_table": "new_table"},
tags=["admin", "test"],
publish=True,
)
print(rd.services)
print(rd.users)
for a full list of implemented methods in each service, print the service
object.
>>> print(client.dashboards)
DashboardsService(attributes: ['endpoint'], methods: ['create', 'create_widget', 'delete', 'duplicate', 'exists', 'favorite', 'favorited', 'get', 'get_all', 'get_by_name', 'get_by_tags', 'get_id', 'get_slug', 'paginate', 'publish', 'refresh', 'share', 'unfavorite', 'unpublish', 'update'])
for more examples on usage, see examples folder on github.
Development
before starting development, install dev dependencies:
pip install redash-python[dev]
Architecture
this library implements a services based architecture splitting each API
endpoint group to its own service, on top of which is the Redash
class. all
the services share base classes from mixins that make it easier to share common
behavior and allows rapid development for any new endpoints. for instance adding
query_snippets is as simple as:
from .base import BaseService
from .mixins import CommonMixin, NameMixin, PrintMixin
class QSnipsService(CommonMixin, NameMixin, PrintMixin):
def __init__(self, base: BaseService) -> None:
CommonMixin.__init__(self, base)
self.__base = base
self.endpoint = "/api/query_snippets"
Directory Structure
redash_python
├── __init__.py
├── redash.py
└── services
├── base.py
└── mixins.py
Contributing
Contributions are welcome, please open an issue or PR to propose any changes.
License