A client library for accessing the Grafana HTTP API, written in Python. It covers most available Grafana HTTP API endpoints and supports Grafana 5.x-9.x, with ongoing compatibility for newer versions, including Grafana 11. The library is actively maintained with a regular release cadence, supporting HTTP Basic authentication and token-based authentication.
pip install --upgrade grafana-clientVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to connect to a Grafana instance using either an API token or HTTP Basic Authentication. It then retrieves the Grafana version and lists existing dashboards. Ensure `GRAFANA_URL` and `GRAFANA_TOKEN` environment variables are set. For API token, `GRAFANA_TOKEN` should be the token itself. For basic auth, it should be in `username:password` format.
Ensure all GrafanaApi initializations include authentication credentials (e.g., `token` or `basic_auth`). If upgrading from a pre-5.0.0 version and calls were unauthenticated, they will now fail.
Update exception handling blocks to catch `GrafanaTimeoutError` instead of `requests.exceptions.Timeout`. If using Python 3.6, upgrade to Python 3.7 or newer.
Always generate Grafana API keys with the least privileged role necessary for your script's operations (e.g., Editor for dashboard management, Admin for user management). Double-check Grafana logs for permission-related errors if an API call seems to succeed but yields unexpected results.
To ensure operations target a specific organization, use an API token (which is tied to one org) or explicitly switch the user's organization context using `GrafanaApi.user.switch_actual_user_organisation` after authentication. Alternatively, bind the `GrafanaApi` instance to a specific organization using `organization_id` parameter, which sends the `X-Grafana-Org-Id` header.
No dependency data recorded yet.