Skip to content

Update the return type of methods #676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 13, 2023
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
55 changes: 35 additions & 20 deletions meilisearch/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from meilisearch.config import Config
from meilisearch.errors import MeiliSearchError
from meilisearch.index import Index
from meilisearch.models.key import Key, KeysResults
from meilisearch.models.task import TaskInfo
from meilisearch.task import cancel_tasks, delete_tasks, get_task, get_tasks, wait_for_task

Expand Down Expand Up @@ -40,7 +41,7 @@ def __init__(

self.http = HttpRequests(self.config)

def create_index(self, uid: str, options: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
def create_index(self, uid: str, options: Optional[Dict[str, Any]] = None) -> TaskInfo:
"""Create an index.

Parameters
Expand All @@ -52,8 +53,8 @@ def create_index(self, uid: str, options: Optional[Dict[str, Any]] = None) -> Di

Returns
-------
task:
Dictionary containing a task to track the informations about the progress of an asynchronous process.
task_info:
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
https://docs.meilisearch.com/reference/api/tasks.html#get-one-task

Raises
Expand All @@ -63,7 +64,7 @@ def create_index(self, uid: str, options: Optional[Dict[str, Any]] = None) -> Di
"""
return Index.create(self.config, uid, options)

def delete_index(self, uid: str) -> Dict[str, Any]:
def delete_index(self, uid: str) -> TaskInfo:
"""Deletes an index

Parameters
Expand All @@ -73,7 +74,7 @@ def delete_index(self, uid: str) -> Dict[str, Any]:

Returns
-------
task:
task_info:
Dictionary containing a task to track the informations about the progress of an asynchronous process.
https://docs.meilisearch.com/reference/api/tasks.html#get-one-task

Expand All @@ -83,7 +84,9 @@ def delete_index(self, uid: str) -> Dict[str, Any]:
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""

return self.http.delete(f"{self.config.paths.index}/{uid}")
task = self.http.delete(f"{self.config.paths.index}/{uid}")

return TaskInfo(**task)

def get_indexes(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, List[Index]]:
"""Get all indexes.
Expand Down Expand Up @@ -241,7 +244,7 @@ def is_healthy(self) -> bool:
return False
return True

def get_key(self, key_or_uid: str) -> Dict[str, Any]:
def get_key(self, key_or_uid: str) -> Key:
"""Gets information about a specific API key.

Parameters
Expand All @@ -260,9 +263,11 @@ def get_key(self, key_or_uid: str) -> Dict[str, Any]:
MeiliSearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
return self.http.get(f"{self.config.paths.keys}/{key_or_uid}")
key = self.http.get(f"{self.config.paths.keys}/{key_or_uid}")

return Key(**key)

def get_keys(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
def get_keys(self, parameters: Optional[Dict[str, Any]] = None) -> KeysResults:
"""Gets the Meilisearch API keys.

Parameters
Expand All @@ -273,7 +278,7 @@ def get_keys(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, Any
Returns
-------
keys:
Dictionary with limit, offset, total and results a list of dictionaries containing the key information.
API keys.
https://docs.meilisearch.com/reference/api/keys.html#get-keys

Raises
Expand All @@ -283,9 +288,11 @@ def get_keys(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, Any
"""
if parameters is None:
parameters = {}
return self.http.get(f"{self.config.paths.keys}?{parse.urlencode(parameters)}")
keys = self.http.get(f"{self.config.paths.keys}?{parse.urlencode(parameters)}")

def create_key(self, options: Dict[str, Any]) -> Dict[str, Any]:
return KeysResults(**keys)

def create_key(self, options: Dict[str, Any]) -> Key:
"""Creates a new API key.

Parameters
Expand All @@ -299,7 +306,7 @@ def create_key(self, options: Dict[str, Any]) -> Dict[str, Any]:

Returns
-------
keys:
key:
The new API key.
https://docs.meilisearch.com/reference/api/keys.html#get-keys

Expand All @@ -308,9 +315,11 @@ def create_key(self, options: Dict[str, Any]) -> Dict[str, Any]:
MeiliSearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
return self.http.post(f"{self.config.paths.keys}", options)
task = self.http.post(f"{self.config.paths.keys}", options)

return Key(**task)

def update_key(self, key_or_uid: str, options: Dict[str, Any]) -> Dict[str, Any]:
def update_key(self, key_or_uid: str, options: Dict[str, Any]) -> Key:
"""Update an API key.

Parameters
Expand All @@ -333,9 +342,11 @@ def update_key(self, key_or_uid: str, options: Dict[str, Any]) -> Dict[str, Any]
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
url = f"{self.config.paths.keys}/{key_or_uid}"
return self.http.patch(url, options)
key = self.http.patch(url, options)

def delete_key(self, key_or_uid: str) -> Dict[str, int]:
return Key(**key)

def delete_key(self, key_or_uid: str) -> int:
"""Deletes an API key.

Parameters
Expand All @@ -354,7 +365,9 @@ def delete_key(self, key_or_uid: str) -> Dict[str, int]:
MeiliSearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
return self.http.delete(f"{self.config.paths.keys}/{key_or_uid}")
response = self.http.delete(f"{self.config.paths.keys}/{key_or_uid}")

return response.status_code

def get_version(self) -> Dict[str, str]:
"""Get version Meilisearch
Expand Down Expand Up @@ -386,7 +399,7 @@ def version(self) -> Dict[str, str]:
"""
return self.get_version()

def create_dump(self) -> Dict[str, str]:
def create_dump(self) -> TaskInfo:
"""Trigger the creation of a Meilisearch dump.

Returns
Expand All @@ -400,7 +413,9 @@ def create_dump(self) -> Dict[str, str]:
MeiliSearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
"""
return self.http.post(self.config.paths.dumps)
task = self.http.post(self.config.paths.dumps)

return TaskInfo(**task)

def swap_indexes(self, parameters: List[Dict[str, List[str]]]) -> TaskInfo:
"""Swap two indexes.
Expand Down
Loading