An SDK for the programmatic management of Redash. The main component of the SDK is a client, which is a go wrapper of Redash's REST API.
- Redash Go SDK
- TODO add go get instructions
To initialize the client, you need to know your API key and your Redash address.
The Redash address is your server address without protocol and trailing slash /. For example, if your server is on https://localhost:5000/ then you need localhost:5000 as your host.
After logging in to your Redash instance, go to the profile page:
And then, you can copy your API key in the "Account" tab:
Based on this documentation page.
import (
"fmt"
redashclient "github.com/recolabs/redash-go-sdk"
"github.com/recolabs/redash-go-sdk/gen/client"
)
func main() {
redashClient := redashclient.NewClient(
"{{.API_KEY}}",
&client.TransportConfig{
Host: "{{.HOST_ADDRESS}}",
})
// This part is just an example, not required.
err := redashClient.Administration.Ping()
if err == nil {
fmt.Println("Client successfully initialized! Happy Redash-ing.")
}
}queries, err := redashClient.Queries.List()queryID := 1
queries, err := redashClient.Queries.Get(1)queryStr := "SELECT * FROM postgres.public.table"
queryName := "swagger query"
queryOptions = `{
"parameters": []
}`
query, err := queries.NewQuery(queryName, queryOptions, queryStr, 1)
if err != nil {
fmt.Printf("%v\n", err)
}
responseQuery, err := redashClient.Queries.Add(query)queryID := 1
err := redashClient.Queries.Archive(1)queryID := 1
err := redashClient.Queries.RegenerateQueryAPIKey(1)dataSources, err := redashClient.DataSources.List()dsID := 1
queries, err := redashClient.DataSources.Get(dsID)import redashclient "github.com/recolabs/redash-go-sdk/datasources"
...
dataSourceType := "pg"
dataSourceName := "test"
postgresqlOptions := `{
"dbname": "aa",
"host": "1.1.1.1",
"port": 5432
}`
ds, err := datasources.NewDataSource(dataSourceType,dataSourceName, postgresqlOptions)
if err != nil {
fmt.Printf("%v\n", err)
}
responseQuery, err := redashClient.Queries.Add(ds)queryID := 1
err := redashClient.DataSources.Delete(queryID)import redashclient "github.com/recolabs/redash-go-sdk/datasources"
...
dataSourceType := "pg"
dataSourceName := "test"
postgresqlOptions := `{
"dbname": "aa",
"host": "1.1.1.1",
"port": 5432
}`
ds, err := datasources.NewDataSource(dataSourceType,dataSourceName, postgresqlOptions)
if err != nil {
fmt.Printf("%v\n", err)
}
ds.ID = 1
responseQuery, err := redashClient.Queries.Update(ds)queryID := 1
visualizationID := 1
queryAPIKey := "{API_KEY}"
dataSources, err := redashClient.Visualizations.GetURL(visualizationID, queryID, queryAPIKey)import redashclient "github.com/recolabs/redash-go-sdk/visualizations"
...
visualizationType := "CHART"
visualizationName := "test chart"
visualizationOptions := "{}"
description := "test visualization"
queryID := 1
vis, err := visualizations.NewVisualization(visualizationType, visualizationName, visualizationOptions, queryID)
if err != nil {
fmt.Printf("%v\n", err)
}
responseQuery, err := redashClient.Visualizations.Add(vis)queryID := 1
err := redashClient.Visualizations.Delete(queryID)userID := 1
dataSources, err := redashClient.Users.Get(userID)The SDK has been tested against the following Redash versions:
- 10.1.0
- Easy to use Go client that covers some parts of the API.
- Swagger definition of the Redash API.
- Documentation and examples.
- Earthly-based build pipeline (lint and test).
- Many linters with golangci-lint and good test coverage.
- Data Sources
- Queries
- Visualizations
- Users
Note that some of these resources might only be partially covered.
Install go-swagger, if you have Homebrew or Linuxbrew run this:
brew tap go-swagger/go-swagger
brew install go-swaggerAnd then, to generate the client code from the swagger definition, run:
scripts/generate_client.shFor each go file you'd like to generate tests for, run:
gotests -w -all file.goFor example:
gotests -w -all users/users.goThe tests mock the swagger generated code (to avoid the need for a live Redash server for the tests). In order to generate the mocks, run
for dir in $(ls gen/client);do mockery --dir="gen/client/$dir" --all --output=./mocks/"$dir" --outpkg="$dir"mock; doneInstall godoc.
go install -v golang.org/x/tools/cmd/godoc@latestThen run the following if you're on Linux:
godoc -http=localhost:6060 &
xdg-open http://localhost:6060/pkg/github.com/recolabs/redash-go-sdkMacOS:
godoc -http=localhost:6060 &
open http://localhost:6060/pkg/github.com/recolabs/redash-go-sdkWe use golangci-lint as our linter aggregator. Our
linter configurations are stored in the .golangci.yml file. Run the linters
using this command:
golangci-lint runSimply run go test -v ./....
We needed a way to programmatically control our self-hosted Redash instance from our backend services - we developed a custom dashboard screen in our product and Redash solved many issues for us, so we decided to use it as both the backend and the Data Analyst query development IDE.
Read more about it here


