grafana / foundation-sdk
A set of tools, types and libraries for building and manipulating Grafana objects.
Installs: 31 239
Dependents: 0
Suggesters: 0
Security: 0
Stars: 216
Watchers: 105
Forks: 14
Open Issues: 27
pkg:composer/grafana/foundation-sdk
- dev-main
- v0.0.11
- v0.0.10
- v0.0.9
- v0.0.8
- v0.0.7
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- dev-renovate/grafana-shared-workflows-digest
- dev-renovate/golang-1.26.0
- dev-renovate/pin-dependencies
- dev-release-preview
- dev-renovate/com.gradleup.shadow-9.x
- dev-add-resource/codeowners
- dev-renovate/lock-file-maintenance
- dev-renovate/major-github-artifact-actions
- dev-renovate/actions-setup-go-6.x
- dev-renovate/github.com-grafana-grafana-foundation-sdk-go-0.x
- dev-renovate/certifi-2026.x
- dev-renovate/mkdocs-material-9.x
- dev-renovate/php83-8.x
- dev-renovate/jackson-monorepo
- dev-renovate/php83packages.phpstan-2.x
- dev-renovate/babel-loader-10.x
- dev-renovate/grafana-tsconfig-2.x
- dev-test-slo-schema
- dev-panels/version-field
- dev-next+cog-v0.0.x
- dev-v11.6.x+cog-v0.0.x
- dev-v11.5.x+cog-v0.0.x
- dev-v11.4.x+cog-v0.0.x
- dev-v11.3.x+cog-v0.0.x
- dev-v11.2.x+cog-v0.0.x
- dev-v11.1.x+cog-v0.0.x
- dev-v11.0.x+cog-v0.0.x
- dev-v10.4.x+cog-v0.0.x
- dev-v10.3.x+cog-v0.0.x
- dev-v10.2.x+cog-v0.0.x
- dev-v10.1.x+cog-v0.0.x
- dev-release-v2
- dev-sandbox/dashboard-v1-v2
- dev-dashboards-v2
- dev-schemas/keep-last-state
- dev-alerting/missing-enum-values
This package is auto-updated.
Last update: 2026-03-03 09:21:46 UTC
README
The Grafana Foundation SDK is a set of types, and builder libraries that let you define Grafana dashboards and other resources using strongly typed code. By writing your resources as code, you can:
- Leverage strong typing: Catch errors at compile time, ensuring more reliable configurations.
- Enhance version control: Track changes seamlessly using standard version control systems like Git.
- Automate deployments: Integrate dashboard provisioning into your CI/CD pipelines for consistent and repeatable setups.
The SDK supports multiple programming languages, including Go, TypeScript, Python, PHP, and Java, so you can choose the one that best fits your development environment.
Note
This SDK is best suited for Grafana >= 12, but will work with Grafana >= 10.
Overview
Here's a quick overview of how the SDK works:
- Builder pattern: The SDK implements the builder pattern to let you define dashboards fluently. You start with a
DashboardBuilder, then add panels, queries, and other components step by step. - Strong typing: Everything in the SDK is strongly typed. This gives you autocompletion in your IDE, catches mistakes early, and helps ensure you're always using valid configuration values.
- Structured options: When a configuration gets complex (like data reduction or display settings), the SDK uses typed option builders to keep things readable and predictable.
- Resources: Multiple resources are supported by the SDK. Dashboards, alerts, …
For example, here is how a dashboard can be built in Go:
package main import ( "encoding/json" "fmt" "github.com/grafana/grafana-foundation-sdk/go/common" "github.com/grafana/grafana-foundation-sdk/go/dashboard" "github.com/grafana/grafana-foundation-sdk/go/prometheus" "github.com/grafana/grafana-foundation-sdk/go/timeseries" "github.com/grafana/grafana-foundation-sdk/go/units" ) func main() { builder := dashboard.NewDashboardBuilder("Sample dashboard"). Uid("generated-from-go"). Tags([]string{"generated", "from", "go"}). Refresh("1m"). Time("now-30m", "now"). Timezone(common.TimeZoneBrowser). WithRow(dashboard.NewRowBuilder("Overview")). WithPanel( timeseries.NewPanelBuilder(). Title("Network Received"). Unit(units.BitsPerSecondSI). Min(0). WithTarget( prometheus.NewDataqueryBuilder(). Expr(`rate(node_network_receive_bytes_total{job="integrations/raspberrypi-node", device!="lo"}[$__rate_interval]) * 8`). LegendFormat("{{ device }}"), ), ) sampleDashboard, err := builder.Build() if err != nil { panic(err) } dashboardJson, err := json.MarshalIndent(sampleDashboard, "", " ") if err != nil { panic(err) } fmt.Println(string(dashboardJson)) }
Note
More examples can be found in the ./examples/ folder.
Publishing resources
After you've defined your resource as code, call the build() function (its
actual name might be slightly different depending on language choice) and
output the result as a JSON.
With the JSON payload, you can:
- Call Grafana's API to programmatically manage the resource.
- Use Grafana CLI to publish the resource from CLI.
Next steps
With the basics of using the Grafana Foundation SDK in mind, here are some possible next steps:
- Explore more features: Check out the full API reference to learn more about what the SDK can do.
- Version control your resources: Store your resources code in Git to track changes over time.
- Automate provisioning with CI/CD: Integrate the SDK into your CI/CD pipeline to deploy dashboards and other resources automatically.
- Explore a more real-world example of using the SDK
Contributing
Contributions are welcome! See CONTRIBUTING.md for more information.
Maturity
The code in this repository should be considered as "public preview". While it is used by Grafana Labs in production, it still is under active development.
Note
Bugs and issues are handled solely by Engineering teams. On-call support or SLAs are not available.