meilisearch-python-sdk 2.12.1__py3-none-any.whl → 3.0.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.

@@ -1,14 +1,13 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import asyncio
4
- import json
4
+ from collections.abc import Generator, MutableMapping, Sequence
5
5
  from csv import DictReader
6
6
  from datetime import datetime
7
7
  from functools import cached_property, partial
8
8
  from pathlib import Path
9
- from typing import TYPE_CHECKING, Any, Generator, Literal, MutableMapping, Sequence
9
+ from typing import TYPE_CHECKING, Any, Literal
10
10
  from urllib.parse import urlencode
11
- from warnings import warn
12
11
 
13
12
  import aiofiles
14
13
  from camel_converter import to_snake
@@ -16,8 +15,9 @@ from httpx import AsyncClient, Client
16
15
 
17
16
  from meilisearch_python_sdk._http_requests import AsyncHttpRequests, HttpRequests
18
17
  from meilisearch_python_sdk._task import async_wait_for_task, wait_for_task
19
- from meilisearch_python_sdk._utils import is_pydantic_2, iso_to_date_time, use_task_groups
18
+ from meilisearch_python_sdk._utils import iso_to_date_time, use_task_groups
20
19
  from meilisearch_python_sdk.errors import InvalidDocumentError, MeilisearchError
20
+ from meilisearch_python_sdk.json_handler import BuiltinHandler, OrjsonHandler, UjsonHandler
21
21
  from meilisearch_python_sdk.models.documents import DocumentsInfo
22
22
  from meilisearch_python_sdk.models.index import IndexStats
23
23
  from meilisearch_python_sdk.models.search import (
@@ -71,6 +71,7 @@ class _BaseIndex:
71
71
  primary_key: str | None = None,
72
72
  created_at: str | datetime | None = None,
73
73
  updated_at: str | datetime | None = None,
74
+ json_handler: BuiltinHandler | OrjsonHandler | UjsonHandler | None = None,
74
75
  ):
75
76
  self.uid = uid
76
77
  self.primary_key = primary_key
@@ -81,6 +82,7 @@ class _BaseIndex:
81
82
  self._documents_url = f"{self._base_url_with_uid}/documents"
82
83
  self._stats_url = f"{self._base_url_with_uid}/stats"
83
84
  self._settings_url = f"{self._base_url_with_uid}/settings"
85
+ self._json_handler = json_handler if json_handler else BuiltinHandler()
84
86
 
85
87
  def __str__(self) -> str:
86
88
  return f"{type(self).__name__}(uid={self.uid}, primary_key={self.primary_key}, created_at={self.created_at}, updated_at={self.updated_at})"
@@ -110,6 +112,7 @@ class AsyncIndex(_BaseIndex):
110
112
  created_at: str | datetime | None = None,
111
113
  updated_at: str | datetime | None = None,
112
114
  plugins: AsyncIndexPlugins | None = None,
115
+ json_handler: BuiltinHandler | OrjsonHandler | UjsonHandler | None = None,
113
116
  ):
114
117
  """Class initializer.
115
118
 
@@ -122,10 +125,14 @@ class AsyncIndex(_BaseIndex):
122
125
  created_at: The date and time the index was created. Defaults to None.
123
126
  updated_at: The date and time the index was last updated. Defaults to None.
124
127
  plugins: Optional plugins can be provided to extend functionality.
128
+ json_handler: The module to use for json operations. The options are BuiltinHandler
129
+ (uses the json module from the standard library), OrjsonHandler (uses orjson), or
130
+ UjsonHandler (uses ujson). Note that in order use orjson or ujson the corresponding
131
+ extra needs to be included. Default: BuiltinHandler.
125
132
  """
126
- super().__init__(uid, primary_key, created_at, updated_at)
133
+ super().__init__(uid, primary_key, created_at, updated_at, json_handler=json_handler)
127
134
  self.http_client = http_client
128
- self._http_requests = AsyncHttpRequests(http_client)
135
+ self._http_requests = AsyncHttpRequests(http_client, json_handler=self._json_handler)
129
136
  self.plugins = plugins
130
137
 
131
138
  @cached_property
@@ -631,6 +638,7 @@ class AsyncIndex(_BaseIndex):
631
638
  wait: bool = True,
632
639
  timeout_in_ms: int | None = None,
633
640
  plugins: AsyncIndexPlugins | None = None,
641
+ json_handler: BuiltinHandler | OrjsonHandler | UjsonHandler | None = None,
634
642
  ) -> Self:
635
643
  """Creates a new index.
636
644
 
@@ -655,6 +663,10 @@ class AsyncIndex(_BaseIndex):
655
663
  MeilisearchTimeoutError. `None` can also be passed to wait indefinitely. Be aware that
656
664
  if the `None` option is used the wait time could be very long. Defaults to None.
657
665
  plugins: Optional plugins can be provided to extend functionality.
666
+ json_handler: The module to use for json operations. The options are BuiltinHandler
667
+ (uses the json module from the standard library), OrjsonHandler (uses orjson), or
668
+ UjsonHandler (uses ujson). Note that in order use orjson or ujson the corresponding
669
+ extra needs to be included. Default: BuiltinHandler.
658
670
 
659
671
  Returns:
660
672
 
@@ -677,10 +689,13 @@ class AsyncIndex(_BaseIndex):
677
689
  payload = {"primaryKey": primary_key, "uid": uid}
678
690
 
679
691
  url = "indexes"
680
- http_request = AsyncHttpRequests(http_client)
692
+ handler = json_handler if json_handler else BuiltinHandler()
693
+ http_request = AsyncHttpRequests(http_client, json_handler=handler)
681
694
  response = await http_request.post(url, payload)
682
695
  await async_wait_for_task(
683
- http_client, response.json()["taskUid"], timeout_in_ms=timeout_in_ms
696
+ http_client,
697
+ response.json()["taskUid"],
698
+ timeout_in_ms=timeout_in_ms,
684
699
  )
685
700
 
686
701
  index_response = await http_request.get(f"{url}/{uid}")
@@ -692,6 +707,7 @@ class AsyncIndex(_BaseIndex):
692
707
  created_at=index_dict["createdAt"],
693
708
  updated_at=index_dict["updatedAt"],
694
709
  plugins=plugins,
710
+ json_handler=json_handler,
695
711
  )
696
712
 
697
713
  if settings:
@@ -1400,7 +1416,6 @@ class AsyncIndex(_BaseIndex):
1400
1416
  primary_key: str | None = None,
1401
1417
  *,
1402
1418
  compress: bool = False,
1403
- serializer: type[json.JSONEncoder] | None = None,
1404
1419
  ) -> TaskInfo:
1405
1420
  """Add documents to the index.
1406
1421
 
@@ -1410,8 +1425,6 @@ class AsyncIndex(_BaseIndex):
1410
1425
  primary_key: The primary key of the documents. This will be ignored if already set.
1411
1426
  Defaults to None.
1412
1427
  compress: If set to True the data will be sent in gzip format. Defaults to False.
1413
- serializer: A custom JSONEncode to handle serializing fields that the build in
1414
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
1415
1428
 
1416
1429
  Returns:
1417
1430
 
@@ -1469,11 +1482,7 @@ class AsyncIndex(_BaseIndex):
1469
1482
  )
1470
1483
  )
1471
1484
 
1472
- tasks.append(
1473
- self._http_requests.post(
1474
- url, documents, compress=compress, serializer=serializer
1475
- )
1476
- )
1485
+ tasks.append(self._http_requests.post(url, documents, compress=compress))
1477
1486
 
1478
1487
  responses = await asyncio.gather(*tasks)
1479
1488
  result = TaskInfo(**responses[-1].json())
@@ -1509,9 +1518,7 @@ class AsyncIndex(_BaseIndex):
1509
1518
  )
1510
1519
 
1511
1520
  response_coroutine = tg.create_task(
1512
- self._http_requests.post(
1513
- url, documents, compress=compress, serializer=serializer
1514
- )
1521
+ self._http_requests.post(url, documents, compress=compress)
1515
1522
  )
1516
1523
 
1517
1524
  response = await response_coroutine
@@ -1529,9 +1536,7 @@ class AsyncIndex(_BaseIndex):
1529
1536
 
1530
1537
  return result
1531
1538
 
1532
- response = await self._http_requests.post(
1533
- url, documents, compress=compress, serializer=serializer
1534
- )
1539
+ response = await self._http_requests.post(url, documents, compress=compress)
1535
1540
 
1536
1541
  result = TaskInfo(**response.json())
1537
1542
  if self._post_add_documents_plugins:
@@ -1554,7 +1559,6 @@ class AsyncIndex(_BaseIndex):
1554
1559
  batch_size: int = 1000,
1555
1560
  primary_key: str | None = None,
1556
1561
  compress: bool = False,
1557
- serializer: type[json.JSONEncoder] | None = None,
1558
1562
  ) -> list[TaskInfo]:
1559
1563
  """Adds documents in batches to reduce RAM usage with indexing.
1560
1564
 
@@ -1566,8 +1570,6 @@ class AsyncIndex(_BaseIndex):
1566
1570
  primary_key: The primary key of the documents. This will be ignored if already set.
1567
1571
  Defaults to None.
1568
1572
  compress: If set to True the data will be sent in gzip format. Defaults to False.
1569
- serializer: A custom JSONEncode to handle serializing fields that the build in
1570
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
1571
1573
 
1572
1574
  Returns:
1573
1575
 
@@ -1591,16 +1593,14 @@ class AsyncIndex(_BaseIndex):
1591
1593
  """
1592
1594
  if not use_task_groups():
1593
1595
  batches = [
1594
- self.add_documents(x, primary_key, compress=compress, serializer=serializer)
1596
+ self.add_documents(x, primary_key, compress=compress)
1595
1597
  for x in _batch(documents, batch_size)
1596
1598
  ]
1597
1599
  return await asyncio.gather(*batches)
1598
1600
 
1599
1601
  async with asyncio.TaskGroup() as tg: # type: ignore[attr-defined]
1600
1602
  tasks = [
1601
- tg.create_task(
1602
- self.add_documents(x, primary_key, compress=compress, serializer=serializer)
1603
- )
1603
+ tg.create_task(self.add_documents(x, primary_key, compress=compress))
1604
1604
  for x in _batch(documents, batch_size)
1605
1605
  ]
1606
1606
 
@@ -1615,7 +1615,6 @@ class AsyncIndex(_BaseIndex):
1615
1615
  csv_delimiter: str | None = None,
1616
1616
  combine_documents: bool = True,
1617
1617
  compress: bool = False,
1618
- serializer: type[json.JSONEncoder] | None = None,
1619
1618
  ) -> list[TaskInfo]:
1620
1619
  """Load all json files from a directory and add the documents to the index.
1621
1620
 
@@ -1632,8 +1631,6 @@ class AsyncIndex(_BaseIndex):
1632
1631
  combine_documents: If set to True this will combine the documents from all the files
1633
1632
  before indexing them. Defaults to True.
1634
1633
  compress: If set to True the data will be sent in gzip format. Defaults to False.
1635
- serializer: A custom JSONEncode to handle serializing fields that the build in
1636
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
1637
1634
 
1638
1635
  Returns:
1639
1636
 
@@ -1661,7 +1658,9 @@ class AsyncIndex(_BaseIndex):
1661
1658
  all_documents = []
1662
1659
  for path in directory.iterdir():
1663
1660
  if path.suffix == f".{document_type}":
1664
- documents = await _async_load_documents_from_file(path, csv_delimiter)
1661
+ documents = await _async_load_documents_from_file(
1662
+ path, csv_delimiter, json_handler=self._json_handler
1663
+ )
1665
1664
  all_documents.append(documents)
1666
1665
 
1667
1666
  _raise_on_no_documents(all_documents, document_type, directory_path)
@@ -1669,9 +1668,7 @@ class AsyncIndex(_BaseIndex):
1669
1668
  loop = asyncio.get_running_loop()
1670
1669
  combined = await loop.run_in_executor(None, partial(_combine_documents, all_documents))
1671
1670
 
1672
- response = await self.add_documents(
1673
- combined, primary_key, compress=compress, serializer=serializer
1674
- )
1671
+ response = await self.add_documents(combined, primary_key, compress=compress)
1675
1672
 
1676
1673
  return [response]
1677
1674
 
@@ -1679,11 +1676,11 @@ class AsyncIndex(_BaseIndex):
1679
1676
  add_documents = []
1680
1677
  for path in directory.iterdir():
1681
1678
  if path.suffix == f".{document_type}":
1682
- documents = await _async_load_documents_from_file(path, csv_delimiter)
1679
+ documents = await _async_load_documents_from_file(
1680
+ path, csv_delimiter, json_handler=self._json_handler
1681
+ )
1683
1682
  add_documents.append(
1684
- self.add_documents(
1685
- documents, primary_key, compress=compress, serializer=serializer
1686
- )
1683
+ self.add_documents(documents, primary_key, compress=compress)
1687
1684
  )
1688
1685
 
1689
1686
  _raise_on_no_documents(add_documents, document_type, directory_path)
@@ -1705,19 +1702,15 @@ class AsyncIndex(_BaseIndex):
1705
1702
  all_results = []
1706
1703
  for i, path in enumerate(directory.iterdir()):
1707
1704
  if path.suffix == f".{document_type}":
1708
- documents = await _async_load_documents_from_file(path, csv_delimiter)
1705
+ documents = await _async_load_documents_from_file(
1706
+ path, csv_delimiter, json_handler=self._json_handler
1707
+ )
1709
1708
  if i == 0:
1710
- all_results = [
1711
- await self.add_documents(
1712
- documents, compress=compress, serializer=serializer
1713
- )
1714
- ]
1709
+ all_results = [await self.add_documents(documents, compress=compress)]
1715
1710
  else:
1716
1711
  tasks.append(
1717
1712
  tg.create_task(
1718
- self.add_documents(
1719
- documents, primary_key, compress=compress, serializer=serializer
1720
- )
1713
+ self.add_documents(documents, primary_key, compress=compress)
1721
1714
  )
1722
1715
  )
1723
1716
 
@@ -1736,7 +1729,6 @@ class AsyncIndex(_BaseIndex):
1736
1729
  csv_delimiter: str | None = None,
1737
1730
  combine_documents: bool = True,
1738
1731
  compress: bool = False,
1739
- serializer: type[json.JSONEncoder] | None = None,
1740
1732
  ) -> list[TaskInfo]:
1741
1733
  """Load all json files from a directory and add the documents to the index in batches.
1742
1734
 
@@ -1755,8 +1747,6 @@ class AsyncIndex(_BaseIndex):
1755
1747
  combine_documents: If set to True this will combine the documents from all the files
1756
1748
  before indexing them. Defaults to True.
1757
1749
  compress: If set to True the data will be sent in gzip format. Defaults to False.
1758
- serializer: A custom JSONEncode to handle serializing fields that the build in
1759
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
1760
1750
 
1761
1751
  Returns:
1762
1752
 
@@ -1785,7 +1775,7 @@ class AsyncIndex(_BaseIndex):
1785
1775
  for path in directory.iterdir():
1786
1776
  if path.suffix == f".{document_type}":
1787
1777
  documents = await _async_load_documents_from_file(
1788
- path, csv_delimiter=csv_delimiter
1778
+ path, csv_delimiter=csv_delimiter, json_handler=self._json_handler
1789
1779
  )
1790
1780
  all_documents.append(documents)
1791
1781
 
@@ -1799,7 +1789,6 @@ class AsyncIndex(_BaseIndex):
1799
1789
  batch_size=batch_size,
1800
1790
  primary_key=primary_key,
1801
1791
  compress=compress,
1802
- serializer=serializer,
1803
1792
  )
1804
1793
 
1805
1794
  responses: list[TaskInfo] = []
@@ -1807,14 +1796,15 @@ class AsyncIndex(_BaseIndex):
1807
1796
  add_documents = []
1808
1797
  for path in directory.iterdir():
1809
1798
  if path.suffix == f".{document_type}":
1810
- documents = await _async_load_documents_from_file(path, csv_delimiter)
1799
+ documents = await _async_load_documents_from_file(
1800
+ path, csv_delimiter, json_handler=self._json_handler
1801
+ )
1811
1802
  add_documents.append(
1812
1803
  self.add_documents_in_batches(
1813
1804
  documents,
1814
1805
  batch_size=batch_size,
1815
1806
  primary_key=primary_key,
1816
1807
  compress=compress,
1817
- serializer=serializer,
1818
1808
  )
1819
1809
  )
1820
1810
 
@@ -1837,7 +1827,6 @@ class AsyncIndex(_BaseIndex):
1837
1827
  primary_key: str | None = None,
1838
1828
  *,
1839
1829
  compress: bool = False,
1840
- serializer: type[json.JSONEncoder] | None = None,
1841
1830
  ) -> TaskInfo:
1842
1831
  """Add documents to the index from a json file.
1843
1832
 
@@ -1847,8 +1836,6 @@ class AsyncIndex(_BaseIndex):
1847
1836
  primary_key: The primary key of the documents. This will be ignored if already set.
1848
1837
  Defaults to None.
1849
1838
  compress: If set to True the data will be sent in gzip format. Defaults to False.
1850
- serializer: A custom JSONEncode to handle serializing fields that the build in
1851
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
1852
1839
 
1853
1840
  Returns:
1854
1841
 
@@ -1870,12 +1857,12 @@ class AsyncIndex(_BaseIndex):
1870
1857
  >>> index = client.index("movies")
1871
1858
  >>> await index.add_documents_from_file(file_path)
1872
1859
  """
1873
- documents = await _async_load_documents_from_file(file_path)
1874
-
1875
- return await self.add_documents(
1876
- documents, primary_key=primary_key, compress=compress, serializer=serializer
1860
+ documents = await _async_load_documents_from_file(
1861
+ file_path, json_handler=self._json_handler
1877
1862
  )
1878
1863
 
1864
+ return await self.add_documents(documents, primary_key=primary_key, compress=compress)
1865
+
1879
1866
  async def add_documents_from_file_in_batches(
1880
1867
  self,
1881
1868
  file_path: Path | str,
@@ -1884,7 +1871,6 @@ class AsyncIndex(_BaseIndex):
1884
1871
  primary_key: str | None = None,
1885
1872
  csv_delimiter: str | None = None,
1886
1873
  compress: bool = False,
1887
- serializer: type[json.JSONEncoder] | None = None,
1888
1874
  ) -> list[TaskInfo]:
1889
1875
  """Adds documents form a json file in batches to reduce RAM usage with indexing.
1890
1876
 
@@ -1898,8 +1884,6 @@ class AsyncIndex(_BaseIndex):
1898
1884
  csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
1899
1885
  can only be used if the file is a csv file. Defaults to comma.
1900
1886
  compress: If set to True the data will be sent in gzip format. Defaults to False.
1901
- serializer: A custom JSONEncode to handle serializing fields that the build in
1902
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
1903
1887
 
1904
1888
  Returns:
1905
1889
 
@@ -1921,14 +1905,15 @@ class AsyncIndex(_BaseIndex):
1921
1905
  >>> index = client.index("movies")
1922
1906
  >>> await index.add_documents_from_file_in_batches(file_path)
1923
1907
  """
1924
- documents = await _async_load_documents_from_file(file_path, csv_delimiter)
1908
+ documents = await _async_load_documents_from_file(
1909
+ file_path, csv_delimiter, json_handler=self._json_handler
1910
+ )
1925
1911
 
1926
1912
  return await self.add_documents_in_batches(
1927
1913
  documents,
1928
1914
  batch_size=batch_size,
1929
1915
  primary_key=primary_key,
1930
1916
  compress=compress,
1931
- serializer=serializer,
1932
1917
  )
1933
1918
 
1934
1919
  async def add_documents_from_raw_file(
@@ -1938,7 +1923,6 @@ class AsyncIndex(_BaseIndex):
1938
1923
  *,
1939
1924
  csv_delimiter: str | None = None,
1940
1925
  compress: bool = False,
1941
- serializer: type[json.JSONEncoder] | None = None,
1942
1926
  ) -> TaskInfo:
1943
1927
  """Directly send csv or ndjson files to Meilisearch without pre-processing.
1944
1928
 
@@ -1954,8 +1938,6 @@ class AsyncIndex(_BaseIndex):
1954
1938
  csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
1955
1939
  can only be used if the file is a csv file. Defaults to comma.
1956
1940
  compress: If set to True the data will be sent in gzip format. Defaults to False.
1957
- serializer: A custom JSONEncode to handle serializing fields that the build in
1958
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
1959
1941
 
1960
1942
  Returns:
1961
1943
 
@@ -2013,7 +1995,7 @@ class AsyncIndex(_BaseIndex):
2013
1995
  data = await f.read()
2014
1996
 
2015
1997
  response = await self._http_requests.post(
2016
- url, body=data, content_type=content_type, compress=compress, serializer=serializer
1998
+ url, body=data, content_type=content_type, compress=compress
2017
1999
  )
2018
2000
 
2019
2001
  return TaskInfo(**response.json())
@@ -2024,7 +2006,6 @@ class AsyncIndex(_BaseIndex):
2024
2006
  primary_key: str | None = None,
2025
2007
  *,
2026
2008
  compress: bool = False,
2027
- serializer: type[json.JSONEncoder] | None = None,
2028
2009
  ) -> TaskInfo:
2029
2010
  """Update documents in the index.
2030
2011
 
@@ -2034,8 +2015,6 @@ class AsyncIndex(_BaseIndex):
2034
2015
  primary_key: The primary key of the documents. This will be ignored if already set.
2035
2016
  Defaults to None.
2036
2017
  compress: If set to True the data will be sent in gzip format. Defaults to False.
2037
- serializer: A custom JSONEncode to handle serializing fields that the build in
2038
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
2039
2018
 
2040
2019
  Returns:
2041
2020
 
@@ -2130,9 +2109,7 @@ class AsyncIndex(_BaseIndex):
2130
2109
  )
2131
2110
 
2132
2111
  response_coroutine = tg.create_task(
2133
- self._http_requests.put(
2134
- url, documents, compress=compress, serializer=serializer
2135
- )
2112
+ self._http_requests.put(url, documents, compress=compress)
2136
2113
  )
2137
2114
 
2138
2115
  response = await response_coroutine
@@ -2151,9 +2128,7 @@ class AsyncIndex(_BaseIndex):
2151
2128
 
2152
2129
  return result
2153
2130
 
2154
- response = await self._http_requests.put(
2155
- url, documents, compress=compress, serializer=serializer
2156
- )
2131
+ response = await self._http_requests.put(url, documents, compress=compress)
2157
2132
  result = TaskInfo(**response.json())
2158
2133
  if self._post_update_documents_plugins:
2159
2134
  post = await AsyncIndex._run_plugins(
@@ -2175,7 +2150,6 @@ class AsyncIndex(_BaseIndex):
2175
2150
  batch_size: int = 1000,
2176
2151
  primary_key: str | None = None,
2177
2152
  compress: bool = False,
2178
- serializer: type[json.JSONEncoder] | None = None,
2179
2153
  ) -> list[TaskInfo]:
2180
2154
  """Update documents in batches to reduce RAM usage with indexing.
2181
2155
 
@@ -2189,8 +2163,6 @@ class AsyncIndex(_BaseIndex):
2189
2163
  primary_key: The primary key of the documents. This will be ignored if already set.
2190
2164
  Defaults to None.
2191
2165
  compress: If set to True the data will be sent in gzip format. Defaults to False.
2192
- serializer: A custom JSONEncode to handle serializing fields that the build in
2193
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
2194
2166
 
2195
2167
  Returns:
2196
2168
 
@@ -2214,7 +2186,7 @@ class AsyncIndex(_BaseIndex):
2214
2186
  """
2215
2187
  if not use_task_groups():
2216
2188
  batches = [
2217
- self.update_documents(x, primary_key, compress=compress, serializer=serializer)
2189
+ self.update_documents(x, primary_key, compress=compress)
2218
2190
  for x in _batch(documents, batch_size)
2219
2191
  ]
2220
2192
  return await asyncio.gather(*batches)
@@ -2235,7 +2207,6 @@ class AsyncIndex(_BaseIndex):
2235
2207
  csv_delimiter: str | None = None,
2236
2208
  combine_documents: bool = True,
2237
2209
  compress: bool = False,
2238
- serializer: type[json.JSONEncoder] | None = None,
2239
2210
  ) -> list[TaskInfo]:
2240
2211
  """Load all json files from a directory and update the documents.
2241
2212
 
@@ -2252,8 +2223,6 @@ class AsyncIndex(_BaseIndex):
2252
2223
  combine_documents: If set to True this will combine the documents from all the files
2253
2224
  before indexing them. Defaults to True.
2254
2225
  compress: If set to True the data will be sent in gzip format. Defaults to False.
2255
- serializer: A custom JSONEncode to handle serializing fields that the build in
2256
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
2257
2226
 
2258
2227
  Returns:
2259
2228
 
@@ -2281,7 +2250,9 @@ class AsyncIndex(_BaseIndex):
2281
2250
  all_documents = []
2282
2251
  for path in directory.iterdir():
2283
2252
  if path.suffix == f".{document_type}":
2284
- documents = await _async_load_documents_from_file(path, csv_delimiter)
2253
+ documents = await _async_load_documents_from_file(
2254
+ path, csv_delimiter, json_handler=self._json_handler
2255
+ )
2285
2256
  all_documents.append(documents)
2286
2257
 
2287
2258
  _raise_on_no_documents(all_documents, document_type, directory_path)
@@ -2289,20 +2260,18 @@ class AsyncIndex(_BaseIndex):
2289
2260
  loop = asyncio.get_running_loop()
2290
2261
  combined = await loop.run_in_executor(None, partial(_combine_documents, all_documents))
2291
2262
 
2292
- response = await self.update_documents(
2293
- combined, primary_key, compress=compress, serializer=serializer
2294
- )
2263
+ response = await self.update_documents(combined, primary_key, compress=compress)
2295
2264
  return [response]
2296
2265
 
2297
2266
  if not use_task_groups():
2298
2267
  update_documents = []
2299
2268
  for path in directory.iterdir():
2300
2269
  if path.suffix == f".{document_type}":
2301
- documents = await _async_load_documents_from_file(path, csv_delimiter)
2270
+ documents = await _async_load_documents_from_file(
2271
+ path, csv_delimiter, json_handler=self._json_handler
2272
+ )
2302
2273
  update_documents.append(
2303
- self.update_documents(
2304
- documents, primary_key, compress=compress, serializer=serializer
2305
- )
2274
+ self.update_documents(documents, primary_key, compress=compress)
2306
2275
  )
2307
2276
 
2308
2277
  _raise_on_no_documents(update_documents, document_type, directory_path)
@@ -2323,19 +2292,17 @@ class AsyncIndex(_BaseIndex):
2323
2292
  results = []
2324
2293
  for i, path in enumerate(directory.iterdir()):
2325
2294
  if path.suffix == f".{document_type}":
2326
- documents = await _async_load_documents_from_file(path, csv_delimiter)
2295
+ documents = await _async_load_documents_from_file(
2296
+ path, csv_delimiter, json_handler=self._json_handler
2297
+ )
2327
2298
  if i == 0:
2328
2299
  results = [
2329
- await self.update_documents(
2330
- documents, primary_key, compress=compress, serializer=serializer
2331
- )
2300
+ await self.update_documents(documents, primary_key, compress=compress)
2332
2301
  ]
2333
2302
  else:
2334
2303
  tasks.append(
2335
2304
  tg.create_task(
2336
- self.update_documents(
2337
- documents, primary_key, compress=compress, serializer=serializer
2338
- )
2305
+ self.update_documents(documents, primary_key, compress=compress)
2339
2306
  )
2340
2307
  )
2341
2308
 
@@ -2353,7 +2320,6 @@ class AsyncIndex(_BaseIndex):
2353
2320
  csv_delimiter: str | None = None,
2354
2321
  combine_documents: bool = True,
2355
2322
  compress: bool = False,
2356
- serializer: type[json.JSONEncoder] | None = None,
2357
2323
  ) -> list[TaskInfo]:
2358
2324
  """Load all json files from a directory and update the documents.
2359
2325
 
@@ -2372,8 +2338,6 @@ class AsyncIndex(_BaseIndex):
2372
2338
  combine_documents: If set to True this will combine the documents from all the files
2373
2339
  before indexing them. Defaults to True.
2374
2340
  compress: If set to True the data will be sent in gzip format. Defaults to False.
2375
- serializer: A custom JSONEncode to handle serializing fields that the build in
2376
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
2377
2341
 
2378
2342
  Returns:
2379
2343
 
@@ -2401,7 +2365,9 @@ class AsyncIndex(_BaseIndex):
2401
2365
  all_documents = []
2402
2366
  for path in directory.iterdir():
2403
2367
  if path.suffix == f".{document_type}":
2404
- documents = await _async_load_documents_from_file(path, csv_delimiter)
2368
+ documents = await _async_load_documents_from_file(
2369
+ path, csv_delimiter, json_handler=self._json_handler
2370
+ )
2405
2371
  all_documents.append(documents)
2406
2372
 
2407
2373
  _raise_on_no_documents(all_documents, document_type, directory_path)
@@ -2414,7 +2380,6 @@ class AsyncIndex(_BaseIndex):
2414
2380
  batch_size=batch_size,
2415
2381
  primary_key=primary_key,
2416
2382
  compress=compress,
2417
- serializer=serializer,
2418
2383
  )
2419
2384
 
2420
2385
  if not use_task_groups():
@@ -2423,14 +2388,15 @@ class AsyncIndex(_BaseIndex):
2423
2388
  update_documents = []
2424
2389
  for path in directory.iterdir():
2425
2390
  if path.suffix == f".{document_type}":
2426
- documents = await _async_load_documents_from_file(path, csv_delimiter)
2391
+ documents = await _async_load_documents_from_file(
2392
+ path, csv_delimiter, json_handler=self._json_handler
2393
+ )
2427
2394
  update_documents.append(
2428
2395
  self.update_documents_in_batches(
2429
2396
  documents,
2430
2397
  batch_size=batch_size,
2431
2398
  primary_key=primary_key,
2432
2399
  compress=compress,
2433
- serializer=serializer,
2434
2400
  )
2435
2401
  )
2436
2402
 
@@ -2452,14 +2418,15 @@ class AsyncIndex(_BaseIndex):
2452
2418
  tasks = []
2453
2419
  for i, path in enumerate(directory.iterdir()):
2454
2420
  if path.suffix == f".{document_type}":
2455
- documents = await _async_load_documents_from_file(path, csv_delimiter)
2421
+ documents = await _async_load_documents_from_file(
2422
+ path, csv_delimiter, json_handler=self._json_handler
2423
+ )
2456
2424
  if i == 0:
2457
2425
  results = await self.update_documents_in_batches(
2458
2426
  documents,
2459
2427
  batch_size=batch_size,
2460
2428
  primary_key=primary_key,
2461
2429
  compress=compress,
2462
- serializer=serializer,
2463
2430
  )
2464
2431
  else:
2465
2432
  tasks.append(
@@ -2469,7 +2436,6 @@ class AsyncIndex(_BaseIndex):
2469
2436
  batch_size=batch_size,
2470
2437
  primary_key=primary_key,
2471
2438
  compress=compress,
2472
- serializer=serializer,
2473
2439
  )
2474
2440
  )
2475
2441
  )
@@ -2485,7 +2451,6 @@ class AsyncIndex(_BaseIndex):
2485
2451
  csv_delimiter: str | None = None,
2486
2452
  *,
2487
2453
  compress: bool = False,
2488
- serializer: type[json.JSONEncoder] | None = None,
2489
2454
  ) -> TaskInfo:
2490
2455
  """Add documents in the index from a json file.
2491
2456
 
@@ -2497,8 +2462,6 @@ class AsyncIndex(_BaseIndex):
2497
2462
  csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
2498
2463
  can only be used if the file is a csv file. Defaults to comma.
2499
2464
  compress: If set to True the data will be sent in gzip format. Defaults to False.
2500
- serializer: A custom JSONEncode to handle serializing fields that the build in
2501
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
2502
2465
 
2503
2466
  Returns:
2504
2467
 
@@ -2518,12 +2481,12 @@ class AsyncIndex(_BaseIndex):
2518
2481
  >>> index = client.index("movies")
2519
2482
  >>> await index.update_documents_from_file(file_path)
2520
2483
  """
2521
- documents = await _async_load_documents_from_file(file_path, csv_delimiter)
2522
-
2523
- return await self.update_documents(
2524
- documents, primary_key=primary_key, compress=compress, serializer=serializer
2484
+ documents = await _async_load_documents_from_file(
2485
+ file_path, csv_delimiter, json_handler=self._json_handler
2525
2486
  )
2526
2487
 
2488
+ return await self.update_documents(documents, primary_key=primary_key, compress=compress)
2489
+
2527
2490
  async def update_documents_from_file_in_batches(
2528
2491
  self,
2529
2492
  file_path: Path | str,
@@ -2531,7 +2494,6 @@ class AsyncIndex(_BaseIndex):
2531
2494
  batch_size: int = 1000,
2532
2495
  primary_key: str | None = None,
2533
2496
  compress: bool = False,
2534
- serializer: type[json.JSONEncoder] | None = None,
2535
2497
  ) -> list[TaskInfo]:
2536
2498
  """Updates documents form a json file in batches to reduce RAM usage with indexing.
2537
2499
 
@@ -2543,8 +2505,6 @@ class AsyncIndex(_BaseIndex):
2543
2505
  primary_key: The primary key of the documents. This will be ignored if already set.
2544
2506
  Defaults to None.
2545
2507
  compress: If set to True the data will be sent in gzip format. Defaults to False.
2546
- serializer: A custom JSONEncode to handle serializing fields that the build in
2547
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
2548
2508
 
2549
2509
  Returns:
2550
2510
 
@@ -2564,14 +2524,15 @@ class AsyncIndex(_BaseIndex):
2564
2524
  >>> index = client.index("movies")
2565
2525
  >>> await index.update_documents_from_file_in_batches(file_path)
2566
2526
  """
2567
- documents = await _async_load_documents_from_file(file_path)
2527
+ documents = await _async_load_documents_from_file(
2528
+ file_path, json_handler=self._json_handler
2529
+ )
2568
2530
 
2569
2531
  return await self.update_documents_in_batches(
2570
2532
  documents,
2571
2533
  batch_size=batch_size,
2572
2534
  primary_key=primary_key,
2573
2535
  compress=compress,
2574
- serializer=serializer,
2575
2536
  )
2576
2537
 
2577
2538
  async def update_documents_from_raw_file(
@@ -2581,7 +2542,6 @@ class AsyncIndex(_BaseIndex):
2581
2542
  csv_delimiter: str | None = None,
2582
2543
  *,
2583
2544
  compress: bool = False,
2584
- serializer: type[json.JSONEncoder] | None = None,
2585
2545
  ) -> TaskInfo:
2586
2546
  """Directly send csv or ndjson files to Meilisearch without pre-processing.
2587
2547
 
@@ -2597,8 +2557,6 @@ class AsyncIndex(_BaseIndex):
2597
2557
  csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
2598
2558
  can only be used if the file is a csv file. Defaults to comma.
2599
2559
  compress: If set to True the data will be sent in gzip format. Defaults to False.
2600
- serializer: A custom JSONEncode to handle serializing fields that the build in
2601
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
2602
2560
 
2603
2561
  Returns:
2604
2562
 
@@ -2656,7 +2614,7 @@ class AsyncIndex(_BaseIndex):
2656
2614
  data = await f.read()
2657
2615
 
2658
2616
  response = await self._http_requests.put(
2659
- url, body=data, content_type=content_type, compress=compress, serializer=serializer
2617
+ url, body=data, content_type=content_type, compress=compress
2660
2618
  )
2661
2619
 
2662
2620
  return TaskInfo(**response.json())
@@ -3078,16 +3036,7 @@ class AsyncIndex(_BaseIndex):
3078
3036
  >>> index = client.index("movies")
3079
3037
  >>> await index.update_settings(new_settings)
3080
3038
  """
3081
- if is_pydantic_2():
3082
- body_dict = {k: v for k, v in body.model_dump(by_alias=True).items() if v is not None} # type: ignore[attr-defined]
3083
- else: # pragma: no cover
3084
- warn(
3085
- "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
3086
- DeprecationWarning,
3087
- stacklevel=2,
3088
- )
3089
- body_dict = {k: v for k, v in body.dict(by_alias=True).items() if v is not None} # type: ignore[attr-defined]
3090
-
3039
+ body_dict = {k: v for k, v in body.model_dump(by_alias=True).items() if v is not None}
3091
3040
  response = await self._http_requests.patch(self._settings_url, body_dict, compress=compress)
3092
3041
 
3093
3042
  return TaskInfo(**response.json())
@@ -3812,23 +3761,11 @@ class AsyncIndex(_BaseIndex):
3812
3761
  >>> TypoTolerance(enabled=False)
3813
3762
  >>> await index.update_typo_tolerance()
3814
3763
  """
3815
- if is_pydantic_2():
3816
- response = await self._http_requests.patch(
3817
- f"{self._settings_url}/typo-tolerance",
3818
- typo_tolerance.model_dump(by_alias=True),
3819
- compress=compress,
3820
- ) # type: ignore[attr-defined]
3821
- else: # pragma: no cover
3822
- warn(
3823
- "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
3824
- DeprecationWarning,
3825
- stacklevel=2,
3826
- )
3827
- response = await self._http_requests.patch(
3828
- f"{self._settings_url}/typo-tolerance",
3829
- typo_tolerance.dict(by_alias=True),
3830
- compress=compress,
3831
- ) # type: ignore[attr-defined]
3764
+ response = await self._http_requests.patch(
3765
+ f"{self._settings_url}/typo-tolerance",
3766
+ typo_tolerance.model_dump(by_alias=True),
3767
+ compress=compress,
3768
+ )
3832
3769
 
3833
3770
  return TaskInfo(**response.json())
3834
3771
 
@@ -3902,21 +3839,11 @@ class AsyncIndex(_BaseIndex):
3902
3839
  >>> index = client.index("movies")
3903
3840
  >>> await index.update_faceting(faceting=Faceting(max_values_per_facet=100))
3904
3841
  """
3905
- if is_pydantic_2():
3906
- response = await self._http_requests.patch(
3907
- f"{self._settings_url}/faceting",
3908
- faceting.model_dump(by_alias=True),
3909
- compress=compress,
3910
- ) # type: ignore[attr-defined]
3911
- else: # pragma: no cover
3912
- warn(
3913
- "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
3914
- DeprecationWarning,
3915
- stacklevel=2,
3916
- )
3917
- response = await self._http_requests.patch(
3918
- f"{self._settings_url}/faceting", faceting.dict(by_alias=True), compress=compress
3919
- ) # type: ignore[attr-defined]
3842
+ response = await self._http_requests.patch(
3843
+ f"{self._settings_url}/faceting",
3844
+ faceting.model_dump(by_alias=True),
3845
+ compress=compress,
3846
+ )
3920
3847
 
3921
3848
  return TaskInfo(**response.json())
3922
3849
 
@@ -3991,21 +3918,11 @@ class AsyncIndex(_BaseIndex):
3991
3918
  >>> index = client.index("movies")
3992
3919
  >>> await index.update_pagination(settings=Pagination(max_total_hits=123))
3993
3920
  """
3994
- if is_pydantic_2():
3995
- response = await self._http_requests.patch(
3996
- f"{self._settings_url}/pagination",
3997
- settings.model_dump(by_alias=True),
3998
- compress=compress,
3999
- ) # type: ignore[attr-defined]
4000
- else: # pragma: no cover
4001
- warn(
4002
- "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
4003
- DeprecationWarning,
4004
- stacklevel=2,
4005
- )
4006
- response = await self._http_requests.patch(
4007
- f"{self._settings_url}/pagination", settings.dict(by_alias=True), compress=compress
4008
- ) # type: ignore[attr-defined]
3921
+ response = await self._http_requests.patch(
3922
+ f"{self._settings_url}/pagination",
3923
+ settings.model_dump(by_alias=True),
3924
+ compress=compress,
3925
+ )
4009
3926
 
4010
3927
  return TaskInfo(**response.json())
4011
3928
 
@@ -4479,19 +4396,9 @@ class AsyncIndex(_BaseIndex):
4479
4396
  """
4480
4397
  payload = {}
4481
4398
  for key, embedder in embedders.embedders.items():
4482
- if is_pydantic_2():
4483
- payload[key] = {
4484
- k: v for k, v in embedder.model_dump(by_alias=True).items() if v is not None
4485
- } # type: ignore[attr-defined]
4486
- else: # pragma: no cover
4487
- warn(
4488
- "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
4489
- DeprecationWarning,
4490
- stacklevel=2,
4491
- )
4492
- payload[key] = {
4493
- k: v for k, v in embedder.dict(by_alias=True).items() if v is not None
4494
- } # type: ignore[attr-defined]
4399
+ payload[key] = {
4400
+ k: v for k, v in embedder.model_dump(by_alias=True).items() if v is not None
4401
+ }
4495
4402
 
4496
4403
  response = await self._http_requests.patch(
4497
4404
  f"{self._settings_url}/embedders", payload, compress=compress
@@ -4606,6 +4513,7 @@ class Index(_BaseIndex):
4606
4513
  created_at: str | datetime | None = None,
4607
4514
  updated_at: str | datetime | None = None,
4608
4515
  plugins: IndexPlugins | None = None,
4516
+ json_handler: BuiltinHandler | OrjsonHandler | UjsonHandler | None = None,
4609
4517
  ):
4610
4518
  """Class initializer.
4611
4519
 
@@ -4618,10 +4526,14 @@ class Index(_BaseIndex):
4618
4526
  created_at: The date and time the index was created. Defaults to None.
4619
4527
  updated_at: The date and time the index was last updated. Defaults to None.
4620
4528
  plugins: Optional plugins can be provided to extend functionality.
4529
+ json_handler: The module to use for json operations. The options are BuiltinHandler
4530
+ (uses the json module from the standard library), OrjsonHandler (uses orjson), or
4531
+ UjsonHandler (uses ujson). Note that in order use orjson or ujson the corresponding
4532
+ extra needs to be included. Default: BuiltinHandler.
4621
4533
  """
4622
- super().__init__(uid, primary_key, created_at, updated_at)
4534
+ super().__init__(uid, primary_key, created_at, updated_at, json_handler=json_handler)
4623
4535
  self.http_client = http_client
4624
- self._http_requests = HttpRequests(http_client)
4536
+ self._http_requests = HttpRequests(http_client, json_handler=self._json_handler)
4625
4537
  self.plugins = plugins
4626
4538
 
4627
4539
  @cached_property
@@ -5001,6 +4913,7 @@ class Index(_BaseIndex):
5001
4913
  wait: bool = True,
5002
4914
  timeout_in_ms: int | None = None,
5003
4915
  plugins: IndexPlugins | None = None,
4916
+ json_handler: BuiltinHandler | OrjsonHandler | UjsonHandler | None = None,
5004
4917
  ) -> Self:
5005
4918
  """Creates a new index.
5006
4919
 
@@ -5025,6 +4938,10 @@ class Index(_BaseIndex):
5025
4938
  MeilisearchTimeoutError. `None` can also be passed to wait indefinitely. Be aware that
5026
4939
  if the `None` option is used the wait time could be very long. Defaults to None.
5027
4940
  plugins: Optional plugins can be provided to extend functionality.
4941
+ json_handler: The module to use for json operations. The options are BuiltinHandler
4942
+ (uses the json module from the standard library), OrjsonHandler (uses orjson), or
4943
+ UjsonHandler (uses ujson). Note that in order use orjson or ujson the corresponding
4944
+ extra needs to be included. Default: BuiltinHandler.
5028
4945
 
5029
4946
  Returns:
5030
4947
 
@@ -5047,7 +4964,8 @@ class Index(_BaseIndex):
5047
4964
  payload = {"primaryKey": primary_key, "uid": uid}
5048
4965
 
5049
4966
  url = "indexes"
5050
- http_request = HttpRequests(http_client)
4967
+ handler = json_handler if json_handler else BuiltinHandler()
4968
+ http_request = HttpRequests(http_client, handler)
5051
4969
  response = http_request.post(url, payload)
5052
4970
  wait_for_task(http_client, response.json()["taskUid"], timeout_in_ms=timeout_in_ms)
5053
4971
  index_response = http_request.get(f"{url}/{uid}")
@@ -5059,6 +4977,7 @@ class Index(_BaseIndex):
5059
4977
  created_at=index_dict["createdAt"],
5060
4978
  updated_at=index_dict["updatedAt"],
5061
4979
  plugins=plugins,
4980
+ json_handler=json_handler,
5062
4981
  )
5063
4982
 
5064
4983
  if settings:
@@ -5578,7 +5497,6 @@ class Index(_BaseIndex):
5578
5497
  primary_key: str | None = None,
5579
5498
  *,
5580
5499
  compress: bool = False,
5581
- serializer: type[json.JSONEncoder] | None = None,
5582
5500
  ) -> TaskInfo:
5583
5501
  """Add documents to the index.
5584
5502
 
@@ -5588,8 +5506,6 @@ class Index(_BaseIndex):
5588
5506
  primary_key: The primary key of the documents. This will be ignored if already set.
5589
5507
  Defaults to None.
5590
5508
  compress: If set to True the data will be sent in gzip format. Defaults to False.
5591
- serializer: A custom JSONEncode to handle serializing fields that the build in
5592
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
5593
5509
 
5594
5510
  Returns:
5595
5511
 
@@ -5626,9 +5542,7 @@ class Index(_BaseIndex):
5626
5542
  if pre.get("document_result"):
5627
5543
  documents = pre["document_result"]
5628
5544
 
5629
- response = self._http_requests.post(
5630
- url, documents, compress=compress, serializer=serializer
5631
- )
5545
+ response = self._http_requests.post(url, documents, compress=compress)
5632
5546
  result = TaskInfo(**response.json())
5633
5547
  if self._post_add_documents_plugins:
5634
5548
  post = Index._run_plugins(self._post_add_documents_plugins, Event.POST, result=result)
@@ -5644,7 +5558,6 @@ class Index(_BaseIndex):
5644
5558
  batch_size: int = 1000,
5645
5559
  primary_key: str | None = None,
5646
5560
  compress: bool = False,
5647
- serializer: type[json.JSONEncoder] | None = None,
5648
5561
  ) -> list[TaskInfo]:
5649
5562
  """Adds documents in batches to reduce RAM usage with indexing.
5650
5563
 
@@ -5656,8 +5569,6 @@ class Index(_BaseIndex):
5656
5569
  primary_key: The primary key of the documents. This will be ignored if already set.
5657
5570
  Defaults to None.
5658
5571
  compress: If set to True the data will be sent in gzip format. Defaults to False.
5659
- serializer: A custom JSONEncode to handle serializing fields that the build in
5660
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
5661
5572
 
5662
5573
  Returns:
5663
5574
 
@@ -5680,7 +5591,7 @@ class Index(_BaseIndex):
5680
5591
  >>> index.add_documents_in_batches(documents)
5681
5592
  """
5682
5593
  return [
5683
- self.add_documents(x, primary_key, compress=compress, serializer=serializer)
5594
+ self.add_documents(x, primary_key, compress=compress)
5684
5595
  for x in _batch(documents, batch_size)
5685
5596
  ]
5686
5597
 
@@ -5693,7 +5604,6 @@ class Index(_BaseIndex):
5693
5604
  csv_delimiter: str | None = None,
5694
5605
  combine_documents: bool = True,
5695
5606
  compress: bool = False,
5696
- serializer: type[json.JSONEncoder] | None = None,
5697
5607
  ) -> list[TaskInfo]:
5698
5608
  """Load all json files from a directory and add the documents to the index.
5699
5609
 
@@ -5710,8 +5620,6 @@ class Index(_BaseIndex):
5710
5620
  combine_documents: If set to True this will combine the documents from all the files
5711
5621
  before indexing them. Defaults to True.
5712
5622
  compress: If set to True the data will be sent in gzip format. Defaults to False.
5713
- serializer: A custom JSONEncode to handle serializing fields that the build in
5714
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
5715
5623
 
5716
5624
  Returns:
5717
5625
 
@@ -5739,28 +5647,26 @@ class Index(_BaseIndex):
5739
5647
  all_documents = []
5740
5648
  for path in directory.iterdir():
5741
5649
  if path.suffix == f".{document_type}":
5742
- documents = _load_documents_from_file(path, csv_delimiter)
5650
+ documents = _load_documents_from_file(
5651
+ path, csv_delimiter, json_handler=self._json_handler
5652
+ )
5743
5653
  all_documents.append(documents)
5744
5654
 
5745
5655
  _raise_on_no_documents(all_documents, document_type, directory_path)
5746
5656
 
5747
5657
  combined = _combine_documents(all_documents)
5748
5658
 
5749
- response = self.add_documents(
5750
- combined, primary_key, compress=compress, serializer=serializer
5751
- )
5659
+ response = self.add_documents(combined, primary_key, compress=compress)
5752
5660
 
5753
5661
  return [response]
5754
5662
 
5755
5663
  responses = []
5756
5664
  for path in directory.iterdir():
5757
5665
  if path.suffix == f".{document_type}":
5758
- documents = _load_documents_from_file(path, csv_delimiter)
5759
- responses.append(
5760
- self.add_documents(
5761
- documents, primary_key, compress=compress, serializer=serializer
5762
- )
5666
+ documents = _load_documents_from_file(
5667
+ path, csv_delimiter, json_handler=self._json_handler
5763
5668
  )
5669
+ responses.append(self.add_documents(documents, primary_key, compress=compress))
5764
5670
 
5765
5671
  _raise_on_no_documents(responses, document_type, directory_path)
5766
5672
 
@@ -5776,7 +5682,6 @@ class Index(_BaseIndex):
5776
5682
  csv_delimiter: str | None = None,
5777
5683
  combine_documents: bool = True,
5778
5684
  compress: bool = False,
5779
- serializer: type[json.JSONEncoder] | None = None,
5780
5685
  ) -> list[TaskInfo]:
5781
5686
  """Load all json files from a directory and add the documents to the index in batches.
5782
5687
 
@@ -5795,8 +5700,6 @@ class Index(_BaseIndex):
5795
5700
  combine_documents: If set to True this will combine the documents from all the files
5796
5701
  before indexing them. Defaults to True.
5797
5702
  compress: If set to True the data will be sent in gzip format. Defaults to False.
5798
- serializer: A custom JSONEncode to handle serializing fields that the build in
5799
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
5800
5703
 
5801
5704
  Returns:
5802
5705
 
@@ -5824,7 +5727,9 @@ class Index(_BaseIndex):
5824
5727
  all_documents = []
5825
5728
  for path in directory.iterdir():
5826
5729
  if path.suffix == f".{document_type}":
5827
- documents = _load_documents_from_file(path, csv_delimiter=csv_delimiter)
5730
+ documents = _load_documents_from_file(
5731
+ path, csv_delimiter=csv_delimiter, json_handler=self._json_handler
5732
+ )
5828
5733
  all_documents.append(documents)
5829
5734
 
5830
5735
  _raise_on_no_documents(all_documents, document_type, directory_path)
@@ -5836,20 +5741,20 @@ class Index(_BaseIndex):
5836
5741
  batch_size=batch_size,
5837
5742
  primary_key=primary_key,
5838
5743
  compress=compress,
5839
- serializer=serializer,
5840
5744
  )
5841
5745
 
5842
5746
  responses: list[TaskInfo] = []
5843
5747
  for path in directory.iterdir():
5844
5748
  if path.suffix == f".{document_type}":
5845
- documents = _load_documents_from_file(path, csv_delimiter)
5749
+ documents = _load_documents_from_file(
5750
+ path, csv_delimiter, json_handler=self._json_handler
5751
+ )
5846
5752
  responses.extend(
5847
5753
  self.add_documents_in_batches(
5848
5754
  documents,
5849
5755
  batch_size=batch_size,
5850
5756
  primary_key=primary_key,
5851
5757
  compress=compress,
5852
- serializer=serializer,
5853
5758
  )
5854
5759
  )
5855
5760
 
@@ -5863,7 +5768,6 @@ class Index(_BaseIndex):
5863
5768
  primary_key: str | None = None,
5864
5769
  *,
5865
5770
  compress: bool = False,
5866
- serializer: type[json.JSONEncoder] | None = None,
5867
5771
  ) -> TaskInfo:
5868
5772
  """Add documents to the index from a json file.
5869
5773
 
@@ -5873,8 +5777,6 @@ class Index(_BaseIndex):
5873
5777
  primary_key: The primary key of the documents. This will be ignored if already set.
5874
5778
  Defaults to None.
5875
5779
  compress: If set to True the data will be sent in gzip format. Defaults to False.
5876
- serializer: A custom JSONEncode to handle serializing fields that the build in
5877
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
5878
5780
 
5879
5781
  Returns:
5880
5782
 
@@ -5896,11 +5798,9 @@ class Index(_BaseIndex):
5896
5798
  >>> index = client.index("movies")
5897
5799
  >>> index.add_documents_from_file(file_path)
5898
5800
  """
5899
- documents = _load_documents_from_file(file_path)
5801
+ documents = _load_documents_from_file(file_path, json_handler=self._json_handler)
5900
5802
 
5901
- return self.add_documents(
5902
- documents, primary_key=primary_key, compress=compress, serializer=serializer
5903
- )
5803
+ return self.add_documents(documents, primary_key=primary_key, compress=compress)
5904
5804
 
5905
5805
  def add_documents_from_file_in_batches(
5906
5806
  self,
@@ -5910,7 +5810,6 @@ class Index(_BaseIndex):
5910
5810
  primary_key: str | None = None,
5911
5811
  csv_delimiter: str | None = None,
5912
5812
  compress: bool = False,
5913
- serializer: type[json.JSONEncoder] | None = None,
5914
5813
  ) -> list[TaskInfo]:
5915
5814
  """Adds documents form a json file in batches to reduce RAM usage with indexing.
5916
5815
 
@@ -5924,8 +5823,6 @@ class Index(_BaseIndex):
5924
5823
  csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
5925
5824
  can only be used if the file is a csv file. Defaults to comma.
5926
5825
  compress: If set to True the data will be sent in gzip format. Defaults to False.
5927
- serializer: A custom JSONEncode to handle serializing fields that the build in
5928
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
5929
5826
 
5930
5827
  Returns:
5931
5828
 
@@ -5947,14 +5844,15 @@ class Index(_BaseIndex):
5947
5844
  >>> index = client.index("movies")
5948
5845
  >>> index.add_documents_from_file_in_batches(file_path)
5949
5846
  """
5950
- documents = _load_documents_from_file(file_path, csv_delimiter)
5847
+ documents = _load_documents_from_file(
5848
+ file_path, csv_delimiter, json_handler=self._json_handler
5849
+ )
5951
5850
 
5952
5851
  return self.add_documents_in_batches(
5953
5852
  documents,
5954
5853
  batch_size=batch_size,
5955
5854
  primary_key=primary_key,
5956
5855
  compress=compress,
5957
- serializer=serializer,
5958
5856
  )
5959
5857
 
5960
5858
  def add_documents_from_raw_file(
@@ -5964,7 +5862,6 @@ class Index(_BaseIndex):
5964
5862
  *,
5965
5863
  csv_delimiter: str | None = None,
5966
5864
  compress: bool = False,
5967
- serializer: type[json.JSONEncoder] | None = None,
5968
5865
  ) -> TaskInfo:
5969
5866
  """Directly send csv or ndjson files to Meilisearch without pre-processing.
5970
5867
 
@@ -5980,8 +5877,6 @@ class Index(_BaseIndex):
5980
5877
  csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
5981
5878
  can only be used if the file is a csv file. Defaults to comma.
5982
5879
  compress: If set to True the data will be sent in gzip format. Defaults to False.
5983
- serializer: A custom JSONEncode to handle serializing fields that the build in
5984
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
5985
5880
 
5986
5881
  Returns:
5987
5882
 
@@ -6039,7 +5934,7 @@ class Index(_BaseIndex):
6039
5934
  data = f.read()
6040
5935
 
6041
5936
  response = self._http_requests.post(
6042
- url, body=data, content_type=content_type, compress=compress, serializer=serializer
5937
+ url, body=data, content_type=content_type, compress=compress
6043
5938
  )
6044
5939
 
6045
5940
  return TaskInfo(**response.json())
@@ -6050,7 +5945,6 @@ class Index(_BaseIndex):
6050
5945
  primary_key: str | None = None,
6051
5946
  *,
6052
5947
  compress: bool = False,
6053
- serializer: type[json.JSONEncoder] | None = None,
6054
5948
  ) -> TaskInfo:
6055
5949
  """Update documents in the index.
6056
5950
 
@@ -6060,8 +5954,6 @@ class Index(_BaseIndex):
6060
5954
  primary_key: The primary key of the documents. This will be ignored if already set.
6061
5955
  Defaults to None.
6062
5956
  compress: If set to True the data will be sent in gzip format. Defaults to False.
6063
- serializer: A custom JSONEncode to handle serializing fields that the build in
6064
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
6065
5957
 
6066
5958
  Returns:
6067
5959
 
@@ -6098,7 +5990,7 @@ class Index(_BaseIndex):
6098
5990
  if pre.get("document_result"):
6099
5991
  documents = pre["document_result"]
6100
5992
 
6101
- response = self._http_requests.put(url, documents, compress=compress, serializer=serializer)
5993
+ response = self._http_requests.put(url, documents, compress=compress)
6102
5994
  result = TaskInfo(**response.json())
6103
5995
  if self._post_update_documents_plugins:
6104
5996
  post = Index._run_plugins(
@@ -6116,7 +6008,6 @@ class Index(_BaseIndex):
6116
6008
  batch_size: int = 1000,
6117
6009
  primary_key: str | None = None,
6118
6010
  compress: bool = False,
6119
- serializer: type[json.JSONEncoder] | None = None,
6120
6011
  ) -> list[TaskInfo]:
6121
6012
  """Update documents in batches to reduce RAM usage with indexing.
6122
6013
 
@@ -6130,8 +6021,6 @@ class Index(_BaseIndex):
6130
6021
  primary_key: The primary key of the documents. This will be ignored if already set.
6131
6022
  Defaults to None.
6132
6023
  compress: If set to True the data will be sent in gzip format. Defaults to False.
6133
- serializer: A custom JSONEncode to handle serializing fields that the build in
6134
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
6135
6024
 
6136
6025
  Returns:
6137
6026
 
@@ -6154,7 +6043,7 @@ class Index(_BaseIndex):
6154
6043
  >>> index.update_documents_in_batches(documents)
6155
6044
  """
6156
6045
  return [
6157
- self.update_documents(x, primary_key, compress=compress, serializer=serializer)
6046
+ self.update_documents(x, primary_key, compress=compress)
6158
6047
  for x in _batch(documents, batch_size)
6159
6048
  ]
6160
6049
 
@@ -6167,7 +6056,6 @@ class Index(_BaseIndex):
6167
6056
  csv_delimiter: str | None = None,
6168
6057
  combine_documents: bool = True,
6169
6058
  compress: bool = False,
6170
- serializer: type[json.JSONEncoder] | None = None,
6171
6059
  ) -> list[TaskInfo]:
6172
6060
  """Load all json files from a directory and update the documents.
6173
6061
 
@@ -6184,8 +6072,6 @@ class Index(_BaseIndex):
6184
6072
  combine_documents: If set to True this will combine the documents from all the files
6185
6073
  before indexing them. Defaults to True.
6186
6074
  compress: If set to True the data will be sent in gzip format. Defaults to False.
6187
- serializer: A custom JSONEncode to handle serializing fields that the build in
6188
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
6189
6075
 
6190
6076
  Returns:
6191
6077
 
@@ -6213,27 +6099,25 @@ class Index(_BaseIndex):
6213
6099
  all_documents = []
6214
6100
  for path in directory.iterdir():
6215
6101
  if path.suffix == f".{document_type}":
6216
- documents = _load_documents_from_file(path, csv_delimiter)
6102
+ documents = _load_documents_from_file(
6103
+ path, csv_delimiter, json_handler=self._json_handler
6104
+ )
6217
6105
  all_documents.append(documents)
6218
6106
 
6219
6107
  _raise_on_no_documents(all_documents, document_type, directory_path)
6220
6108
 
6221
6109
  combined = _combine_documents(all_documents)
6222
6110
 
6223
- response = self.update_documents(
6224
- combined, primary_key, compress=compress, serializer=serializer
6225
- )
6111
+ response = self.update_documents(combined, primary_key, compress=compress)
6226
6112
  return [response]
6227
6113
 
6228
6114
  responses = []
6229
6115
  for path in directory.iterdir():
6230
6116
  if path.suffix == f".{document_type}":
6231
- documents = _load_documents_from_file(path, csv_delimiter)
6232
- responses.append(
6233
- self.update_documents(
6234
- documents, primary_key, compress=compress, serializer=serializer
6235
- )
6117
+ documents = _load_documents_from_file(
6118
+ path, csv_delimiter, json_handler=self._json_handler
6236
6119
  )
6120
+ responses.append(self.update_documents(documents, primary_key, compress=compress))
6237
6121
 
6238
6122
  _raise_on_no_documents(responses, document_type, directory_path)
6239
6123
 
@@ -6249,7 +6133,6 @@ class Index(_BaseIndex):
6249
6133
  csv_delimiter: str | None = None,
6250
6134
  combine_documents: bool = True,
6251
6135
  compress: bool = False,
6252
- serializer: type[json.JSONEncoder] | None = None,
6253
6136
  ) -> list[TaskInfo]:
6254
6137
  """Load all json files from a directory and update the documents.
6255
6138
 
@@ -6268,8 +6151,6 @@ class Index(_BaseIndex):
6268
6151
  combine_documents: If set to True this will combine the documents from all the files
6269
6152
  before indexing them. Defaults to True.
6270
6153
  compress: If set to True the data will be sent in gzip format. Defaults to False.
6271
- serializer: A custom JSONEncode to handle serializing fields that the build in
6272
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
6273
6154
 
6274
6155
  Returns:
6275
6156
 
@@ -6297,7 +6178,9 @@ class Index(_BaseIndex):
6297
6178
  all_documents = []
6298
6179
  for path in directory.iterdir():
6299
6180
  if path.suffix == f".{document_type}":
6300
- documents = _load_documents_from_file(path, csv_delimiter)
6181
+ documents = _load_documents_from_file(
6182
+ path, csv_delimiter, json_handler=self._json_handler
6183
+ )
6301
6184
  all_documents.append(documents)
6302
6185
 
6303
6186
  _raise_on_no_documents(all_documents, document_type, directory_path)
@@ -6309,21 +6192,21 @@ class Index(_BaseIndex):
6309
6192
  batch_size=batch_size,
6310
6193
  primary_key=primary_key,
6311
6194
  compress=compress,
6312
- serializer=serializer,
6313
6195
  )
6314
6196
 
6315
6197
  responses: list[TaskInfo] = []
6316
6198
 
6317
6199
  for path in directory.iterdir():
6318
6200
  if path.suffix == f".{document_type}":
6319
- documents = _load_documents_from_file(path, csv_delimiter)
6201
+ documents = _load_documents_from_file(
6202
+ path, csv_delimiter, json_handler=self._json_handler
6203
+ )
6320
6204
  responses.extend(
6321
6205
  self.update_documents_in_batches(
6322
6206
  documents,
6323
6207
  batch_size=batch_size,
6324
6208
  primary_key=primary_key,
6325
6209
  compress=compress,
6326
- serializer=serializer,
6327
6210
  )
6328
6211
  )
6329
6212
 
@@ -6338,7 +6221,6 @@ class Index(_BaseIndex):
6338
6221
  csv_delimiter: str | None = None,
6339
6222
  *,
6340
6223
  compress: bool = False,
6341
- serializer: type[json.JSONEncoder] | None = None,
6342
6224
  ) -> TaskInfo:
6343
6225
  """Add documents in the index from a json file.
6344
6226
 
@@ -6350,8 +6232,6 @@ class Index(_BaseIndex):
6350
6232
  csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
6351
6233
  can only be used if the file is a csv file. Defaults to comma.
6352
6234
  compress: If set to True the data will be sent in gzip format. Defaults to False.
6353
- serializer: A custom JSONEncode to handle serializing fields that the build in
6354
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
6355
6235
 
6356
6236
  Returns:
6357
6237
 
@@ -6371,12 +6251,12 @@ class Index(_BaseIndex):
6371
6251
  >>> index = client.index("movies")
6372
6252
  >>> index.update_documents_from_file(file_path)
6373
6253
  """
6374
- documents = _load_documents_from_file(file_path, csv_delimiter)
6375
-
6376
- return self.update_documents(
6377
- documents, primary_key=primary_key, compress=compress, serializer=serializer
6254
+ documents = _load_documents_from_file(
6255
+ file_path, csv_delimiter, json_handler=self._json_handler
6378
6256
  )
6379
6257
 
6258
+ return self.update_documents(documents, primary_key=primary_key, compress=compress)
6259
+
6380
6260
  def update_documents_from_file_in_batches(
6381
6261
  self,
6382
6262
  file_path: Path | str,
@@ -6384,7 +6264,6 @@ class Index(_BaseIndex):
6384
6264
  batch_size: int = 1000,
6385
6265
  primary_key: str | None = None,
6386
6266
  compress: bool = False,
6387
- serializer: type[json.JSONEncoder] | None = None,
6388
6267
  ) -> list[TaskInfo]:
6389
6268
  """Updates documents form a json file in batches to reduce RAM usage with indexing.
6390
6269
 
@@ -6396,8 +6275,6 @@ class Index(_BaseIndex):
6396
6275
  primary_key: The primary key of the documents. This will be ignored if already set.
6397
6276
  Defaults to None.
6398
6277
  compress: If set to True the data will be sent in gzip format. Defaults to False.
6399
- serializer: A custom JSONEncode to handle serializing fields that the build in
6400
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
6401
6278
 
6402
6279
  Returns:
6403
6280
 
@@ -6417,14 +6294,13 @@ class Index(_BaseIndex):
6417
6294
  >>> index = client.index("movies")
6418
6295
  >>> index.update_documents_from_file_in_batches(file_path)
6419
6296
  """
6420
- documents = _load_documents_from_file(file_path)
6297
+ documents = _load_documents_from_file(file_path, json_handler=self._json_handler)
6421
6298
 
6422
6299
  return self.update_documents_in_batches(
6423
6300
  documents,
6424
6301
  batch_size=batch_size,
6425
6302
  primary_key=primary_key,
6426
6303
  compress=compress,
6427
- serializer=serializer,
6428
6304
  )
6429
6305
 
6430
6306
  def update_documents_from_raw_file(
@@ -6434,7 +6310,6 @@ class Index(_BaseIndex):
6434
6310
  csv_delimiter: str | None = None,
6435
6311
  *,
6436
6312
  compress: bool = False,
6437
- serializer: type[json.JSONEncoder] | None = None,
6438
6313
  ) -> TaskInfo:
6439
6314
  """Directly send csv or ndjson files to Meilisearch without pre-processing.
6440
6315
 
@@ -6450,8 +6325,6 @@ class Index(_BaseIndex):
6450
6325
  csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
6451
6326
  can only be used if the file is a csv file. Defaults to comma.
6452
6327
  compress: If set to True the data will be sent in gzip format. Defaults to False.
6453
- serializer: A custom JSONEncode to handle serializing fields that the build in
6454
- json.dumps cannot handle, for example UUID and datetime. Defaults to None.
6455
6328
 
6456
6329
  Returns:
6457
6330
 
@@ -6509,7 +6382,7 @@ class Index(_BaseIndex):
6509
6382
  data = f.read()
6510
6383
 
6511
6384
  response = self._http_requests.put(
6512
- url, body=data, content_type=content_type, compress=compress, serializer=serializer
6385
+ url, body=data, content_type=content_type, compress=compress
6513
6386
  )
6514
6387
 
6515
6388
  return TaskInfo(**response.json())
@@ -6769,16 +6642,7 @@ class Index(_BaseIndex):
6769
6642
  >>> index = client.index("movies")
6770
6643
  >>> index.update_settings(new_settings)
6771
6644
  """
6772
- if is_pydantic_2():
6773
- body_dict = {k: v for k, v in body.model_dump(by_alias=True).items() if v is not None} # type: ignore[attr-defined]
6774
- else: # pragma: no cover
6775
- warn(
6776
- "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
6777
- DeprecationWarning,
6778
- stacklevel=2,
6779
- )
6780
- body_dict = {k: v for k, v in body.dict(by_alias=True).items() if v is not None} # type: ignore[attr-defined]
6781
-
6645
+ body_dict = {k: v for k, v in body.model_dump(by_alias=True).items() if v is not None}
6782
6646
  response = self._http_requests.patch(self._settings_url, body_dict, compress=compress)
6783
6647
 
6784
6648
  return TaskInfo(**response.json())
@@ -7492,23 +7356,11 @@ class Index(_BaseIndex):
7492
7356
  >>> TypoTolerance(enabled=False)
7493
7357
  >>> index.update_typo_tolerance()
7494
7358
  """
7495
- if is_pydantic_2():
7496
- response = self._http_requests.patch(
7497
- f"{self._settings_url}/typo-tolerance",
7498
- typo_tolerance.model_dump(by_alias=True),
7499
- compress=compress,
7500
- ) # type: ignore[attr-defined]
7501
- else: # pragma: no cover
7502
- warn(
7503
- "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
7504
- DeprecationWarning,
7505
- stacklevel=2,
7506
- )
7507
- response = self._http_requests.patch(
7508
- f"{self._settings_url}/typo-tolerance",
7509
- typo_tolerance.dict(by_alias=True),
7510
- compress=compress,
7511
- ) # type: ignore[attr-defined]
7359
+ response = self._http_requests.patch(
7360
+ f"{self._settings_url}/typo-tolerance",
7361
+ typo_tolerance.model_dump(by_alias=True),
7362
+ compress=compress,
7363
+ )
7512
7364
 
7513
7365
  return TaskInfo(**response.json())
7514
7366
 
@@ -7582,21 +7434,11 @@ class Index(_BaseIndex):
7582
7434
  >>> index = client.index("movies")
7583
7435
  >>> index.update_faceting(faceting=Faceting(max_values_per_facet=100))
7584
7436
  """
7585
- if is_pydantic_2():
7586
- response = self._http_requests.patch(
7587
- f"{self._settings_url}/faceting",
7588
- faceting.model_dump(by_alias=True),
7589
- compress=compress,
7590
- ) # type: ignore[attr-defined]
7591
- else: # pragma: no cover
7592
- warn(
7593
- "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
7594
- DeprecationWarning,
7595
- stacklevel=2,
7596
- )
7597
- response = self._http_requests.patch(
7598
- f"{self._settings_url}/faceting", faceting.dict(by_alias=True), compress=compress
7599
- ) # type: ignore[attr-defined]
7437
+ response = self._http_requests.patch(
7438
+ f"{self._settings_url}/faceting",
7439
+ faceting.model_dump(by_alias=True),
7440
+ compress=compress,
7441
+ )
7600
7442
 
7601
7443
  return TaskInfo(**response.json())
7602
7444
 
@@ -7671,21 +7513,11 @@ class Index(_BaseIndex):
7671
7513
  >>> index = client.index("movies")
7672
7514
  >>> index.update_pagination(settings=Pagination(max_total_hits=123))
7673
7515
  """
7674
- if is_pydantic_2():
7675
- response = self._http_requests.patch(
7676
- f"{self._settings_url}/pagination",
7677
- settings.model_dump(by_alias=True),
7678
- compress=compress,
7679
- ) # type: ignore[attr-defined]
7680
- else: # pragma: no cover
7681
- warn(
7682
- "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
7683
- DeprecationWarning,
7684
- stacklevel=2,
7685
- )
7686
- response = self._http_requests.patch(
7687
- f"{self._settings_url}/pagination", settings.dict(by_alias=True), compress=compress
7688
- ) # type: ignore[attr-defined]
7516
+ response = self._http_requests.patch(
7517
+ f"{self._settings_url}/pagination",
7518
+ settings.model_dump(by_alias=True),
7519
+ compress=compress,
7520
+ )
7689
7521
 
7690
7522
  return TaskInfo(**response.json())
7691
7523
 
@@ -8153,19 +7985,9 @@ class Index(_BaseIndex):
8153
7985
  """
8154
7986
  payload = {}
8155
7987
  for key, embedder in embedders.embedders.items():
8156
- if is_pydantic_2():
8157
- payload[key] = {
8158
- k: v for k, v in embedder.model_dump(by_alias=True).items() if v is not None
8159
- } # type: ignore[attr-defined]
8160
- else: # pragma: no cover
8161
- warn(
8162
- "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
8163
- DeprecationWarning,
8164
- stacklevel=2,
8165
- )
8166
- payload[key] = {
8167
- k: v for k, v in embedder.dict(by_alias=True).items() if v is not None
8168
- } # type: ignore[attr-defined]
7988
+ payload[key] = {
7989
+ k: v for k, v in embedder.model_dump(by_alias=True).items() if v is not None
7990
+ }
8169
7991
 
8170
7992
  response = self._http_requests.patch(
8171
7993
  f"{self._settings_url}/embedders", payload, compress=compress
@@ -8241,6 +8063,8 @@ class Index(_BaseIndex):
8241
8063
  async def _async_load_documents_from_file(
8242
8064
  file_path: Path | str,
8243
8065
  csv_delimiter: str | None = None,
8066
+ *,
8067
+ json_handler: BuiltinHandler | OrjsonHandler | UjsonHandler,
8244
8068
  ) -> list[dict[Any, Any]]:
8245
8069
  if isinstance(file_path, str):
8246
8070
  file_path = Path(file_path)
@@ -8267,11 +8091,11 @@ async def _async_load_documents_from_file(
8267
8091
 
8268
8092
  if file_path.suffix == ".ndjson":
8269
8093
  with open(file_path) as f: # noqa: ASYNC101 ASYNC230
8270
- return [await loop.run_in_executor(None, partial(json.loads, x)) for x in f]
8094
+ return [await loop.run_in_executor(None, partial(json_handler.loads, x)) for x in f]
8271
8095
 
8272
8096
  async with aiofiles.open(file_path, mode="r") as f: # type: ignore
8273
8097
  data = await f.read() # type: ignore
8274
- documents = await loop.run_in_executor(None, partial(json.loads, data))
8098
+ documents = await loop.run_in_executor(None, partial(json_handler.loads, data))
8275
8099
 
8276
8100
  if not isinstance(documents, list):
8277
8101
  raise InvalidDocumentError("Meilisearch requires documents to be in a list")
@@ -8310,6 +8134,8 @@ def _plugin_has_method(
8310
8134
  def _load_documents_from_file(
8311
8135
  file_path: Path | str,
8312
8136
  csv_delimiter: str | None = None,
8137
+ *,
8138
+ json_handler: BuiltinHandler | OrjsonHandler | UjsonHandler,
8313
8139
  ) -> list[dict[Any, Any]]:
8314
8140
  if isinstance(file_path, str):
8315
8141
  file_path = Path(file_path)
@@ -8333,11 +8159,11 @@ def _load_documents_from_file(
8333
8159
 
8334
8160
  if file_path.suffix == ".ndjson":
8335
8161
  with open(file_path) as f:
8336
- return [json.loads(x) for x in f]
8162
+ return [json_handler.loads(x) for x in f]
8337
8163
 
8338
8164
  with open(file_path) as f:
8339
8165
  data = f.read()
8340
- documents = json.loads(data)
8166
+ documents = json_handler.loads(data)
8341
8167
 
8342
8168
  if not isinstance(documents, list):
8343
8169
  raise InvalidDocumentError("Meilisearch requires documents to be in a list")
@@ -8419,15 +8245,7 @@ def _process_search_parameters(
8419
8245
  body["vector"] = vector
8420
8246
 
8421
8247
  if hybrid:
8422
- if is_pydantic_2():
8423
- body["hybrid"] = hybrid.model_dump(by_alias=True) # type: ignore[attr-defined]
8424
- else: # pragma: no cover
8425
- warn(
8426
- "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
8427
- DeprecationWarning,
8428
- stacklevel=2,
8429
- )
8430
- body["hybrid"] = hybrid.dict(by_alias=True) # type: ignore[attr-defined]
8248
+ body["hybrid"] = hybrid.model_dump(by_alias=True)
8431
8249
 
8432
8250
  return body
8433
8251