VisualizationsClient¶
Client for the Kibana Visualizations HTTP API.
Note
The Visualizations HTTP API is in technical preview (added in Kibana 9.4.0) and may change in future releases.
Manages Lens visualizations (metric, XY, pie, gauge, heatmap, tag cloud,
region map, datatable, mosaic, treemap, waffle, legacy metric) through the
/api/visualizations endpoints. Responses use the same {id, data, meta}
envelope as the Dashboards API: data holds the chart
configuration and meta holds timestamps and version information.
All operations support Kibana spaces via the space_id parameter or a
space-scoped client created with client.space("my-space").
- class kibana._sync.client.visualizations.VisualizationsClient(client, default_space_id=None, validate_spaces=True)[source]¶
Bases:
NamespaceClientClient for the Kibana Visualizations HTTP API.
Technical preview in 9.4 (added in 9.4.0). Manages Lens visualizations (metric, XY, pie, gauge, heatmap, tag cloud, region map, datatable, mosaic, treemap, waffle, legacy metric) through the
/api/visualizationsendpoints. Responses use the same{id, data, meta}envelope as the Dashboards API:dataholds the chart configuration andmetaholds timestamps and version information.All operations support Kibana spaces via the
space_idparameter or a space-scoped client created withclient.space("my-space").Example
>>> from kibana import Kibana >>> client = Kibana("http://localhost:5601", api_key="...") >>> >>> # Create a metric visualization >>> created = client.visualizations.create( ... data={ ... "type": "metric", ... "title": "Total log documents", ... "data_source": { ... "type": "data_view_spec", ... "index_pattern": "logs-*", ... }, ... "query": {"expression": "", "language": "kql"}, ... "metrics": [{"type": "primary", "operation": "count"}], ... } ... ) >>> viz_id = created.body["id"] >>> >>> # Search visualizations by title >>> results = client.visualizations.get_all(query="Total log*") >>> print(results.body["meta"]["total"])
Creating Visualizations
Create a Lens visualization with the
create()method. Thedataobject carries the chart type and configuration:from kibana import Kibana client = Kibana("http://localhost:5601", api_key="your_api_key") # Create a metric visualization created = client.visualizations.create( data={ "type": "metric", "title": "Total log documents", "data_source": { "type": "data_view_spec", "index_pattern": "logs-*", }, "query": {"expression": "", "language": "kql"}, "metrics": [{"type": "primary", "operation": "count"}], } ) viz_id = created.body["id"] print(f"Created visualization: {viz_id}")
Retrieving and Searching
# Get a visualization by ID viz = client.visualizations.get(id=viz_id) print(viz.body["data"]["title"]) # Search visualizations by title results = client.visualizations.get_all(query="Total log*") print(f"Total matches: {results.body['meta']['total']}")
Updating and Deleting
# Replace the visualization configuration client.visualizations.update( id=viz_id, data={ "type": "metric", "title": "Total log documents (updated)", "data_source": { "type": "data_view_spec", "index_pattern": "logs-*", }, "query": {"expression": "", "language": "kql"}, "metrics": [{"type": "primary", "operation": "count"}], }, ) # Delete the visualization client.visualizations.delete(id=viz_id)
Space-Scoped Visualizations
# Target a space explicitly viz = client.visualizations.create( data={"type": "metric", "title": "Marketing metric"}, space_id="marketing", ) # Or use a space-scoped client marketing = client.space("marketing") viz = marketing.visualizations.get_all()
- get_all(*, query=None, search_fields=None, fields=None, page=None, per_page=None, space_id=None, validate_spaces=None)[source]¶
Search visualizations.
Technical preview in 9.4. Returns a paginated envelope with a
dataarray of{id, data, meta}items and ametaobject containingpage,per_pageandtotal.- Parameters:
query (str | None) – Text to match against
search_fields. Supports simple query syntax (e.g. trailing*wildcards).search_fields (str | list[str] | None) – Attribute field(s) the
queryis matched against (e.g.["title"]). Note: on live Kibana 9.4.3 this parameter triggers a500 Internal Server Error(server-side bug in the technical preview API); preferqueryalone until fixed upstream.fields (str | list[str] | None) – Attribute field(s) to return in the
datapayload of each result (e.g.["title"]); omit to return the full visualization configuration. Note: on live Kibana 9.4.3 this parameter triggers a500 Internal Server Errorwhenever the search matches existing objects (server-side bug in the technical preview API).page (int | None) – Page number (default 1).
per_page (int | None) – Results per page (default 20, maximum 1000).
space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space validation for this call.
- Returns:
ObjectApiResponse with
data(list of visualizations) andmeta(page,per_page,total).- Raises:
BadRequestError – If a query parameter is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
- Return type:
Example
>>> results = client.visualizations.get_all( ... query="sales*", per_page=10 ... ) >>> for item in results.body["data"]: ... print(item["id"], item["data"]["title"])
- create(*, data, overwrite=None, space_id=None, validate_spaces=None)[source]¶
Create a visualization.
Technical preview in 9.4. The server assigns the visualization ID and returns the created object in the
{id, data, meta}envelope.- Parameters:
data (dict[str, Any]) – Visualization configuration (the Lens API config). Must include
type(one ofmetric,xy,pie,gauge,heatmap,tagcloud,regionmap,datatable,mosaic,treemap,waffleor a legacy metric), adata_source(data view reference or spec), aqueryfilter and the chart-type-specific dimensions (e.g.metricsfor metric charts).overwrite (bool | None) – When True, overwrite an existing object on ID clash.
space_id (str | None) – Optional space ID to create the visualization in.
validate_spaces (bool | None) – Override space validation for this call.
- Returns:
ObjectApiResponse with
id,data(normalized configuration) andmeta(created_at,updated_at,version…).- Raises:
BadRequestError – If the configuration fails schema validation.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
- Return type:
Example
>>> created = client.visualizations.create( ... data={ ... "type": "metric", ... "title": "Order count", ... "data_source": { ... "type": "data_view_spec", ... "index_pattern": "orders-*", ... }, ... "query": {"expression": "", "language": "kql"}, ... "metrics": [{"type": "primary", "operation": "count"}], ... } ... ) >>> print(created.body["id"])
- get(*, id, space_id=None, validate_spaces=None)[source]¶
Get a visualization by ID.
Technical preview in 9.4.
- Parameters:
- Returns:
ObjectApiResponse with
id,data(the visualization configuration) andmeta.- Raises:
NotFoundError – If no visualization exists with the given ID.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
- Return type:
Example
>>> viz = client.visualizations.get(id="my-viz-id") >>> print(viz.body["data"]["title"])
- update(*, id, data, space_id=None, validate_spaces=None)[source]¶
Update (or create with a chosen ID) a visualization.
Technical preview in 9.4. The body fully replaces the stored configuration. If no visualization exists with the given ID the server creates one (upsert; HTTP 201 instead of 200).
- Parameters:
- Returns:
ObjectApiResponse with the updated
id,dataandmeta.- Raises:
BadRequestError – If the configuration fails schema validation.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
- Return type:
Example
>>> updated = client.visualizations.update( ... id="my-viz-id", ... data={ ... "type": "metric", ... "title": "Order count (renamed)", ... "data_source": { ... "type": "data_view_spec", ... "index_pattern": "orders-*", ... }, ... "query": {"expression": "", "language": "kql"}, ... "metrics": [{"type": "primary", "operation": "count"}], ... }, ... ) >>> print(updated.body["data"]["title"])
- delete(*, id, space_id=None, validate_spaces=None)[source]¶
Delete a visualization by ID.
Technical preview in 9.4. Returns HTTP 204 with an empty body on success.
- Parameters:
- Returns:
ObjectApiResponse with an empty body (HTTP 204 No Content).
- Raises:
NotFoundError – If no visualization exists with the given ID.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
- Return type:
Example
>>> client.visualizations.delete(id="my-viz-id")
- __init__(client, default_space_id=None, validate_spaces=True)¶
Initialize NamespaceClient with optional space support.
AsyncVisualizationsClient¶
Asynchronous version of the VisualizationsClient for use with async/await syntax.
- class kibana._async.client.visualizations.AsyncVisualizationsClient(client, default_space_id=None, validate_spaces=True)[source]¶
Bases:
AsyncNamespaceClientAsync client for the Kibana Visualizations HTTP API.
Technical preview in 9.4 (added in 9.4.0). Manages Lens visualizations (metric, XY, pie, gauge, heatmap, tag cloud, region map, datatable, mosaic, treemap, waffle, legacy metric) through the
/api/visualizationsendpoints. Responses use the same{id, data, meta}envelope as the Dashboards API:dataholds the chart configuration andmetaholds timestamps and version information.All operations support Kibana spaces via the
space_idparameter or a space-scoped client created withclient.space("my-space").Example
>>> from kibana import AsyncKibana >>> client = AsyncKibana("http://localhost:5601", api_key="...") >>> >>> # Create a metric visualization >>> created = await client.visualizations.create( ... data={ ... "type": "metric", ... "title": "Total log documents", ... "data_source": { ... "type": "data_view_spec", ... "index_pattern": "logs-*", ... }, ... "query": {"expression": "", "language": "kql"}, ... "metrics": [{"type": "primary", "operation": "count"}], ... } ... ) >>> viz_id = created.body["id"] >>> >>> # Search visualizations by title >>> results = await client.visualizations.get_all(query="Total log*") >>> print(results.body["meta"]["total"])
Usage
The AsyncVisualizationsClient provides the same methods as VisualizationsClient but all methods are async and must be awaited:
from kibana import AsyncKibana import asyncio async def main(): async with AsyncKibana("http://localhost:5601") as client: # Create a visualization (async) created = await client.visualizations.create( data={ "type": "metric", "title": "Async metric", "data_source": { "type": "data_view_spec", "index_pattern": "logs-*", }, "query": {"expression": "", "language": "kql"}, "metrics": [{"type": "primary", "operation": "count"}], } ) # Search visualizations (async) results = await client.visualizations.get_all(query="Async*") # Delete (async) await client.visualizations.delete(id=created.body["id"]) asyncio.run(main())
- async get_all(*, query=None, search_fields=None, fields=None, page=None, per_page=None, space_id=None, validate_spaces=None)[source]¶
Search visualizations.
Technical preview in 9.4. Returns a paginated envelope with a
dataarray of{id, data, meta}items and ametaobject containingpage,per_pageandtotal.- Parameters:
query (str | None) – Text to match against
search_fields. Supports simple query syntax (e.g. trailing*wildcards).search_fields (str | list[str] | None) – Attribute field(s) the
queryis matched against (e.g.["title"]). Note: on live Kibana 9.4.3 this parameter triggers a500 Internal Server Error(server-side bug in the technical preview API); preferqueryalone until fixed upstream.fields (str | list[str] | None) – Attribute field(s) to return in the
datapayload of each result (e.g.["title"]); omit to return the full visualization configuration. Note: on live Kibana 9.4.3 this parameter triggers a500 Internal Server Errorwhenever the search matches existing objects (server-side bug in the technical preview API).page (int | None) – Page number (default 1).
per_page (int | None) – Results per page (default 20, maximum 1000).
space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space validation for this call.
- Returns:
ObjectApiResponse with
data(list of visualizations) andmeta(page,per_page,total).- Raises:
BadRequestError – If a query parameter is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
- Return type:
Example
>>> results = await client.visualizations.get_all( ... query="sales*", per_page=10 ... ) >>> for item in results.body["data"]: ... print(item["id"], item["data"]["title"])
- async create(*, data, overwrite=None, space_id=None, validate_spaces=None)[source]¶
Create a visualization.
Technical preview in 9.4. The server assigns the visualization ID and returns the created object in the
{id, data, meta}envelope.- Parameters:
data (dict[str, Any]) – Visualization configuration (the Lens API config). Must include
type(one ofmetric,xy,pie,gauge,heatmap,tagcloud,regionmap,datatable,mosaic,treemap,waffleor a legacy metric), adata_source(data view reference or spec), aqueryfilter and the chart-type-specific dimensions (e.g.metricsfor metric charts).overwrite (bool | None) – When True, overwrite an existing object on ID clash.
space_id (str | None) – Optional space ID to create the visualization in.
validate_spaces (bool | None) – Override space validation for this call.
- Returns:
ObjectApiResponse with
id,data(normalized configuration) andmeta(created_at,updated_at,version…).- Raises:
BadRequestError – If the configuration fails schema validation.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
- Return type:
Example
>>> created = await client.visualizations.create( ... data={ ... "type": "metric", ... "title": "Order count", ... "data_source": { ... "type": "data_view_spec", ... "index_pattern": "orders-*", ... }, ... "query": {"expression": "", "language": "kql"}, ... "metrics": [{"type": "primary", "operation": "count"}], ... } ... ) >>> print(created.body["id"])
- async get(*, id, space_id=None, validate_spaces=None)[source]¶
Get a visualization by ID.
Technical preview in 9.4.
- Parameters:
- Returns:
ObjectApiResponse with
id,data(the visualization configuration) andmeta.- Raises:
NotFoundError – If no visualization exists with the given ID.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
- Return type:
Example
>>> viz = await client.visualizations.get(id="my-viz-id") >>> print(viz.body["data"]["title"])
- async update(*, id, data, space_id=None, validate_spaces=None)[source]¶
Update (or create with a chosen ID) a visualization.
Technical preview in 9.4. The body fully replaces the stored configuration. If no visualization exists with the given ID the server creates one (upsert; HTTP 201 instead of 200).
- Parameters:
- Returns:
ObjectApiResponse with the updated
id,dataandmeta.- Raises:
BadRequestError – If the configuration fails schema validation.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
- Return type:
Example
>>> updated = await client.visualizations.update( ... id="my-viz-id", ... data={ ... "type": "metric", ... "title": "Order count (renamed)", ... "data_source": { ... "type": "data_view_spec", ... "index_pattern": "orders-*", ... }, ... "query": {"expression": "", "language": "kql"}, ... "metrics": [{"type": "primary", "operation": "count"}], ... }, ... ) >>> print(updated.body["data"]["title"])
- async delete(*, id, space_id=None, validate_spaces=None)[source]¶
Delete a visualization by ID.
Technical preview in 9.4. Returns HTTP 204 with an empty body on success.
- Parameters:
- Returns:
ObjectApiResponse with an empty body (HTTP 204 No Content).
- Raises:
NotFoundError – If no visualization exists with the given ID.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
- Return type:
Example
>>> await client.visualizations.delete(id="my-viz-id")
- __init__(client, default_space_id=None, validate_spaces=True)¶
Initialize AsyncNamespaceClient with optional space support.