ListsClient¶
Client for the Kibana Security Lists API.
Value lists hold values of a single Elasticsearch type (ip, keyword,
ip_range, …) that Security detection rule exceptions can reference,
e.g. a list of known-bad IP addresses. A value list is a container; the
individual values live in list items, which can be managed one by one or
imported from a newline-separated text file.
Value lists are stored in per-space .lists-<space> and .items-<space>
data streams that must exist before lists can be created. All Lists APIs are
space-scoped: every method accepts an optional space_id to target a
specific space.
- class kibana._sync.client.lists.ListsClient(client, default_space_id=None, validate_spaces=True)[source]¶
Bases:
NamespaceClientClient for the Kibana Security Lists API.
Value lists (
/api/lists) hold values of a single Elasticsearch type (ip,keyword,ip_range, …) that Security detection rule exceptions can reference, e.g. a list of malicious IP addresses. A value list is a container; the individual values live in list items (/api/lists/items), which can be managed one by one or imported from a newline-separated text file.Value lists are stored in per-space
.lists-<space>and.items-<space>data streams that must exist before lists can be created; seecreate_index()andget_index_status().All Lists APIs are space-scoped: every method accepts an optional
space_idto target a specific space (Nonetargets the default space or the space the client is scoped to).Example
>>> from kibana import Kibana >>> client = Kibana("http://localhost:5601", api_key="...") >>> >>> # Make sure the value list data streams exist >>> status = client.lists.get_index_status() >>> >>> # Create a list of bad IPs and add a value >>> created = client.lists.create( ... name="Bad ips", description="Known bad IPs", type="ip" ... ) >>> list_id = created.body["id"] >>> client.lists.create_item(list_id=list_id, value="192.0.2.1") >>> >>> # Export the values and clean up >>> exported = client.lists.export_items(list_id=list_id) >>> client.lists.delete(id=list_id)
Preparing the Value List Data Streams
from kibana import Kibana from kibana.exceptions import NotFoundError client = Kibana("http://localhost:5601", api_key="your_api_key") # Value lists live in per-space data streams; create them once try: status = client.lists.get_index_status() except NotFoundError: client.lists.create_index()
Managing Value Lists
# Create a list of bad IPs created = client.lists.create( name="Bad ips", description="Known bad IP addresses", type="ip", id="bad-ips", ) # Read, replace, patch and search fetched = client.lists.get(id="bad-ips") client.lists.update( id="bad-ips", name="Bad ips - updated", description="Latest bad IPs", _version=fetched.body["_version"], ) client.lists.patch(id="bad-ips", name="Bad ips - patched") found = client.lists.find(filter="type:ip", per_page=50) # Deleting a list also deletes all of its items client.lists.delete(id="bad-ips")
Managing List Items
# Add individual values item = client.lists.create_item( list_id="bad-ips", value="192.0.2.1", refresh="wait_for" ) # Look items up by ID, or by list_id + value (returns an array) by_id = client.lists.get_item(id=item.body["id"]) by_value = client.lists.get_item(list_id="bad-ips", value="192.0.2.1") # Update / patch / delete client.lists.update_item(id=item.body["id"], value="192.0.2.2") client.lists.patch_item(id=item.body["id"], value="192.0.2.3") client.lists.delete_item(list_id="bad-ips", value="192.0.2.3") # Paginate through a list's items page = client.lists.find_items(list_id="bad-ips", per_page=100)
Importing and Exporting Values
# Import values into an existing list (newline-separated upload) client.lists.import_items( file=["198.51.100.1", "198.51.100.2"], list_id="bad-ips", refresh="wait_for", ) # Or create a brand-new list from a file: id/name come from filename client.lists.import_items( file="203.0.113.1\n203.0.113.2\n", type="ip", filename="more-bad-ips.txt", ) # Export values (one entry per item value) exported = client.lists.export_items(list_id="bad-ips") for value in exported: print(value)
Privileges
privileges = client.lists.get_privileges() print(privileges.body["is_authenticated"])
- __init__(client, default_space_id=None, validate_spaces=True)[source]¶
Initialize the ListsClient.
- Parameters:
Example
>>> lists_client = ListsClient(kibana_client)
- create(*, name, description, type, id=None, meta=None, version=None, space_id=None, validate_spaces=None)[source]¶
Create a value list.
POST /api/listsCreates a new value list container. The value list data streams must exist first (see
create_index()); otherwise Kibana responds with a 400 error.- Parameters:
name (str) – Value list’s name.
description (str) – Describes the value list.
type (str) – The Elasticsearch data type of the values the list holds, e.g.
"ip","ip_range","keyword","text","date","integer","long","double", and the other types accepted by the API.id (str | None) – Optional identifier for the list (server-generated when omitted).
meta (dict[str, Any] | None) – Placeholder for metadata about the value list.
version (int | None) – The document version number (defaults to 1).
space_id (str | None) – Optional space ID to create the list in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the created list (
id,name,description,type,version,_version,created_at/created_by,updated_at/updated_by,tie_breaker_id,immutable).- Raises:
BadRequestError – If the payload is invalid or the value list data streams do not exist yet.
ConflictError – If a list with the same
idalready exists.AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> created = client.lists.create( ... name="Bad ips", ... description="Known bad IPs", ... type="ip", ... id="bad-ips", ... ) >>> print(created.body["id"]) bad-ips
- get(*, id, space_id=None, validate_spaces=None)[source]¶
Get value list details.
GET /api/listsGets the details of a value list using the list ID.
- Parameters:
- Returns:
ObjectApiResponse containing the value list.
- Raises:
NotFoundError – If the list does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> fetched = client.lists.get(id="bad-ips") >>> print(fetched.body["type"]) ip
- update(*, id, name, description, _version=None, meta=None, version=None, space_id=None, validate_spaces=None)[source]¶
Update a value list.
PUT /api/listsUpdates a value list using the list
id. The original list is replaced, and all unspecified fields are deleted. You cannot modify theidvalue.- Parameters:
id (str) – Value list’s identifier.
name (str) – Value list’s name.
description (str) – Describes the value list.
_version (str | None) – The version id returned when the list was retrieved. Use it to ensure updates are done against the latest version.
meta (dict[str, Any] | None) – Placeholder for metadata about the value list.
version (int | None) – The document version number.
space_id (str | None) – Optional space ID to update the list in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the updated value list.
- Raises:
NotFoundError – If the list does not exist.
BadRequestError – If the payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> updated = client.lists.update( ... id="bad-ips", ... name="Bad ips - updated", ... description="Latest list of bad IPs", ... ) >>> print(updated.body["name"]) Bad ips - updated
- patch(*, id, name=None, description=None, meta=None, _version=None, version=None, space_id=None, validate_spaces=None)[source]¶
Patch a value list.
PATCH /api/listsUpdates specific fields of an existing list using the list
id; unspecified fields keep their current values.- Parameters:
id (str) – Value list’s identifier.
name (str | None) – New value list’s name.
description (str | None) – New description for the value list.
meta (dict[str, Any] | None) – Placeholder for metadata about the value list.
_version (str | None) – The version id returned when the list was retrieved. Use it to ensure updates are done against the latest version.
version (int | None) – The document version number.
space_id (str | None) – Optional space ID to patch the list in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the patched value list.
- Raises:
NotFoundError – If the list does not exist.
BadRequestError – If the payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> patched = client.lists.patch(id="bad-ips", name="New name") >>> print(patched.body["name"]) New name
- delete(*, id, delete_references=None, ignore_references=None, space_id=None, validate_spaces=None)[source]¶
Delete a value list.
DELETE /api/listsDeletes a value list using the list ID. When you delete a list, all of its list items are also deleted.
- Parameters:
id (str) – Value list’s identifier.
delete_references (bool | None) – Determines whether exception items referencing this value list should be deleted (default: false).
ignore_references (bool | None) – Determines whether to delete the value list without performing any additional checks of where this list may be utilized (default: false).
space_id (str | None) – Optional space ID to delete the list from.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the deleted value list.
- Raises:
NotFoundError – If the list does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> deleted = client.lists.delete(id="bad-ips") >>> print(deleted.body["id"]) bad-ips
- find(*, page=None, per_page=None, sort_field=None, sort_order=None, cursor=None, filter=None, space_id=None, validate_spaces=None)[source]¶
Get value lists.
GET /api/lists/_findGets a paginated subset of value lists. By default, the first page is returned, with 20 results per page.
- Parameters:
page (int | None) – The page number to return.
per_page (int | None) – The number of value lists to return per page.
sort_field (str | None) – Determines which field is used to sort the results.
sort_order (str | None) – Determines the sort order (
"asc"or"desc").cursor (str | None) – Returns the lists that come after the last list returned in the previous call (use the
cursorvalue returned in the previous response).filter (str | None) – Filters the returned results according to the value of the specified field, using the
<field>:<value>syntax.space_id (str | None) – Optional space ID to search in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse with
data(array of lists),page,per_page,totalandcursor.- Raises:
BadRequestError – If the query parameters are invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> found = client.lists.find(filter="type:ip", per_page=50) >>> print(found.body["total"]) 1
- create_index(*, space_id=None, validate_spaces=None)[source]¶
Create value list data streams.
POST /api/lists/indexCreates the
.lists-<space>and.items-<space>data streams that store value lists and their items in the target space. On Kibana 9.4.3 this call is idempotent and responds with{"acknowledged": true}even when the data streams already exist.- Parameters:
- Returns:
ObjectApiResponse with
{"acknowledged": true}.- Raises:
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> result = client.lists.create_index() >>> print(result.body["acknowledged"]) True
- get_index_status(*, space_id=None, validate_spaces=None)[source]¶
Get the status of value list data streams.
GET /api/lists/indexVerifies that the
.lists-<space>and.items-<space>data streams exist in the target space.- Parameters:
- Returns:
ObjectApiResponse with
list_indexandlist_item_indexbooleans.- Raises:
NotFoundError – If the value list data streams do not exist (the error message names the missing data streams).
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> status = client.lists.get_index_status() >>> print(status.body["list_index"], status.body["list_item_index"]) True True
- delete_index(*, space_id=None, validate_spaces=None)[source]¶
Delete value list data streams.
DELETE /api/lists/indexDeletes the
.lists-<space>and.items-<space>data streams of the target space and all value lists and list items stored in them. Use with extreme caution: any detection rule exceptions that reference value lists in this space stop matching.- Parameters:
- Returns:
ObjectApiResponse with
{"acknowledged": true}.- Raises:
NotFoundError – If the value list data streams do not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> result = client.lists.delete_index(space_id="sandbox") >>> print(result.body["acknowledged"]) True
- create_item(*, list_id, value, id=None, meta=None, refresh=None, space_id=None, validate_spaces=None)[source]¶
Create a value list item.
POST /api/lists/itemsCreates a value list item and associates it with the specified value list. All list items in the same list must be the same type; e.g. each list item in an
iplist must define a specific IP address.- Parameters:
list_id (str) – Value list’s identifier.
value (str) – The value used to evaluate exceptions.
id (str | None) – Optional identifier for the item (server-generated when omitted).
meta (dict[str, Any] | None) – Placeholder for metadata about the value list item.
refresh (str | None) – Determines when changes made by the request are made visible to search:
"true","false"or"wait_for".space_id (str | None) – Optional space ID to create the item in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the created list item (
id,list_id,type,value,_version, timestamps).- Raises:
NotFoundError – If the list does not exist.
BadRequestError – If the value is invalid for the list’s type.
ConflictError – If an item with the same
idalready exists.AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> item = client.lists.create_item( ... list_id="bad-ips", value="192.0.2.1", refresh="wait_for" ... ) >>> print(item.body["value"]) 192.0.2.1
- get_item(*, id=None, list_id=None, value=None, space_id=None, validate_spaces=None)[source]¶
Get a value list item.
GET /api/lists/itemsGets the details of a value list item, either by the item’s
idor by the pair of its list’slist_idand the itemvalue.- Parameters:
id (str | None) – Value list item’s identifier. Required if
list_idandvalueare not specified.list_id (str | None) – Value list’s identifier. Required if
idis not specified.value (str | None) – The item value to look up. Required if
idis not specified.space_id (str | None) – Optional space ID to read the item from.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the list item when queried by
id, or an array of matching list items when queried bylist_idandvalue.- Raises:
ValueError – If neither
idnor bothlist_idandvalueare provided.NotFoundError – If the item does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> items = client.lists.get_item( ... list_id="bad-ips", value="192.0.2.1" ... ) >>> print(items.body[0]["value"]) 192.0.2.1
- update_item(*, id, value, _version=None, meta=None, space_id=None, validate_spaces=None)[source]¶
Update a value list item.
PUT /api/lists/itemsUpdates a value list item using the list item ID. The original item is replaced, and all unspecified fields are deleted. You cannot modify the
idvalue.- Parameters:
id (str) – Value list item’s identifier.
value (str) – The new value used to evaluate exceptions.
_version (str | None) – The version id returned when the item was retrieved. Use it to ensure updates are done against the latest version.
meta (dict[str, Any] | None) – Placeholder for metadata about the value list item.
space_id (str | None) – Optional space ID to update the item in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the updated list item.
- Raises:
NotFoundError – If the item does not exist.
BadRequestError – If the payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> updated = client.lists.update_item( ... id="item-id", value="192.0.2.2" ... ) >>> print(updated.body["value"]) 192.0.2.2
- patch_item(*, id, value=None, meta=None, _version=None, refresh=None, space_id=None, validate_spaces=None)[source]¶
Patch a value list item.
PATCH /api/lists/itemsUpdates specific fields of an existing value list item using the item
id; unspecified fields keep their current values.- Parameters:
id (str) – Value list item’s identifier.
value (str | None) – The new value used to evaluate exceptions.
meta (dict[str, Any] | None) – Placeholder for metadata about the value list item.
_version (str | None) – The version id returned when the item was retrieved. Use it to ensure updates are done against the latest version.
refresh (str | None) – Determines when changes made by the request are made visible to search:
"true","false"or"wait_for".space_id (str | None) – Optional space ID to patch the item in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the patched list item.
- Raises:
NotFoundError – If the item does not exist.
BadRequestError – If the payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> patched = client.lists.patch_item( ... id="item-id", value="192.0.2.3" ... ) >>> print(patched.body["value"]) 192.0.2.3
- delete_item(*, id=None, list_id=None, value=None, refresh=None, space_id=None, validate_spaces=None)[source]¶
Delete a value list item.
DELETE /api/lists/itemsDeletes a value list item, either by the item’s
idor by the pair of its list’slist_idand the itemvalue.- Parameters:
id (str | None) – Value list item’s identifier. Required if
list_idandvalueare not specified.list_id (str | None) – Value list’s identifier. Required if
idis not specified.value (str | None) – The item value to delete. Required if
idis not specified.refresh (str | None) – Determines when changes made by the request are made visible to search:
"true","false"or"wait_for"(default:"false").space_id (str | None) – Optional space ID to delete the item from.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the deleted list item when queried by
id, or an array of deleted list items when queried bylist_idandvalue.- Raises:
ValueError – If neither
idnor bothlist_idandvalueare provided.NotFoundError – If the item does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> deleted = client.lists.delete_item( ... list_id="bad-ips", value="192.0.2.1" ... )
- find_items(*, list_id, page=None, per_page=None, sort_field=None, sort_order=None, cursor=None, filter=None, space_id=None, validate_spaces=None)[source]¶
Get value list items.
GET /api/lists/items/_findGets a paginated subset of the value list items of a list. By default, the first page is returned, with 20 results per page.
- Parameters:
list_id (str) – Value list’s identifier.
page (int | None) – The page number to return.
per_page (int | None) – The number of list items to return per page.
sort_field (str | None) – Determines which field is used to sort the results.
sort_order (str | None) – Determines the sort order (
"asc"or"desc").cursor (str | None) – Returns the items that come after the last item returned in the previous call (use the
cursorvalue returned in the previous response).filter (str | None) – Filters the returned results according to the value of the specified field, using the
<field>:<value>syntax.space_id (str | None) – Optional space ID to search in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse with
data(array of list items),page,per_page,totalandcursor.- Raises:
BadRequestError – If the query parameters are invalid.
NotFoundError – If the list does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> found = client.lists.find_items(list_id="bad-ips") >>> print(found.body["total"]) 2
- export_items(*, list_id, space_id=None, validate_spaces=None)[source]¶
Export value list items.
POST /api/lists/items/_exportExports the values of all items of a value list as a newline- separated text file.
Note: Kibana labels the response
application/ndjsonalthough the body is a plain newline-separated dump of the raw values (this matches the formatimport_items()accepts). The parsed response body is a list with one entry per exported value; values that are not valid JSON tokens (e.g. IP addresses) are returned as strings, while values that parse as JSON scalars (e.g. numbers) are returned as their parsed Python type.- Parameters:
- Returns:
Response whose body is the list of exported item values (iterate over it, or join with newlines to rebuild the file).
- Raises:
NotFoundError – If the list does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> exported = client.lists.export_items(list_id="bad-ips") >>> for value in exported: ... print(value) 192.0.2.1 192.0.2.2
- import_items(*, file, list_id=None, type=None, refresh=None, filename='import.txt', space_id=None, validate_spaces=None)[source]¶
Import value list items.
POST /api/lists/items/_importImports a list of item values from a newline-separated
.txtor.csvfile (uploaded asmultipart/form-data). Values are imported into an existing list whenlist_idis given; otherwise a new list is created withidandnametaken fromfilenameand the type given bytype.- Parameters:
file (bytes | str | list[str]) – The file content: raw
bytes/strof newline- separated values, or a list of values which is encoded one-value-per-line automatically.list_id (str | None) – The
idof the list to import items into. Required when importing to an existing list.type (str | None) – The type of the importing list (e.g.
"ip","keyword"). Required when importing a new list, i.e. whenlist_idis not specified.refresh (str | None) – Determines when changes made by the request are made visible to search:
"true","false"or"wait_for".filename (str) – Filename advertised in the multipart upload. When creating a new list it becomes the list’s
idandname.space_id (str | None) – Optional space ID to import into.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the list the items were imported into (the existing list, or the newly created one).
- Raises:
ValueError – If
fileis empty or missing.NotFoundError – If
list_iddoes not exist.BadRequestError – If neither
list_idnortypeis given, or a value is invalid for the list’s type.AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> result = client.lists.import_items( ... file=["192.0.2.1", "192.0.2.2"], ... list_id="bad-ips", ... refresh="wait_for", ... ) >>> print(result.body["id"]) bad-ips
- get_privileges(*, space_id=None, validate_spaces=None)[source]¶
Get value list privileges.
GET /api/lists/privilegesReturns the value list and list item privileges of the calling user, including cluster and index privileges for the underlying data streams.
- Parameters:
- Returns:
ObjectApiResponse with
lists,listItemsandis_authenticated.- Raises:
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> privileges = client.lists.get_privileges() >>> print(privileges.body["is_authenticated"]) True
AsyncListsClient¶
Asynchronous version of the ListsClient for use with async/await syntax.
- class kibana._async.client.lists.AsyncListsClient(client, default_space_id=None, validate_spaces=True)[source]¶
Bases:
AsyncNamespaceClientAsync client for the Kibana Security Lists API.
Value lists (
/api/lists) hold values of a single Elasticsearch type (ip,keyword,ip_range, …) that Security detection rule exceptions can reference, e.g. a list of malicious IP addresses. A value list is a container; the individual values live in list items (/api/lists/items), which can be managed one by one or imported from a newline-separated text file.Value lists are stored in per-space
.lists-<space>and.items-<space>data streams that must exist before lists can be created; seecreate_index()andget_index_status().All Lists APIs are space-scoped: every method accepts an optional
space_idto target a specific space (Nonetargets the default space or the space the client is scoped to).Example
>>> from kibana import AsyncKibana >>> client = AsyncKibana("http://localhost:5601", api_key="...") >>> >>> # Make sure the value list data streams exist >>> status = await client.lists.get_index_status() >>> >>> # Create a list of bad IPs and add a value >>> created = await client.lists.create( ... name="Bad ips", description="Known bad IPs", type="ip" ... ) >>> list_id = created.body["id"] >>> await client.lists.create_item(list_id=list_id, value="192.0.2.1") >>> >>> # Export the values and clean up >>> exported = await client.lists.export_items(list_id=list_id) >>> await client.lists.delete(id=list_id)
Usage
The AsyncListsClient provides the same methods as ListsClient 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 list and add a value (async) created = await client.lists.create( name="Bad ips", description="Known bad IP addresses", type="ip", ) list_id = created.body["id"] await client.lists.create_item( list_id=list_id, value="192.0.2.1", refresh="wait_for" ) # Export and clean up (async) exported = await client.lists.export_items(list_id=list_id) await client.lists.delete(id=list_id) asyncio.run(main())
- __init__(client, default_space_id=None, validate_spaces=True)[source]¶
Initialize the AsyncListsClient.
- Parameters:
client (AsyncKibana) – The parent AsyncKibana client instance to delegate requests to.
default_space_id (str | None) – Optional default space ID for all operations.
validate_spaces (bool) – Whether to validate space existence before space-scoped operations (default: True).
Example
>>> lists_client = AsyncListsClient(kibana_client)
- async create(*, name, description, type, id=None, meta=None, version=None, space_id=None, validate_spaces=None)[source]¶
Create a value list.
POST /api/listsCreates a new value list container. The value list data streams must exist first (see
create_index()); otherwise Kibana responds with a 400 error.- Parameters:
name (str) – Value list’s name.
description (str) – Describes the value list.
type (str) – The Elasticsearch data type of the values the list holds, e.g.
"ip","ip_range","keyword","text","date","integer","long","double", and the other types accepted by the API.id (str | None) – Optional identifier for the list (server-generated when omitted).
meta (dict[str, Any] | None) – Placeholder for metadata about the value list.
version (int | None) – The document version number (defaults to 1).
space_id (str | None) – Optional space ID to create the list in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the created list (
id,name,description,type,version,_version,created_at/created_by,updated_at/updated_by,tie_breaker_id,immutable).- Raises:
BadRequestError – If the payload is invalid or the value list data streams do not exist yet.
ConflictError – If a list with the same
idalready exists.AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> created = await client.lists.create( ... name="Bad ips", ... description="Known bad IPs", ... type="ip", ... id="bad-ips", ... ) >>> print(created.body["id"]) bad-ips
- async get(*, id, space_id=None, validate_spaces=None)[source]¶
Get value list details.
GET /api/listsGets the details of a value list using the list ID.
- Parameters:
- Returns:
ObjectApiResponse containing the value list.
- Raises:
NotFoundError – If the list does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> fetched = await client.lists.get(id="bad-ips") >>> print(fetched.body["type"]) ip
- async update(*, id, name, description, _version=None, meta=None, version=None, space_id=None, validate_spaces=None)[source]¶
Update a value list.
PUT /api/listsUpdates a value list using the list
id. The original list is replaced, and all unspecified fields are deleted. You cannot modify theidvalue.- Parameters:
id (str) – Value list’s identifier.
name (str) – Value list’s name.
description (str) – Describes the value list.
_version (str | None) – The version id returned when the list was retrieved. Use it to ensure updates are done against the latest version.
meta (dict[str, Any] | None) – Placeholder for metadata about the value list.
version (int | None) – The document version number.
space_id (str | None) – Optional space ID to update the list in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the updated value list.
- Raises:
NotFoundError – If the list does not exist.
BadRequestError – If the payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> updated = await client.lists.update( ... id="bad-ips", ... name="Bad ips - updated", ... description="Latest list of bad IPs", ... ) >>> print(updated.body["name"]) Bad ips - updated
- async patch(*, id, name=None, description=None, meta=None, _version=None, version=None, space_id=None, validate_spaces=None)[source]¶
Patch a value list.
PATCH /api/listsUpdates specific fields of an existing list using the list
id; unspecified fields keep their current values.- Parameters:
id (str) – Value list’s identifier.
name (str | None) – New value list’s name.
description (str | None) – New description for the value list.
meta (dict[str, Any] | None) – Placeholder for metadata about the value list.
_version (str | None) – The version id returned when the list was retrieved. Use it to ensure updates are done against the latest version.
version (int | None) – The document version number.
space_id (str | None) – Optional space ID to patch the list in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the patched value list.
- Raises:
NotFoundError – If the list does not exist.
BadRequestError – If the payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> patched = await client.lists.patch(id="bad-ips", name="New name") >>> print(patched.body["name"]) New name
- async delete(*, id, delete_references=None, ignore_references=None, space_id=None, validate_spaces=None)[source]¶
Delete a value list.
DELETE /api/listsDeletes a value list using the list ID. When you delete a list, all of its list items are also deleted.
- Parameters:
id (str) – Value list’s identifier.
delete_references (bool | None) – Determines whether exception items referencing this value list should be deleted (default: false).
ignore_references (bool | None) – Determines whether to delete the value list without performing any additional checks of where this list may be utilized (default: false).
space_id (str | None) – Optional space ID to delete the list from.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the deleted value list.
- Raises:
NotFoundError – If the list does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> deleted = await client.lists.delete(id="bad-ips") >>> print(deleted.body["id"]) bad-ips
- async find(*, page=None, per_page=None, sort_field=None, sort_order=None, cursor=None, filter=None, space_id=None, validate_spaces=None)[source]¶
Get value lists.
GET /api/lists/_findGets a paginated subset of value lists. By default, the first page is returned, with 20 results per page.
- Parameters:
page (int | None) – The page number to return.
per_page (int | None) – The number of value lists to return per page.
sort_field (str | None) – Determines which field is used to sort the results.
sort_order (str | None) – Determines the sort order (
"asc"or"desc").cursor (str | None) – Returns the lists that come after the last list returned in the previous call (use the
cursorvalue returned in the previous response).filter (str | None) – Filters the returned results according to the value of the specified field, using the
<field>:<value>syntax.space_id (str | None) – Optional space ID to search in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse with
data(array of lists),page,per_page,totalandcursor.- Raises:
BadRequestError – If the query parameters are invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> found = await client.lists.find(filter="type:ip", per_page=50) >>> print(found.body["total"]) 1
- async create_index(*, space_id=None, validate_spaces=None)[source]¶
Create value list data streams.
POST /api/lists/indexCreates the
.lists-<space>and.items-<space>data streams that store value lists and their items in the target space. On Kibana 9.4.3 this call is idempotent and responds with{"acknowledged": true}even when the data streams already exist.- Parameters:
- Returns:
ObjectApiResponse with
{"acknowledged": true}.- Raises:
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> result = await client.lists.create_index() >>> print(result.body["acknowledged"]) True
- async get_index_status(*, space_id=None, validate_spaces=None)[source]¶
Get the status of value list data streams.
GET /api/lists/indexVerifies that the
.lists-<space>and.items-<space>data streams exist in the target space.- Parameters:
- Returns:
ObjectApiResponse with
list_indexandlist_item_indexbooleans.- Raises:
NotFoundError – If the value list data streams do not exist (the error message names the missing data streams).
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> status = await client.lists.get_index_status() >>> print(status.body["list_index"], status.body["list_item_index"]) True True
- async delete_index(*, space_id=None, validate_spaces=None)[source]¶
Delete value list data streams.
DELETE /api/lists/indexDeletes the
.lists-<space>and.items-<space>data streams of the target space and all value lists and list items stored in them. Use with extreme caution: any detection rule exceptions that reference value lists in this space stop matching.- Parameters:
- Returns:
ObjectApiResponse with
{"acknowledged": true}.- Raises:
NotFoundError – If the value list data streams do not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> result = await client.lists.delete_index(space_id="sandbox") >>> print(result.body["acknowledged"]) True
- async create_item(*, list_id, value, id=None, meta=None, refresh=None, space_id=None, validate_spaces=None)[source]¶
Create a value list item.
POST /api/lists/itemsCreates a value list item and associates it with the specified value list. All list items in the same list must be the same type; e.g. each list item in an
iplist must define a specific IP address.- Parameters:
list_id (str) – Value list’s identifier.
value (str) – The value used to evaluate exceptions.
id (str | None) – Optional identifier for the item (server-generated when omitted).
meta (dict[str, Any] | None) – Placeholder for metadata about the value list item.
refresh (str | None) – Determines when changes made by the request are made visible to search:
"true","false"or"wait_for".space_id (str | None) – Optional space ID to create the item in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the created list item (
id,list_id,type,value,_version, timestamps).- Raises:
NotFoundError – If the list does not exist.
BadRequestError – If the value is invalid for the list’s type.
ConflictError – If an item with the same
idalready exists.AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> item = await client.lists.create_item( ... list_id="bad-ips", value="192.0.2.1", refresh="wait_for" ... ) >>> print(item.body["value"]) 192.0.2.1
- async get_item(*, id=None, list_id=None, value=None, space_id=None, validate_spaces=None)[source]¶
Get a value list item.
GET /api/lists/itemsGets the details of a value list item, either by the item’s
idor by the pair of its list’slist_idand the itemvalue.- Parameters:
id (str | None) – Value list item’s identifier. Required if
list_idandvalueare not specified.list_id (str | None) – Value list’s identifier. Required if
idis not specified.value (str | None) – The item value to look up. Required if
idis not specified.space_id (str | None) – Optional space ID to read the item from.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the list item when queried by
id, or an array of matching list items when queried bylist_idandvalue.- Raises:
ValueError – If neither
idnor bothlist_idandvalueare provided.NotFoundError – If the item does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> items = await client.lists.get_item( ... list_id="bad-ips", value="192.0.2.1" ... ) >>> print(items.body[0]["value"]) 192.0.2.1
- async update_item(*, id, value, _version=None, meta=None, space_id=None, validate_spaces=None)[source]¶
Update a value list item.
PUT /api/lists/itemsUpdates a value list item using the list item ID. The original item is replaced, and all unspecified fields are deleted. You cannot modify the
idvalue.- Parameters:
id (str) – Value list item’s identifier.
value (str) – The new value used to evaluate exceptions.
_version (str | None) – The version id returned when the item was retrieved. Use it to ensure updates are done against the latest version.
meta (dict[str, Any] | None) – Placeholder for metadata about the value list item.
space_id (str | None) – Optional space ID to update the item in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the updated list item.
- Raises:
NotFoundError – If the item does not exist.
BadRequestError – If the payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> updated = await client.lists.update_item( ... id="item-id", value="192.0.2.2" ... ) >>> print(updated.body["value"]) 192.0.2.2
- async patch_item(*, id, value=None, meta=None, _version=None, refresh=None, space_id=None, validate_spaces=None)[source]¶
Patch a value list item.
PATCH /api/lists/itemsUpdates specific fields of an existing value list item using the item
id; unspecified fields keep their current values.- Parameters:
id (str) – Value list item’s identifier.
value (str | None) – The new value used to evaluate exceptions.
meta (dict[str, Any] | None) – Placeholder for metadata about the value list item.
_version (str | None) – The version id returned when the item was retrieved. Use it to ensure updates are done against the latest version.
refresh (str | None) – Determines when changes made by the request are made visible to search:
"true","false"or"wait_for".space_id (str | None) – Optional space ID to patch the item in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the patched list item.
- Raises:
NotFoundError – If the item does not exist.
BadRequestError – If the payload is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> patched = await client.lists.patch_item( ... id="item-id", value="192.0.2.3" ... ) >>> print(patched.body["value"]) 192.0.2.3
- async delete_item(*, id=None, list_id=None, value=None, refresh=None, space_id=None, validate_spaces=None)[source]¶
Delete a value list item.
DELETE /api/lists/itemsDeletes a value list item, either by the item’s
idor by the pair of its list’slist_idand the itemvalue.- Parameters:
id (str | None) – Value list item’s identifier. Required if
list_idandvalueare not specified.list_id (str | None) – Value list’s identifier. Required if
idis not specified.value (str | None) – The item value to delete. Required if
idis not specified.refresh (str | None) – Determines when changes made by the request are made visible to search:
"true","false"or"wait_for"(default:"false").space_id (str | None) – Optional space ID to delete the item from.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the deleted list item when queried by
id, or an array of deleted list items when queried bylist_idandvalue.- Raises:
ValueError – If neither
idnor bothlist_idandvalueare provided.NotFoundError – If the item does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> deleted = await client.lists.delete_item( ... list_id="bad-ips", value="192.0.2.1" ... )
- async find_items(*, list_id, page=None, per_page=None, sort_field=None, sort_order=None, cursor=None, filter=None, space_id=None, validate_spaces=None)[source]¶
Get value list items.
GET /api/lists/items/_findGets a paginated subset of the value list items of a list. By default, the first page is returned, with 20 results per page.
- Parameters:
list_id (str) – Value list’s identifier.
page (int | None) – The page number to return.
per_page (int | None) – The number of list items to return per page.
sort_field (str | None) – Determines which field is used to sort the results.
sort_order (str | None) – Determines the sort order (
"asc"or"desc").cursor (str | None) – Returns the items that come after the last item returned in the previous call (use the
cursorvalue returned in the previous response).filter (str | None) – Filters the returned results according to the value of the specified field, using the
<field>:<value>syntax.space_id (str | None) – Optional space ID to search in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse with
data(array of list items),page,per_page,totalandcursor.- Raises:
BadRequestError – If the query parameters are invalid.
NotFoundError – If the list does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> found = await client.lists.find_items(list_id="bad-ips") >>> print(found.body["total"]) 2
- async export_items(*, list_id, space_id=None, validate_spaces=None)[source]¶
Export value list items.
POST /api/lists/items/_exportExports the values of all items of a value list as a newline- separated text file.
Note: Kibana labels the response
application/ndjsonalthough the body is a plain newline-separated dump of the raw values (this matches the formatimport_items()accepts). The parsed response body is a list with one entry per exported value; values that are not valid JSON tokens (e.g. IP addresses) are returned as strings, while values that parse as JSON scalars (e.g. numbers) are returned as their parsed Python type.- Parameters:
- Returns:
Response whose body is the list of exported item values (iterate over it, or join with newlines to rebuild the file).
- Raises:
NotFoundError – If the list does not exist.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> exported = await client.lists.export_items(list_id="bad-ips") >>> for value in exported: ... print(value) 192.0.2.1 192.0.2.2
- async import_items(*, file, list_id=None, type=None, refresh=None, filename='import.txt', space_id=None, validate_spaces=None)[source]¶
Import value list items.
POST /api/lists/items/_importImports a list of item values from a newline-separated
.txtor.csvfile (uploaded asmultipart/form-data). Values are imported into an existing list whenlist_idis given; otherwise a new list is created withidandnametaken fromfilenameand the type given bytype.- Parameters:
file (bytes | str | list[str]) – The file content: raw
bytes/strof newline- separated values, or a list of values which is encoded one-value-per-line automatically.list_id (str | None) – The
idof the list to import items into. Required when importing to an existing list.type (str | None) – The type of the importing list (e.g.
"ip","keyword"). Required when importing a new list, i.e. whenlist_idis not specified.refresh (str | None) – Determines when changes made by the request are made visible to search:
"true","false"or"wait_for".filename (str) – Filename advertised in the multipart upload. When creating a new list it becomes the list’s
idandname.space_id (str | None) – Optional space ID to import into.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the list the items were imported into (the existing list, or the newly created one).
- Raises:
ValueError – If
fileis empty or missing.NotFoundError – If
list_iddoes not exist.BadRequestError – If neither
list_idnortypeis given, or a value is invalid for the list’s type.AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> result = await client.lists.import_items( ... file=["192.0.2.1", "192.0.2.2"], ... list_id="bad-ips", ... refresh="wait_for", ... ) >>> print(result.body["id"]) bad-ips
- async get_privileges(*, space_id=None, validate_spaces=None)[source]¶
Get value list privileges.
GET /api/lists/privilegesReturns the value list and list item privileges of the calling user, including cluster and index privileges for the underlying data streams.
- Parameters:
- Returns:
ObjectApiResponse with
lists,listItemsandis_authenticated.- Raises:
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> privileges = await client.lists.get_privileges() >>> print(privileges.body["is_authenticated"]) True