Skip to content

Commit 13cfefb

Browse files
authored
Merge pull request #1498 from sanders41/experimental-features
Add ability to get and update experimental features
2 parents 7a29182 + 50aa147 commit 13cfefb

File tree

3 files changed

+111
-2
lines changed

3 files changed

+111
-2
lines changed

meilisearch_python_sdk/_client.py

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import TYPE_CHECKING, Any
66

77
import jwt
8+
from camel_converter import dict_to_camel
89
from httpx import AsyncClient as HttpxAsyncClient
910
from httpx import Client as HttpxClient
1011

@@ -1189,7 +1190,7 @@ async def wait_for_task(
11891190
>>> {"id": 1, "title": "Movie 1", "genre": "comedy"},
11901191
>>> {"id": 2, "title": "Movie 2", "genre": "drama"},
11911192
>>> ]
1192-
>>> async with Client("http://localhost.com", "masterKey") as client:
1193+
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
11931194
>>> index = client.index("movies")
11941195
>>> response = await index.add_documents(documents)
11951196
>>> await client.wait_for_task(client, response.update_id)
@@ -1232,7 +1233,7 @@ async def transfer_documents( # pragma: no cover
12321233
12331234
Examples
12341235
>>> from meilisearch_python_sdk import AsyncClient
1235-
>>> async with Client("http://localhost.com", "masterKey") as client:
1236+
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
12361237
>>> await index.transfer_documents(
12371238
>>> "https://another-instance.com", api_key="otherMasterKey"
12381239
>>> )
@@ -1252,6 +1253,52 @@ async def transfer_documents( # pragma: no cover
12521253

12531254
return TaskInfo(**response.json())
12541255

1256+
async def get_experimental_features(self) -> dict[str, bool]:
1257+
"""Gets all experimental features and if they are enabled or not.
1258+
1259+
Returns:
1260+
The status of the experimental features.
1261+
1262+
Raises:
1263+
MeilisearchCommunicationError: If there was an error communicating with the server.
1264+
MeilisearchApiError: If the Meilisearch API returned an error.
1265+
MeilisearchTimeoutError: If the connection times out.
1266+
1267+
Examples
1268+
>>> from meilisearch_python_sdk import AsyncClient
1269+
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
1270+
>>> await index.get_experimental_feature()
1271+
"""
1272+
1273+
response = await self._http_requests.get("/experimental-features")
1274+
return response.json()
1275+
1276+
async def update_experimental_features(self, features: dict[str, bool]) -> dict[str, bool]:
1277+
"""Update the status of an experimental feature.
1278+
1279+
Args:
1280+
features: Dictionary of features to enable/disable. The dictionary keys can be in either
1281+
camel case or snake case, the conversion to the correct type will be handed for you by
1282+
the program. For example {"logsRoute": True} and {"logs_route": True} will both work.
1283+
1284+
Returns:
1285+
The status of the experimental features.
1286+
1287+
Raises:
1288+
MeilisearchCommunicationError: If there was an error communicating with the server.
1289+
MeilisearchApiError: If the Meilisearch API returned an error.
1290+
MeilisearchTimeoutError: If the connection times out.
1291+
1292+
Examples
1293+
>>> from meilisearch_python_sdk import AsyncClient
1294+
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
1295+
>>> await index.update_experimental_features({"logsRoute": True})
1296+
"""
1297+
payload = dict_to_camel(features)
1298+
response = await self._http_requests.patch("/experimental-features", body=payload)
1299+
1300+
return response.json()
1301+
12551302

12561303
class Client(BaseClient):
12571304
"""client to connect to the Meilisearch API."""
@@ -2351,6 +2398,52 @@ def transfer_documents( # pragma: no cover
23512398

23522399
return TaskInfo(**response.json())
23532400

2401+
def get_experimental_features(self) -> dict[str, bool]:
2402+
"""Gets all experimental features and if they are enabled or not.
2403+
2404+
Returns:
2405+
The status of the experimental features.
2406+
2407+
Raises:
2408+
MeilisearchCommunicationError: If there was an error communicating with the server.
2409+
MeilisearchApiError: If the Meilisearch API returned an error.
2410+
MeilisearchTimeoutError: If the connection times out.
2411+
2412+
Examples
2413+
>>> from meilisearch_python_sdk import Client
2414+
>>> with Client("http://localhost.com", "masterKey") as client:
2415+
>>> index.get_experimental_feature()
2416+
"""
2417+
2418+
response = self._http_requests.get("/experimental-features")
2419+
return response.json()
2420+
2421+
def update_experimental_features(self, features: dict[str, bool]) -> dict[str, bool]:
2422+
"""Update the status of an experimental feature.
2423+
2424+
Args:
2425+
features: Dictionary of features to enable/disable. The dictionary keys can be in either
2426+
camel case or snake case, the conversion to the correct type will be handed for you by
2427+
the program. For example {"logsRoute": True} and {"logs_route": True} will both work.
2428+
2429+
Returns:
2430+
The status of the experimental features.
2431+
2432+
Raises:
2433+
MeilisearchCommunicationError: If there was an error communicating with the server.
2434+
MeilisearchApiError: If the Meilisearch API returned an error.
2435+
MeilisearchTimeoutError: If the connection times out.
2436+
2437+
Examples
2438+
>>> from meilisearch_python_sdk import Client
2439+
>>> with Client("http://localhost.com", "masterKey") as client:
2440+
>>> index.update_experimental_features({"logsRoute": True})
2441+
"""
2442+
payload = dict_to_camel(features)
2443+
response = self._http_requests.patch("/experimental-features", body=payload)
2444+
2445+
return response.json()
2446+
23542447

23552448
def _build_offset_limit_url(base: str, offset: int | None, limit: int | None) -> str:
23562449
if offset is not None and limit is not None:

tests/test_async_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,3 +1131,11 @@ async def test_delete_webhook(async_client, webhook):
11311131
status_code = await async_client.delete_webhook(webhook.uuid)
11321132

11331133
assert status_code == 204
1134+
1135+
1136+
async def test_experimental_features(async_client):
1137+
features = await async_client.get_experimental_features()
1138+
assert len(features) >= 1
1139+
key = next(iter(features))
1140+
update = await async_client.update_experimental_features({key: True})
1141+
assert update[key] is True

tests/test_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,3 +1112,11 @@ def test_delete_webhook(client, webhook):
11121112
status_code = client.delete_webhook(webhook.uuid)
11131113

11141114
assert status_code == 204
1115+
1116+
1117+
def test_experimental_features(client):
1118+
features = client.get_experimental_features()
1119+
assert len(features) >= 1
1120+
key = next(iter(features))
1121+
update = client.update_experimental_features({key: True})
1122+
assert update[key] is True

0 commit comments

Comments
 (0)