Package: redash-api-client
Redash-API-ClientRedash API Client written in Python.DependenciesPython3.6+Installationpip install redash-api-clientGetting StartedfromredashAPIimportRedashAPIClient# Create API client instance""":args:API_KEYREDASH_HOST (optional): `http://localhost:5000` by default"""Redash=RedashAPIClient(API_KEY,REDASH_HOST)Redash's RESTful APIURISupported MethodsusersGET,POSTusers/1GET,POSTdata_sourcesGET,POSTdata_sources/1GET,POST,DELETEqueriesGET,POSTqueries/1GET,POST,DELETEquery_resultsPOSTquery_results/1GETvisualizationsPOSTvisualizations/1POST,DELETEdashboardsGET,POSTdashboards/slugGET,POST,DELETEwidgetsPOSTwidgets/1POST,DELETE### EXAMPLE #### List all Data Sourcesres=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 Sourceres=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 SourceRedash.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 SourceRedash.delete('data_sources/2')Create Data Source_typeType of Data Source. (Supported types)nameName for Data Source.optionsConfiguration.### 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 Queryds_idData Source ID.nameName for query.qryQuery string.desc (optional)Description.with_results (optional)Generate query results automatically,Trueby default.options (optional)Custom options.### EXAMPLE ###Redash.create_query(1,"First Query","SELECT * FROM table_name;")Refresh Queryqry_idQuery ID.### EXAMPLE ###Redash.refresh_query(1)Generate Query Resultds_idData Source ID.qryQuery String.qry_id (optional)Query ID.max_age (optional)If query results less thanmax_ageseconds 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,Trueby default.### EXAMPLE ###Redash.generate_query_results(1)Query and Wait Resultds_idData Source ID.qryQuery String.timeout (optional)Defines the time in seconds to wait before cutting the request.### EXAMPLE ###Redash.query_and_wait_result(1,'select * from my_table;',60)Create Visualizationqry_idQuery ID._typeType of Visualization. (table,line,column,area,pie,scatter,bubble,box,pivot)nameName for Visualization.columns (optional)Columns for Table. (Required if_typeistable)x_axis (optional)Column for X Axis. (Required if_typeis nottablenorpivot)y_axis (optional)Columns for Y Axis (Required if_typeis nottablenorpivot)size_column (optional)Column for size. (Bubble)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 DashboardnameName for Dashboard.### EXAMPLE ###Redash.create_dashboard("First Dashboard")Add Widget into Dashboarddb_idDashboard ID.text (optional)Text Widget.vs_id (optional)Visualization ID.full_width (optional)Full width or not,Falseby 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 Dashboarddb_idDashboard ID.### EXAMPLE ###url=Redash.publish_dashboard(1)LicenseThis project is licensed under the MIT License - see theLICENSEfile for details.