Skip to main content

RedaSQL

redasql

RedaSQL is querying tool for redash. I like psql(PostgreSQL CLI). so redasql resemble psql in some respects.

Install

pip install redasql

supported readsh version

RedaSQL supports Redash v8, v9 and v10.RedaSQL supports Redash v8, v9 and v10.

How To Use

redasql need some arguments or environment variables. redasql prioritizes arguments over environment variables.

argument env mean required
-k/--api-key REDASQL_REDASH_APIKEY API KEY(user api key) True
-s/--server-host REDASQL_REDASH_ENDPOINT Redash server hostname. ex) https://your.redash.server.host/ True
-p/--proxy REDASQL_HTTP_PROXY if your redash server restricted by Proxy, set url format. ex)http://user:pass@your.proxy.server:proxy-port False
-d/--data-source None initial connect datasource name. False
--ignore-rc None ignore .redasqlrc file False(default false)
--wait-interval-sec None Wait Job Pooling Interval Sec False(default 0.1)
--timeout-count None Wait Job Pooling Count(int) False(default 600)
--debug None debug mode False(default false)
--no-fetch-data None execute query but don't fetch result data. only display row count and execution status. False(default false)
-c/--command None execute a single query and exit. False
--variable None value for query parameter {{ name }}. NAME=VALUE format. can be specified multiple times. False

if you want to use redasql with direnv, rename .envrc.sample to .envrc and set attributes.

special commands

redasql has management commands.

metadata=# \?
\?: HELP META COMMANDS.
\q: EXIT.
\d: DESCRIBE TABLE
\c: SELECT DATASOURCE.
\x: QUERY RESULT TOGGLE PIVOT.
\f: CHANGE RESULT FORMATTER ['table', 'markdown', 'markdown_with_sql', 'csv'].
\l: LOAD QUERY FROM REDASH.
\o: CHANGE THE OUTPUT DESTINATION TO ['stdout', 'stdout_and_clipboard', 'file'].
\i: LOAD QUERY FROM LOCAL FILE.

execute query

see below

start

$ redasql

 ____          _       ____   ___  _     
|  _ \ ___  __| | __ _/ ___| / _ \| |    
| |_) / _ \/ _` |/ _` \___ \| | | | |    
|  _ <  __/ (_| | (_| |___) | |_| | |___ 
|_| \_\___|\__,_|\__,_|____/ \__\_\_____|

    - redash query cli tool -

SUCCESS CONNECT
- server version 8.0.0+b32245
- client version 0.1.0

(No DataSource)=#

connect datasource

use \c data_source_name. if not provide data_source_name, show all available data sources.

(No DataSource)=# \c metadata
metadata=#

describe table

use \d table_name. if not provide table_name, show all table names. if provide table_name with wildcard(*), show describe matched tables.

metadata=# \d
access_permissions
alembic_version
:
queries
query_results
query_snippets
users
visualizations
widgets
metadata=# \d queries
## queries
- schedule
- updated_at
- api_key
- name
- id
- version
- is_draft
- query
- is_archived
- tags
- last_modified_by_id
- org_id
- options
- query_hash
- description
- latest_query_data_id
- search_vector
- data_source_id
- schedule_failures
- created_at
- user_id
metadata=# \d query_*
## query_results
- id
- data
- org_id
- query_hash
- data_source_id
- runtime
- query
- retrieved_at
## query_snippets
- updated_at
- id
- description
- created_at
- user_id
- trigger
- snippet
- org_id

execute query

enter your SQL and semicolon.

metadata=# select count(*) from queries;
+-------+
| count |
+-------+
|  3606 |
+-------+

1 row returned.
Time: 0.0159s

\x pivot result.

metadata=# \x
set pivoted [True]

metadata=# select id, user_id from queries limit 3;
-[RECORD 1]-------
     id: 543
user_id: 40
-[RECORD 2]-------
     id: 717
user_id: 40
-[RECORD 3]-------
     id: 515
user_id: 38


3 rows returned.
Time: 0.0281s

formats

redasql support many formats. \f <format_name> and \x

table format(default)

metadata=# select id, object_id, org_id, created_at from favorites limit 3;

+------+-------------+----------+--------------------------+
|   id |   object_id |   org_id | created_at               |
|------+-------------+----------+--------------------------|
|    2 |         513 |        1 | 2019-05-22T05:30:17.185Z |
|    3 |         514 |        1 | 2019-05-22T05:30:19.031Z |
|    4 |         230 |        1 | 2019-05-22T08:17:12.693Z |
+------+-------------+----------+--------------------------+

3 rows returned.
Time: 0.0219s

table format(pivoted)

metadata=# select id, object_id, org_id, created_at from favorites limit 3;

-[RECORD 1]----------
        id| 2
 object_id| 513
    org_id| 1
created_at| 2019-05-22T05:30:17.185Z
-[RECORD 2]----------
        id| 3
 object_id| 514
    org_id| 1
created_at| 2019-05-22T05:30:19.031Z
-[RECORD 3]----------
        id| 4
 object_id| 230
    org_id| 1
created_at| 2019-05-22T08:17:12.693Z


3 rows returned.
Time: 0.0223s

markdown

metadata=# \f markdown
set formatter [markdown]
metadata=# select id, object_id, org_id, created_at from favorites limit 3;

|   id |   object_id |   org_id | created_at               |
|------|-------------|----------|--------------------------|
|    2 |         513 |        1 | 2019-05-22T05:30:17.185Z |
|    3 |         514 |        1 | 2019-05-22T05:30:19.031Z |
|    4 |         230 |        1 | 2019-05-22T08:17:12.693Z |

3 rows returned.
Time: 0.0207s

markdown(pivoted)

metadata=# select id, object_id, org_id, created_at from favorites limit 3;

| colum_name   | value                    |
|--------------|--------------------------|
| created_at   | 2019-05-22T05:30:17.185Z |
| org_id       | 1                        |
| id           | 2                        |
| object_id    | 513                      |
| -----        | -----                    |
| created_at   | 2019-05-22T05:30:19.031Z |
| org_id       | 1                        |
| id           | 3                        |
| object_id    | 514                      |
| -----        | -----                    |
| created_at   | 2019-05-22T08:17:12.693Z |
| org_id       | 1                        |
| id           | 4                        |
| object_id    | 230                      |

3 rows returned.
Time: 0.0106s

markdown_with_sql

```sql
select id, object_id, org_id, created_at from favorites limit 3;
``` .

|   id |   object_id |   org_id | created_at               |
|------|-------------|----------|--------------------------|
|    2 |         513 |        1 | 2019-05-22T05:30:17.185Z |
|    3 |         514 |        1 | 2019-05-22T05:30:19.031Z |
|    4 |         230 |        1 | 2019-05-22T08:17:12.693Z |

3 rows returned.
Time: 0.0253s


csv

metadata=# \f csv
set formatter [csv]
metadata=# select id, object_id, org_id, created_at from favorites limit 3;

id,object_id,org_id,created_at
2,513,1,2019-05-22T05:30:17.185Z
3,514,1,2019-05-22T05:30:19.031Z
4,230,1,2019-05-22T08:17:12.693Z

change output type

stdout(default)

result to stdout only.

metadata=# \o stdout
set output [stdout]

stdout_with_clipboard

result to stdout and clipboard.

metadata=# \o stdout_and_clipboard
set output [stdout_and_clipboard]

file

result to stdout and File.

metadata=# \o file /tmp/result.txt
set output [file(/tmp/result.txt)]

query parameters

redash style query parameter {{ name }} is supported. redasql asks the value for each parameter before executing the query. the previous input is used as default on next time.

metadata=# select id, name from queries where id = {{ query_id }};
query_id? > 543
+------+-----------+
|   id | name      |
|------+-----------|
|  543 | New Query |
+------+-----------+

1 row returned.
Time: 0.0144s

if you set values with --variable NAME=VALUE, redasql does not ask and uses them. this also applies to parameters of the query loaded by \l.

$ redasql -d metadata --variable query_id=543

execute single query (-c)

-c executes a single query and exits without entering REPL. -d is required. query parameters must be given by --variable. missing parameters cause an error.

$ redasql -d metadata -c "select id, name from queries where id = {{ query_id }}" --variable query_id=543
+------+-----------+
|   id | name      |
|------+-----------|
|  543 | New Query |
+------+-----------+

1 row returned.
Time: 0.0144s

run sqlfile

\i run local sqlfile.

metadata=# \i test.sql
select count(*) from queries;

+---------+
|   count |
|---------|
|    3876 |
+---------+

1 row returned.
Time: 0.018s

quit

ctrl + D or \q quit redasql.

metadata=# \q                                                                                                                                                                        
Sayonara!

.redasqlrc

if you create ~/.redasqlrc, redasql reads the file at startup and performs initial settings.

Contribution

run test

start up containers (redash, MySQL, postgresql)

unittest necessary redash test server. use docker-compose.yml in ./tests/docker/v{REDAHS_VERSION}

  • 8.0.2.b37747
  • 9.0.0-beta.b49509
  • 10.0.0.b50363
$ cd ./tests/docker/v8.0.2.b37747
$ docker-compose up -d

run test

$ python -m unittest discover -s tests/

Metadata

Release files for redasql 2.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for redasql 2.9.0
File Size Uploaded Provenance Actions
redasql-2.9.0.tar.gz 23.1 kB Without provenance Details for redasql-2.9.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for redasql 2.9.0
File Interpreter ABI Platform Actions
redasql-2.9.0-py3-none-any.whl Python 3 none any Details for redasql-2.9.0-py3-none-any.whl

Total release size: 47.6 kB

Release files / redasql-2.9.0.tar.gz

Download URL redasql-2.9.0.tar.gz
Size 23.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c611983f1997c4e6fbb05f4599f03989a23885783ece317fce590ea9c7cf4889
BLAKE2b-256 checksum
How to use checksums
db2655533590c21ad07a0203fde6b4369a6e1e2145b779907439b1bc3b9afaff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.15.1 Linux/7.0.0-1017-azure

Release files / redasql-2.9.0-py3-none-any.whl

Download URL redasql-2.9.0-py3-none-any.whl
Size 24.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d82c98d39092c7659f31a7afe91732121929d23e04f04cd15ae7e79ba4503940
BLAKE2b-256 checksum
How to use checksums
68927edec4ee3c7366ef9c2e57544c5fa5bbdbba62965fc7c77bb96feeb59a2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.15.1 Linux/7.0.0-1017-azure

Security for redasql 2.9.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page