Skip to main content

Redash API Client

Project description

Redash-API-Client

PyPI version fury.io PyPI pyversions PyPI license Downloads

Redash API Client written in Python.

Dependencies

  • Python3.6+

Installation

pip install redash-api-client

Getting Started

from redashAPI import RedashAPIClient

# Create API 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()
"""
[
    {
        'name': 'data_source1',
        'pause_reason': None,
        'syntax': 'sql',
        'paused': 0,
        'view_only': False,
        'type': 'pg',
        'id': 1
    },
    ...
]
"""

# Retrieve specific Data Source
res = Redash.get('data_sources/1')
res.json()
"""
{
    "scheduled_queue_name": "scheduled_queries",
    "name": "test1",
    "pause_reason": "None",
    "queue_name": "queries",
    "syntax": "sql",
    "paused": 0,
    "options": {
        "password": "--------",
        "dbname": "bi",
        "user": ""
    },
    "groups": {
        "1":False
    },
    "type": "pg",
    "id": 1
}
"""

# Create New Data Source
Redash.post('data_sources', {
    "name": "New Data Source",
    "type": "pg",
    "options": {
        "dbname": DB_NAME,
        "host": DB_HOST,
        "user": DB_USER,
        "passwd": DB_PASSWORD,
        "port": DB_PORT
    }
})
"""
{
    "scheduled_queue_name": "scheduled_queries",
    "name": "New Data Source",
    "pause_reason": "None",
    "queue_name": "queries",
    "syntax": "sql",
    "paused": 0,
    "options": {
        "dbname": DB_NAME,
        "host": DB_HOST,
        "user": DB_USER,
        "passwd": DB_PASSWORD,
        "port": DB_PORT
    },
    "groups": {
        "2": False
    },
    "type": "pg",
    "id": 2
}
"""

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

Create Data Source

  • _type

  • name

    • Name for Data Source.
  • options

    • Configuration.
### EXAMPLE ###

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

  • ds_id

    • Data Source ID.
  • name

    • Name for query.
  • qry

    • Query string.
  • desc (optional)

    • Description.
  • with_results (optional)

    • Generate query results automatically, True by default.
  • options (optional)

    • Custom options.
### EXAMPLE ###

Redash.create_query(1, "First Query", "SELECT * FROM table_name;")

Refresh Query

  • qry_id

    • Query ID.
### EXAMPLE ###

Redash.refresh_query(1)

Generate Query Result

  • ds_id

    • Data Source ID.
  • qry

    • Query String.
  • qry_id (optional)

    • Query ID.
  • max_age (optional)

    • If query results less than max_age seconds old are available, return them, otherwise execute the query; if omitted or -1, returns any cached result, or executes if not available. Set to zero to always execute.
  • parameters (optional)

    • A set of parameter values to apply to the query.
  • return_results (optional)

    • Return results if query is executed successfully, True by default.
### EXAMPLE ###

Redash.generate_query_results(1)

Create Visualization

  • qry_id

    • Query ID.
  • _type

    • Type of Visualization. (table, line, column, area, pie, scatter, bubble, box, pivot)
  • name

    • Name for Visualization.
  • columns (optional)

    • Columns for Table. (Required if _type is table)
  • x_axis (optional)

    • Column for X Axis. (Required if _type is not table nor pivot)
  • y_axis (optional)

    • Columns for Y Axis (Required if _type is not table nor pivot)
  • group_by (optional)

    • Group by specific column.
  • custom_options (optional)

    • Custom options for Visualization.
  • desc (optional)

    • Description.
### EXAMPLE 1 ###

Redash.create_visualization(1, "table", "First Visualization", columns=[
    {"name": "column1", "type": "string"},
    {"name": "column2", "type": "datetime"}
])

### EXAMPLE 2 ###
Redash.create_visualization(1, "line", "Second Visualization", x_axis="column1", y_axis=[
    {"type": "line", "name": "column2", "label": "c2"}
])

Create Dashboard

  • name

    • Name for Dashboard.
### EXAMPLE ###

Redash.create_dashboard("First Dashboard")

Add Widget into Dashboard

  • db_id

    • Dashboard ID.
  • text (optional)

    • Text Widget.
  • vs_id (optional)

    • Visualization ID.
  • full_width (optional)

    • Full width or not, False by default.
  • position (optional)

    • Custom position for Widget.
### EXAMPLE 1 ###

Redash.add_widget(1, text="Test")

### EXAMPLE 2 ###
Redash.add_widget(1, visualization_id=1, full_width=True)

Publish Dashboard

  • db_id

    • Dashboard ID.
### EXAMPLE ###

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.8.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

redash_api_client-0.2.8-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: redash-api-client-0.2.8.tar.gz
  • Upload date:
  • Size: 6.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.9

File hashes

Hashes for redash-api-client-0.2.8.tar.gz
Algorithm Hash digest
SHA256 aad9067a48403ff70f2d37fc1bdd6d6d5a56080d95ddd970b84f1ee7d5323285
MD5 e148401ee3b60df95825bbf74bd2e347
BLAKE2b-256 1a0ae60f0ebfb6cd5e203b969d3d7836348a99d0c3b0d048fe1337d760b659f7

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: redash_api_client-0.2.8-py3-none-any.whl
  • Upload date:
  • Size: 6.7 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.9

File hashes

Hashes for redash_api_client-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 acfb0f1691dfdef0e4baca576d2a510c27705e56dcd7f41da6592501df197086
MD5 d812ea69af6fec34be1fbeb0deeb7f1c
BLAKE2b-256 e5381b5eba83273c83c515167b3ac92fa64152dcfc0bf677f4a7cbab69824a5d

See more details on using hashes here.

Provenance

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