meilisearch-python-sdk 5.0.2__py3-none-any.whl → 5.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of meilisearch-python-sdk might be problematic. Click here for more details.

@@ -117,10 +117,10 @@ class BaseClient:
117
117
  >>>
118
118
  >>> expires_at = datetime.now(tz=timezone.utc) + timedelta(days=7)
119
119
  >>>
120
- >>> client = Client("http://localhost.com", "masterKey")
121
- >>> token = client.generate_tenant_token(
122
- >>> search_rules = ["*"], api_key=api_key, expires_at=expires_at
123
- >>> )
120
+ >>> with Client("http://localhost.com", "masterKey") as client:
121
+ >>> token = client.generate_tenant_token(
122
+ >>> search_rules = ["*"], api_key=api_key, expires_at=expires_at
123
+ >>> )
124
124
  """
125
125
  if isinstance(search_rules, dict) and search_rules.get("indexes"):
126
126
  for index in search_rules["indexes"]:
@@ -1293,6 +1293,24 @@ class Client(BaseClient):
1293
1293
 
1294
1294
  self._http_requests = HttpRequests(self.http_client, json_handler=self.json_handler)
1295
1295
 
1296
+ def __enter__(self) -> Self:
1297
+ return self
1298
+
1299
+ def __exit__(
1300
+ self,
1301
+ et: type[BaseException] | None,
1302
+ ev: type[BaseException] | None,
1303
+ traceback: TracebackType | None,
1304
+ ) -> None:
1305
+ self.close()
1306
+
1307
+ def close(self) -> None:
1308
+ """Closes the client.
1309
+
1310
+ This only needs to be used if the client was not created with a context manager.
1311
+ """
1312
+ self.http_client.close()
1313
+
1296
1314
  def add_or_update_networks(self, *, network: Network) -> Network:
1297
1315
  """Set or update remote networks.
1298
1316
 
@@ -1318,8 +1336,8 @@ class Client(BaseClient):
1318
1336
  >>> "remote_2": {"url": "http://localhost:7720", "searchApiKey": "xxxx"},
1319
1337
  >>> },
1320
1338
  >>> )
1321
- >>> client = Client("http://localhost.com", "masterKey")
1322
- >>> response = client.add_or_update_networks(network=network)
1339
+ >>> with Client("http://localhost.com", "masterKey") as client:
1340
+ >>> response = client.add_or_update_networks(network=network)
1323
1341
  """
1324
1342
  response = self._http_requests.patch(
1325
1343
  "network", network.model_dump(by_alias=True, exclude_none=True)
@@ -1341,8 +1359,8 @@ class Client(BaseClient):
1341
1359
  >>> from meilisearch_python_sdk import AsyncClient
1342
1360
  >>>
1343
1361
  >>>
1344
- >>> client = Client("http://localhost.com", "masterKey")
1345
- >>> response = client.get_networks()
1362
+ >>> with Client("http://localhost.com", "masterKey") as client:
1363
+ >>> response = client.get_networks()
1346
1364
  """
1347
1365
  response = self._http_requests.get("network")
1348
1366
 
@@ -1360,8 +1378,8 @@ class Client(BaseClient):
1360
1378
 
1361
1379
  Examples:
1362
1380
  >>> from meilisearch_python_sdk import Client
1363
- >>> client = Client("http://localhost.com", "masterKey")
1364
- >>> webhooks = client.get_webhooks()
1381
+ >>> with Client("http://localhost.com", "masterKey") as client:
1382
+ >>> webhooks = client.get_webhooks()
1365
1383
  """
1366
1384
  response = self._http_requests.get("webhooks")
1367
1385
 
@@ -1382,8 +1400,8 @@ class Client(BaseClient):
1382
1400
 
1383
1401
  Examples:
1384
1402
  >>> from meilisearch_python_sdk import Client
1385
- >>> client = Client("http://localhost.com", "masterKey")
1386
- >>> webhook = client.get_webhook("abc-123")
1403
+ >>> with Client("http://localhost.com", "masterKey"):
1404
+ >>> webhook = client.get_webhook("abc-123")
1387
1405
  """
1388
1406
  response = self._http_requests.get(f"webhooks/{uuid}")
1389
1407
 
@@ -1405,12 +1423,12 @@ class Client(BaseClient):
1405
1423
  Examples:
1406
1424
  >>> from meilisearch_python_sdk import Client
1407
1425
  >>> from meilisearch_python_sdk.models.webhook import WebhookCreate
1408
- >>> client = Client("http://localhost.com", "masterKey")
1409
- >>> webhook_config = WebhookCreate(
1410
- >>> url="https://example.com/webhook",
1411
- >>> headers={"Authorization": "Bearer token"}
1412
- >>> )
1413
- >>> webhook = client.create_webhook(webhook_config)
1426
+ >>> with Client("http://localhost.com", "masterKey") as client:
1427
+ >>> webhook_config = WebhookCreate(
1428
+ >>> url="https://example.com/webhook",
1429
+ >>> headers={"Authorization": "Bearer token"}
1430
+ >>> )
1431
+ >>> webhook = client.create_webhook(webhook_config)
1414
1432
  """
1415
1433
  response = self._http_requests.post(
1416
1434
  "webhooks", webhook.model_dump(by_alias=True, exclude_none=True)
@@ -1435,9 +1453,9 @@ class Client(BaseClient):
1435
1453
  Examples:
1436
1454
  >>> from meilisearch_python_sdk import Client
1437
1455
  >>> from meilisearch_python_sdk.models.webhook import WebhookUpdate
1438
- >>> client = Client("http://localhost.com", "masterKey")
1439
- >>> webhook_update = WebhookUpdate(url="https://example.com/new-webhook")
1440
- >>> webhook = client.update_webhook("abc-123", webhook_update)
1456
+ >>> with Client("http://localhost.com", "masterKey") as client:
1457
+ >>> webhook_update = WebhookUpdate(url="https://example.com/new-webhook")
1458
+ >>> webhook = client.update_webhook("abc-123", webhook_update)
1441
1459
  """
1442
1460
  response = self._http_requests.patch(
1443
1461
  f"webhooks/{uuid}", webhook.model_dump(by_alias=True, exclude_none=True)
@@ -1460,8 +1478,8 @@ class Client(BaseClient):
1460
1478
 
1461
1479
  Examples:
1462
1480
  >>> from meilisearch_python_sdk import Client
1463
- >>> client = Client("http://localhost.com", "masterKey")
1464
- >>> client.delete_webhook("abc-123")
1481
+ >>> with Client("http://localhost.com", "masterKey") as client:
1482
+ >>> client.delete_webhook("abc-123")
1465
1483
  """
1466
1484
  response = self._http_requests.delete(f"webhooks/{uuid}")
1467
1485
  return response.status_code
@@ -1478,8 +1496,8 @@ class Client(BaseClient):
1478
1496
 
1479
1497
  Examples
1480
1498
  >>> from meilisearch_python_sdk import Client
1481
- >>> client = Client("http://localhost.com", "masterKey")
1482
- >>> client.create_dump()
1499
+ >>> with Client("http://localhost.com", "masterKey") as client:
1500
+ >>> client.create_dump()
1483
1501
  """
1484
1502
  response = self._http_requests.post("dumps")
1485
1503
 
@@ -1525,8 +1543,8 @@ class Client(BaseClient):
1525
1543
 
1526
1544
  Examples
1527
1545
  >>> from meilisearch_python_sdk import Client
1528
- >>> client = Client("http://localhost.com", "masterKey")
1529
- >>> index = client.create_index("movies")
1546
+ >>> with Client("http://localhost.com", "masterKey") as client:
1547
+ >>> index = client.create_index("movies")
1530
1548
  """
1531
1549
  return Index.create(
1532
1550
  self.http_client,
@@ -1552,8 +1570,8 @@ class Client(BaseClient):
1552
1570
 
1553
1571
  Examples
1554
1572
  >>> from meilisearch_python_sdk import Client
1555
- >>> client = Client("http://localhost.com", "masterKey")
1556
- >>> client.create_snapshot()
1573
+ >>> with Client("http://localhost.com", "masterKey") as client:
1574
+ >>> client.create_snapshot()
1557
1575
  """
1558
1576
  response = self._http_requests.post("snapshots")
1559
1577
 
@@ -1574,8 +1592,8 @@ class Client(BaseClient):
1574
1592
 
1575
1593
  Examples
1576
1594
  >>> from meilisearch_python_sdk import Client
1577
- >>> client = Client("http://localhost.com", "masterKey")
1578
- >>> client.delete_index_if_exists()
1595
+ >>> with Client("http://localhost.com", "masterKey") as client:
1596
+ >>> client.delete_index_if_exists()
1579
1597
  """
1580
1598
  response = self._http_requests.delete(f"indexes/{uid}")
1581
1599
  status = self.wait_for_task(response.json()["taskUid"], timeout_in_ms=100000)
@@ -1602,8 +1620,8 @@ class Client(BaseClient):
1602
1620
 
1603
1621
  Examples
1604
1622
  >>> from meilisearch_python_sdk import Client
1605
- >>> client = Client("http://localhost.com", "masterKey") as client:
1606
- >>> indexes = client.get_indexes()
1623
+ >>> with Client("http://localhost.com", "masterKey") as client:
1624
+ >>> indexes = client.get_indexes()
1607
1625
  """
1608
1626
  url = _build_offset_limit_url("indexes", offset, limit)
1609
1627
  response = self._http_requests.get(url)
@@ -1638,8 +1656,8 @@ class Client(BaseClient):
1638
1656
 
1639
1657
  Examples
1640
1658
  >>> from meilisearch_python_sdk import Client
1641
- >>> client = Client("http://localhost.com", "masterKey")
1642
- >>> index = client.get_index()
1659
+ >>> with Client("http://localhost.com", "masterKey") as client:
1660
+ >>> index = client.get_index()
1643
1661
  """
1644
1662
  return Index(self.http_client, uid, json_handler=self.json_handler).fetch_info()
1645
1663
 
@@ -1659,8 +1677,8 @@ class Client(BaseClient):
1659
1677
 
1660
1678
  Examples
1661
1679
  >>> from meilisearch_python_sdk import Client
1662
- >>> client = Client("http://localhost.com", "masterKey")
1663
- >>> index = client.index("movies")
1680
+ >>> with Client("http://localhost.com", "masterKey") as client:
1681
+ >>> index = client.index("movies")
1664
1682
  """
1665
1683
  return Index(self.http_client, uid=uid, plugins=plugins, json_handler=self.json_handler)
1666
1684
 
@@ -1677,8 +1695,8 @@ class Client(BaseClient):
1677
1695
 
1678
1696
  Examples
1679
1697
  >>> from meilisearch_python_sdk import Client
1680
- >>> client = Client("http://localhost.com", "masterKey")
1681
- >>> stats = client.get_all_stats()
1698
+ >>> with Client("http://localhost.com", "masterKey") as client:
1699
+ >>> stats = client.get_all_stats()
1682
1700
  """
1683
1701
  response = self._http_requests.get("stats")
1684
1702
 
@@ -1711,8 +1729,8 @@ class Client(BaseClient):
1711
1729
 
1712
1730
  Examples
1713
1731
  >>> from meilisearch_python_sdk import Client
1714
- >>> client = Client("http://localhost.com", "masterKey")
1715
- >>> index = client.get_or_create_index("movies")
1732
+ >>> with Client("http://localhost.com", "masterKey") as client:
1733
+ >>> index = client.get_or_create_index("movies")
1716
1734
  """
1717
1735
  try:
1718
1736
  index_instance = self.get_index(uid)
@@ -1741,13 +1759,13 @@ class Client(BaseClient):
1741
1759
  Examples
1742
1760
  >>> from meilisearch_python_sdk import Client
1743
1761
  >>> from meilissearch_async_client.models.client import KeyCreate
1744
- >>> client = Client("http://localhost.com", "masterKey")
1745
- >>> key_info = KeyCreate(
1746
- >>> description="My new key",
1747
- >>> actions=["search"],
1748
- >>> indexes=["movies"],
1749
- >>> )
1750
- >>> keys = client.create_key(key_info)
1762
+ >>> with Client("http://localhost.com", "masterKey") as client:
1763
+ >>> key_info = KeyCreate(
1764
+ >>> description="My new key",
1765
+ >>> actions=["search"],
1766
+ >>> indexes=["movies"],
1767
+ >>> )
1768
+ >>> keys = client.create_key(key_info)
1751
1769
  """
1752
1770
  response = self._http_requests.post(
1753
1771
  "keys", self.json_handler.loads(key.model_dump_json(by_alias=True))
@@ -1770,8 +1788,8 @@ class Client(BaseClient):
1770
1788
 
1771
1789
  Examples
1772
1790
  >>> from meilisearch_python_sdk import Client
1773
- >>> client = Client("http://localhost.com", "masterKey")
1774
- >>> client.delete_key("abc123")
1791
+ >>> with Client("http://localhost.com", "masterKey") as client:
1792
+ >>> client.delete_key("abc123")
1775
1793
  """
1776
1794
  response = self._http_requests.delete(f"keys/{key}")
1777
1795
  return response.status_code
@@ -1793,8 +1811,8 @@ class Client(BaseClient):
1793
1811
 
1794
1812
  Examples
1795
1813
  >>> from meilisearch_python_sdk import Client
1796
- >>> client = AsyncClient("http://localhost.com", "masterKey")
1797
- >>> keys = client.get_keys()
1814
+ >>> with Client("http://localhost.com", "masterKey") as client:
1815
+ >>> keys = client.get_keys()
1798
1816
  """
1799
1817
  url = _build_offset_limit_url("keys", offset, limit)
1800
1818
  response = self._http_requests.get(url)
@@ -1816,8 +1834,8 @@ class Client(BaseClient):
1816
1834
 
1817
1835
  Examples
1818
1836
  >>> from meilisearch_python_sdk import Client
1819
- >>> client = Client("http://localhost.com", "masterKey")
1820
- >>> keys = client.get_key("abc123")
1837
+ >>> with Client("http://localhost.com", "masterKey") as client:
1838
+ >>> keys = client.get_key("abc123")
1821
1839
  """
1822
1840
  response = self._http_requests.get(f"keys/{key}")
1823
1841
 
@@ -1840,12 +1858,12 @@ class Client(BaseClient):
1840
1858
  Examples
1841
1859
  >>> from meilisearch_python_sdk import Client
1842
1860
  >>> from meilissearch_async_client.models.client import KeyUpdate
1843
- >>> client = Client("http://localhost.com", "masterKey")
1844
- >>> key_info = KeyUpdate(
1845
- key="abc123",
1846
- >>> indexes=["*"],
1847
- >>> )
1848
- >>> keys = client.update_key(key_info)
1861
+ >>> with Client("http://localhost.com", "masterKey") as client:
1862
+ >>> key_info = KeyUpdate(
1863
+ key="abc123",
1864
+ >>> indexes=["*"],
1865
+ >>> )
1866
+ >>> keys = client.update_key(key_info)
1849
1867
  """
1850
1868
  payload = _build_update_key_payload(key, self.json_handler)
1851
1869
  response = self._http_requests.patch(f"keys/{key.key}", payload)
@@ -1879,12 +1897,12 @@ class Client(BaseClient):
1879
1897
  Examples
1880
1898
  >>> from meilisearch_python_sdk import Client
1881
1899
  >>> from meilisearch_python_sdk.models.search import SearchParams
1882
- >>> client = Client("http://localhost.com", "masterKey")
1883
- >>> queries = [
1884
- >>> SearchParams(index_uid="my_first_index", query"Some search"),
1885
- >>> SearchParams(index_uid="my_second_index", query="Another search")
1886
- >>> ]
1887
- >>> search_results = client.search(queries)
1900
+ >>> with Client("http://localhost.com", "masterKey") as client:
1901
+ >>> queries = [
1902
+ >>> SearchParams(index_uid="my_first_index", query"Some search"),
1903
+ >>> SearchParams(index_uid="my_second_index", query="Another search")
1904
+ >>> ]
1905
+ >>> search_results = client.search(queries)
1888
1906
  """
1889
1907
  url = "multi-search"
1890
1908
  processed_queries = []
@@ -1937,8 +1955,8 @@ class Client(BaseClient):
1937
1955
 
1938
1956
  Examples
1939
1957
  >>> from meilisearch_python_sdk import Client
1940
- >>> client = Client("http://localhost.com", "masterKey")
1941
- >>> index = client.get_raw_index("movies")
1958
+ >>> with Client("http://localhost.com", "masterKey") as client:
1959
+ >>> index = client.get_raw_index("movies")
1942
1960
  """
1943
1961
  response = self.http_client.get(f"indexes/{uid}")
1944
1962
 
@@ -1968,8 +1986,8 @@ class Client(BaseClient):
1968
1986
 
1969
1987
  Examples
1970
1988
  >>> from meilisearch_python_sdk import Client
1971
- >>> client = Client("http://localhost.com", "masterKey")
1972
- >>> index = client.get_raw_indexes()
1989
+ >>> with Client("http://localhost.com", "masterKey") as client:
1990
+ >>> index = client.get_raw_indexes()
1973
1991
  """
1974
1992
  url = _build_offset_limit_url("indexes", offset, limit)
1975
1993
  response = self._http_requests.get(url)
@@ -1991,8 +2009,8 @@ class Client(BaseClient):
1991
2009
 
1992
2010
  Examples
1993
2011
  >>> from meilisearch_python_sdk import Client
1994
- >>> client = Client("http://localhost.com", "masterKey")
1995
- >>> version = client.get_version()
2012
+ >>> with Client("http://localhost.com", "masterKey") as client:
2013
+ >>> version = client.get_version()
1996
2014
  """
1997
2015
  response = self._http_requests.get("version")
1998
2016
 
@@ -2010,8 +2028,8 @@ class Client(BaseClient):
2010
2028
 
2011
2029
  Examples
2012
2030
  >>> from meilisearch_python_sdk import Client
2013
- >>> client = Client("http://localhost.com", "masterKey")
2014
- >>> health = client.get_health()
2031
+ >>> with Client("http://localhost.com", "masterKey") as client:
2032
+ >>> health = client.get_health()
2015
2033
  """
2016
2034
  response = self._http_requests.get("health")
2017
2035
 
@@ -2034,8 +2052,8 @@ class Client(BaseClient):
2034
2052
 
2035
2053
  Examples
2036
2054
  >>> from meilisearch_python_sdk import Client
2037
- >>> client = Client("http://localhost.com", "masterKey")
2038
- >>> index = client.swap_indexes([("index_a", "index_b")])
2055
+ >>> with Client("http://localhost.com", "masterKey") as client:
2056
+ >>> index = client.swap_indexes([("index_a", "index_b")])
2039
2057
  """
2040
2058
  if rename:
2041
2059
  processed_indexes = [{"indexes": x, "rename": True} for x in indexes]
@@ -2118,8 +2136,8 @@ class Client(BaseClient):
2118
2136
  >>> from meilisearch_python_sdk import Client
2119
2137
  >>> from meilisearch_python_sdk.task import cancel_tasks
2120
2138
  >>>
2121
- >>> client = Client("http://localhost.com", "masterKey")
2122
- >>> client.cancel_tasks(uids=[1, 2])
2139
+ >>> with Client("http://localhost.com", "masterKey") as client:
2140
+ >>> client.cancel_tasks(uids=[1, 2])
2123
2141
  """
2124
2142
  return _task.cancel_tasks(
2125
2143
  self.http_client,
@@ -2170,8 +2188,8 @@ class Client(BaseClient):
2170
2188
  Examples
2171
2189
  >>> from meilisearch_python_sdk import Client
2172
2190
  >>>
2173
- >>> client = Client("http://localhost.com", "masterKey")
2174
- >>> client.delete_tasks(client, uids=[1, 2])
2191
+ >>> with Client("http://localhost.com", "masterKey") as client:
2192
+ >>> client.delete_tasks(client, uids=[1, 2])
2175
2193
  """
2176
2194
  return _task.delete_tasks(
2177
2195
  self.http_client,
@@ -2202,8 +2220,8 @@ class Client(BaseClient):
2202
2220
  Examples
2203
2221
  >>> from meilisearch_python_sdk import Client
2204
2222
  >>>
2205
- >>> client = AsyncClient("http://localhost.com", "masterKey")
2206
- >>> get_task(client, 1244)
2223
+ >>> with Client("http://localhost.com", "masterKey") as client:
2224
+ >>> client.get_task(client, 1244)
2207
2225
  """
2208
2226
  return _task.get_task(self.http_client, task_id=task_id)
2209
2227
 
@@ -2233,8 +2251,8 @@ class Client(BaseClient):
2233
2251
  Examples
2234
2252
  >>> from meilisearch_python_sdk import Client
2235
2253
  >>>
2236
- >>> client = Client("http://localhost.com", "masterKey")
2237
- >>> client.get_tasks(client)
2254
+ >>> with Client("http://localhost.com", "masterKey") as client:
2255
+ >>> client.get_tasks(client)
2238
2256
  """
2239
2257
  return _task.get_tasks(self.http_client, index_ids=index_ids, types=types, reverse=reverse)
2240
2258
 
@@ -2272,10 +2290,10 @@ class Client(BaseClient):
2272
2290
  >>> {"id": 1, "title": "Movie 1", "genre": "comedy"},
2273
2291
  >>> {"id": 2, "title": "Movie 2", "genre": "drama"},
2274
2292
  >>> ]
2275
- >>> client = Client("http://localhost.com", "masterKey")
2276
- >>> index = client.index("movies")
2277
- >>> response = await index.add_documents(documents)
2278
- >>> client.wait_for_task(response.update_id)
2293
+ >>> with Client("http://localhost.com", "masterKey") as client:
2294
+ >>> index = client.index("movies")
2295
+ >>> response = await index.add_documents(documents)
2296
+ >>> client.wait_for_task(response.update_id)
2279
2297
  """
2280
2298
  return _task.wait_for_task(
2281
2299
  self.http_client,
@@ -2315,8 +2333,8 @@ class Client(BaseClient):
2315
2333
 
2316
2334
  Examples
2317
2335
  >>> from meilisearch_python_sdk import Client
2318
- >>> client = Client("http://localhost.com", "masterKey")
2319
- >>> index.transfer_documents("https://another-instance.com", api_key="otherMasterKey")
2336
+ >>> with Client("http://localhost.com", "masterKey") as client:
2337
+ >>> index.transfer_documents("https://another-instance.com", api_key="otherMasterKey")
2320
2338
  """
2321
2339
  payload: JsonDict = {"url": url}
2322
2340
 
@@ -1 +1 @@
1
- VERSION = "5.0.2"
1
+ VERSION = "5.2.0"