Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
python-version: ${{ env.PYTHON_VERSION }}

- name: mypy type check
run: uv run mypy meilisearch
run: uv run mypy meilisearch tests/types

ruff:
name: ruff
Expand Down
24 changes: 19 additions & 5 deletions meilisearch/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import json
import re
from collections.abc import Iterator, Mapping, MutableMapping, Sequence
from typing import Any
from typing import Any, TypedDict
from urllib import parse

from meilisearch._httprequests import HttpRequests
Expand All @@ -25,6 +25,20 @@
from meilisearch.task import TaskHandler


class _IndexPagination(TypedDict):
limit: int
offset: int
total: int


class IndexesResults(_IndexPagination):
results: list[Index]


class RawIndexesResults(_IndexPagination):
results: list[dict[str, Any]]


class Client:
"""
A client for the Meilisearch API
Expand Down Expand Up @@ -129,7 +143,7 @@ def delete_index(self, uid: str, *, metadata: str | None = None) -> TaskInfo:

return TaskInfo(**task)

def get_indexes(self, parameters: Mapping[str, Any] | None = None) -> dict[str, list[Index]]:
def get_indexes(self, parameters: Mapping[str, Any] | None = None) -> IndexesResults:
"""Get all indexes.

Parameters
Expand All @@ -140,7 +154,7 @@ def get_indexes(self, parameters: Mapping[str, Any] | None = None) -> dict[str,
Returns
-------
indexes:
Dictionary with limit, offset, total and results a list of Index instances.
Dictionary with limit, offset, total and a list of Index instances in results.

Raises
------
Expand All @@ -163,7 +177,7 @@ def get_indexes(self, parameters: Mapping[str, Any] | None = None) -> dict[str,
]
return response

def get_raw_indexes(self, parameters: Mapping[str, Any] | None = None) -> list[dict[str, Any]]:
def get_raw_indexes(self, parameters: Mapping[str, Any] | None = None) -> RawIndexesResults:
"""Get all indexes in dictionary format.

Parameters
Expand All @@ -174,7 +188,7 @@ def get_raw_indexes(self, parameters: Mapping[str, Any] | None = None) -> list[d
Returns
-------
indexes:
Dictionary with limit, offset, total and results a list of indexes in dictionary format. (e.g [{ 'uid': 'movies' 'primaryKey': 'objectID' }])
Dictionary with limit, offset, total and a list of raw index dictionaries in results.

Raises
------
Expand Down
20 changes: 20 additions & 0 deletions tests/types/index_pagination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import Any

from typing_extensions import assert_type

from meilisearch import Client
from meilisearch.index import Index


def check_index_pagination(client: Client) -> None:
indexes = client.get_indexes()
assert_type(indexes["results"], list[Index])
assert_type(indexes["limit"], int)
assert_type(indexes["offset"], int)
assert_type(indexes["total"], int)

raw = client.get_raw_indexes()
assert_type(raw["results"], list[dict[str, Any]])
assert_type(raw["limit"], int)
assert_type(raw["offset"], int)
assert_type(raw["total"], int)
Loading