Skip to main content

Redash API Client

Project description

Redash-API-Client

Redash API Client written in Python.

Dependencies

  • Python3.6+

Installation

Install using pip:

pip install redash-api-client

Getting Started

from redashAPI.client import RedashAPIClient

# Create Client instance
"""
    :args:
    API_KEY
    REDASH_HOST (optional): 'http://localhost:5000' by default
"""
Redash = RedashAPIClient(API_KEY, REDASH_HOST)

Redash's RESTful API

URI Supported Methods
users GET, POST
users/1 GET, POST
data_sources GET, POST
data_sources/1 GET, POST, DELETE
queries GET, POST
queries/1 GET, POST, DELETE
query_results POST
query_results/1 GET
visualizations POST
visualizations/1 POST, DELETE
dashboards GET, POST
dashboards/slug GET, POST, DELETE
widgets POST
widgets/1 POST, DELETE
### EXAMPLE ###

# List all Data Sources
res = Redash.get('data_sources')
res.json()
"""
Response: [{"name": "Data Source 1", "pause_reason": null, "syntax": "sql", "paused": false, "view_only": false, "type": "mysql", "id": 1}]
"""

# Get specific Data Source
res = Redash.get('data_sources/1')
res.json()
"""
Response: {"scheduled_queue_name": "scheduled_queries", "name": "Data Source 1", "pause_reason": null, "queue_name": "queries", "syntax": "sql", "paused": false, "options": {"passwd": "--------", "host": "mysql", "db": "mds", "port": 3306, "user": "root"}, "groups": {"2": false}, "type": "mysql", "id": 1}
"""

# Create New Data Source
Redash.post('data_sources', {
    "name": "New Data Source",
    "type": "mysql",
    "options": {
        "dbname": DB_NAME,
        "host": DB_HOST,
        "user": DB_USER,
        "passwd": DB_PASSWORD,
        "port": DB_PORT
    }
})

# Delete Data Source
Redash.delete('data_sources/1')

Methods

# Create Data Source
"""
    :args:
    DATA_SOURCE_TYPE: ["sqlite", "mysql", "pg", "mongodb", "mssql" ...]
    DATA_SOURCE_NAME
    OPTIONS
"""
Redash.create_data_source("pg", "First Data Source", {
    "dbname": DB_NAME,
    "host": DB_HOST,
    "user": DB_USER,
    "passwd": DB_PASSWORD,
    "port": DB_PORT
})


# Create Query
"""
    :args:
    DATA_SOURCE_ID
    QUERY_NAME
    QUERY_STRING
    DESC (optional)
    WITH_RESULTS (optional): Generate query results automatically, True by default
"""
Redash.create_query(1, "First Query", "SELECT * FROM table_name;", with_results=False)


# Refresh Query
"""
    :args:
    QUERY_ID
"""
Redash.refresh_query(1)


# Generate Query Result
"""
    :args:
    QUERY_ID
"""
Redash.generate_query_result(1)


# Create Visualization
"""
    :args:
    QUERY_ID
    CHART_TYPE: ["table", "line", "column", "area", "pie", "scatter", "bubble", "box", "pivot"]
    CHART_NAME
    X_AXIS (optional): Column for X Axis (Required if CHART_TYPE is not table nor pivot)
    Y_AXIS (optional): Columns for Y Axis (Required if CHART_TYPE is not table nor pivot)
    TABLE_OPTIONS (optional): Custom options for Table (Required if CHART_TYPE is table)
    PIVOT_TABLE_OPTIONS (optional): Options for Pivot Table (Required if CHART_TYPE is pivot)
    DESC (optional)
"""
Redash.create_visualization(1, "table", "First Visualization", table_options={"itemsPerPage": 100, "columns": [{"name": "column1", "type": "string"}]})
Redash.create_visualization(1, "line", "Second Visualization", x_axis="column1", y_axis=[{"type": "line", "name": "column2", "label": "c2"}])


# Create Dashboard
"""
    :args:
    NAME
"""
Redash.create_dashboard("First Dashboard")


# Add Widget into Dashboard
"""
    :args:
    DASHBOARD_ID
    TEXT (optional)
    VISUALIZATION_ID (optional)
    FULL_WIDTH (optional): Full width or not on dashboard, False by default
    POSITION (optional)
"""
Redash.add_wdiget(1, text="Test")
Redash.add_widget(1, visualization_id=1, full_width=True)


# Publish Dashboard
"""
    :args:
    DASHBOARD_ID
"""
url = Redash.publish_dashboard(1)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redash-api-client-0.2.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

redash_api_client-0.2.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file redash-api-client-0.2.0.tar.gz.

File metadata

  • Download URL: redash-api-client-0.2.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for redash-api-client-0.2.0.tar.gz
Algorithm Hash digest
SHA256 320c5f972473881f1de10191718ce91ec930bd2555df069f39a431cfd49be994
MD5 e3550b790f4d9eb1bb898d1f990a8f11
BLAKE2b-256 77807a7ae561cabd9a44c500fe8de198ed22bba59099a5cd463381a2a3c0b24b

See more details on using hashes here.

File details

Details for the file redash_api_client-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: redash_api_client-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for redash_api_client-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 97a75e01ea915da73a63340c60aea1fe612337d94913e2b657fb479c4f6654e2
MD5 105487813daf419e15c768567df4ce06
BLAKE2b-256 bbcc611f909385fc1c37c06f51a685208878584d29eec94442d841b8123e6014

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page