Skip to content

AsyncClient

AsyncClient Usage

Create a client with a context manager

This client runs in a context manager which ensures that everything is cleaned up after the use of the client is done. To create a client:

from meilisearch-python-sdk import AsyncClient


async with AsyncClient("http://localhost:7700", "masterKey") as client:
    index = client.index("movies")
    ...

Create a client without a context manager

It is also possible to call the client without using a context manager, but in doing so you will need to make sure to do the cleanup yourself:

from meilisearch-python-sdk import AsyncClient


try:
    client = AsyncClient("http://localhost:7700", "masterKey")
    ...
finally:
    await client.aclose()

AsyncClient API

Bases: BaseClient

Async client to connect to the Meilisearch API.

Source code in meilisearch_python_sdk/_client.py
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
class AsyncClient(BaseClient):
    """Async client to connect to the Meilisearch API."""

    def __init__(
        self,
        url: str,
        api_key: str | None = None,
        *,
        timeout: int | None = None,
        verify: str | bool | SSLContext = True,
    ) -> None:
        """Class initializer.

        Args:

            url: The url to the Meilisearch API (ex: http://localhost:7700)
            api_key: The optional API key for Meilisearch. Defaults to None.
            timeout: The amount of time in seconds that the client will wait for a response before
                timing out. Defaults to None.
            verify: SSL certificates (a.k.a CA bundle) used to
                verify the identity of requested hosts. Either `True` (default CA bundle),
                a path to an SSL certificate file, or `False` (disable verification)
        """
        super().__init__(api_key)

        self.http_client = HttpxAsyncClient(
            base_url=url, timeout=timeout, headers=self._headers, verify=verify
        )
        self._http_requests = AsyncHttpRequests(self.http_client)

    async def __aenter__(self) -> AsyncClient:
        return self

    async def __aexit__(
        self,
        et: type[BaseException] | None,
        ev: type[BaseException] | None,
        traceback: TracebackType | None,
    ) -> None:
        await self.aclose()

    async def aclose(self) -> None:
        """Closes the client.

        This only needs to be used if the client was not created with a context manager.
        """
        await self.http_client.aclose()

    async def create_dump(self) -> TaskInfo:
        """Trigger the creation of a Meilisearch dump.

        Returns:

            The details of the task.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     await client.create_dump()
        """
        response = await self._http_requests.post("dumps")

        return TaskInfo(**response.json())

    async def create_index(
        self,
        uid: str,
        primary_key: str | None = None,
        *,
        settings: MeilisearchSettings | None = None,
        wait: bool = True,
        timeout_in_ms: int | None = None,
        plugins: AsyncIndexPlugins | None = None,
    ) -> AsyncIndex:
        """Creates a new index.

        Args:

            uid: The index's unique identifier.
            primary_key: The primary key of the documents. Defaults to None.
            settings: Settings for the index. The settings can also be updated independently of
                creating the index. The advantage to updating them here is updating the settings after
                adding documents will cause the documents to be re-indexed. Because of this it will be
                faster to update them before adding documents. Defaults to None (i.e. default
                Meilisearch index settings).
            wait: If set to True and settings are being updated, the index will be returned after
                the settings update has completed. If False it will not wait for settings to complete.
                Default: True
            timeout_in_ms: Amount of time in milliseconds to wait before raising a
                MeilisearchTimeoutError. `None` can also be passed to wait indefinitely. Be aware that
                if the `None` option is used the wait time could be very long. Defaults to None.
            plugins: Optional plugins can be provided to extend functionality.

        Returns:

            An instance of AsyncIndex containing the information of the newly created index.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     index = await client.create_index("movies")
        """
        return await AsyncIndex.create(
            self.http_client,
            uid,
            primary_key,
            settings=settings,
            wait=wait,
            timeout_in_ms=timeout_in_ms,
            plugins=plugins,
        )

    async def create_snapshot(self) -> TaskInfo:
        """Trigger the creation of a Meilisearch snapshot.

        Returns:

            The details of the task.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     await client.create_snapshot()
        """
        response = await self._http_requests.post("snapshots")

        return TaskInfo(**response.json())

    async def delete_index_if_exists(self, uid: str) -> bool:
        """Deletes an index if it already exists.

        Args:

            uid: The index's unique identifier.

        Returns:

            True if an index was deleted for False if not.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     await client.delete_index_if_exists()
        """
        response = await self._http_requests.delete(f"indexes/{uid}")
        status = await self.wait_for_task(response.json()["taskUid"], timeout_in_ms=100000)
        if status.status == "succeeded":
            return True
        return False

    async def get_indexes(
        self, *, offset: int | None = None, limit: int | None = None
    ) -> list[AsyncIndex] | None:
        """Get all indexes.
        Args:

            offset: Number of indexes to skip. The default of None will use the Meilisearch
                default.
            limit: Number of indexes to return. The default of None will use the Meilisearch
                default.

        Returns:

            A list of all indexes.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     indexes = await client.get_indexes()
        """
        url = _build_offset_limit_url("indexes", offset, limit)
        response = await self._http_requests.get(url)

        if not response.json()["results"]:
            return None

        return [
            AsyncIndex(
                http_client=self.http_client,
                uid=x["uid"],
                primary_key=x["primaryKey"],
                created_at=x["createdAt"],
                updated_at=x["updatedAt"],
            )
            for x in response.json()["results"]
        ]

    async def get_index(self, uid: str) -> AsyncIndex:
        """Gets a single index based on the uid of the index.

        Args:

            uid: The index's unique identifier.

        Returns:

            An AsyncIndex instance containing the information of the fetched index.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     index = await client.get_index()
        """
        return await AsyncIndex(self.http_client, uid).fetch_info()

    def index(self, uid: str, *, plugins: AsyncIndexPlugins | None = None) -> AsyncIndex:
        """Create a local reference to an index identified by UID, without making an HTTP call.

        Because no network call is made this method is not awaitable.

        Args:

            uid: The index's unique identifier.
            plugins: Optional plugins can be provided to extend functionality.

        Returns:

            An AsyncIndex instance.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     index = client.index("movies")
        """
        return AsyncIndex(self.http_client, uid=uid, plugins=plugins)

    async def get_all_stats(self) -> ClientStats:
        """Get stats for all indexes.

        Returns:

            Information about database size and all indexes.
            https://docs.meilisearch.com/reference/api/stats.html

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     stats = await client.get_all_stats()
        """
        response = await self._http_requests.get("stats")

        return ClientStats(**response.json())

    async def get_or_create_index(
        self, uid: str, primary_key: str | None = None, *, plugins: AsyncIndexPlugins | None = None
    ) -> AsyncIndex:
        """Get an index, or create it if it doesn't exist.

        Args:

            uid: The index's unique identifier.
            primary_key: The primary key of the documents. Defaults to None.
            plugins: Optional plugins can be provided to extend functionality.

        Returns:

            An instance of AsyncIndex containing the information of the retrieved or newly created index.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.MeilisearchTimeoutError: If the connection times out.
            MeilisearchTimeoutError: If the connection times out.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     index = await client.get_or_create_index("movies")
        """
        try:
            index_instance = await self.get_index(uid)
        except MeilisearchApiError as err:
            if "index_not_found" not in err.code:
                raise
            index_instance = await self.create_index(uid, primary_key, plugins=plugins)
        return index_instance

    async def create_key(self, key: KeyCreate) -> Key:
        """Creates a new API key.

        Args:

            key: The information to use in creating the key. Note that if an expires_at value
                is included it should be in UTC time.

        Returns:

            The new API key.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> from meilissearch_async_client.models.client import KeyCreate
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     key_info = KeyCreate(
            >>>         description="My new key",
            >>>         actions=["search"],
            >>>         indexes=["movies"],
            >>>     )
            >>>     keys = await client.create_key(key_info)
        """
        if is_pydantic_2():
            response = await self._http_requests.post(
                "keys", json.loads(key.model_dump_json(by_alias=True))
            )  # type: ignore[attr-defined]
        else:  # pragma: no cover
            warn(
                "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
                DeprecationWarning,
                stacklevel=2,
            )
            response = await self._http_requests.post("keys", json.loads(key.json(by_alias=True)))  # type: ignore[attr-defined]

        return Key(**response.json())

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

        Args:

            key: The key or uid to delete.

        Returns:

            The Response status code. 204 signifies a successful delete.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     await client.delete_key("abc123")
        """
        response = await self._http_requests.delete(f"keys/{key}")
        return response.status_code

    async def get_keys(self, *, offset: int | None = None, limit: int | None = None) -> KeySearch:
        """Gets the Meilisearch API keys.
        Args:

            offset: Number of indexes to skip. The default of None will use the Meilisearch
                default.
            limit: Number of indexes to return. The default of None will use the Meilisearch
                default.

        Returns:

            API keys.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            from meilisearch_python_sdk import AsyncClient
            async with AsyncClient("http://localhost.com", "masterKey") as client:
                keys = await client.get_keys()
        """
        url = _build_offset_limit_url("keys", offset, limit)
        response = await self._http_requests.get(url)

        return KeySearch(**response.json())

    async def get_key(self, key: str) -> Key:
        """Gets information about a specific API key.

        Args:

            key: The key for which to retrieve the information.

        Returns:

            The API key, or `None` if the key is not found.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     keys = await client.get_key("abc123")
        """
        response = await self._http_requests.get(f"keys/{key}")

        return Key(**response.json())

    async def update_key(self, key: KeyUpdate) -> Key:
        """Update an API key.

        Args:

            key: The information to use in updating the key. Note that if an expires_at value
                is included it should be in UTC time.

        Returns:

            The updated API key.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> from meilissearch_async_client.models.client import KeyUpdate
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     key_info = KeyUpdate(
                        key="abc123",
            >>>         indexes=["*"],
            >>>     )
            >>>     keys = await client.update_key(key_info)
        """
        payload = _build_update_key_payload(key)
        response = await self._http_requests.patch(f"keys/{key.key}", payload)

        return Key(**response.json())

    async def multi_search(self, queries: list[SearchParams]) -> list[SearchResultsWithUID]:
        """Multi-index search.

        Args:

            queries: List of SearchParameters

        Returns:

            Results of the search

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> from meilisearch_python_sdk.models.search import SearchParams
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     queries = [
            >>>         SearchParams(index_uid="my_first_index", query"Some search"),
            >>>         SearchParams(index_uid="my_second_index", query="Another search")
            >>>     ]
            >>>     search_results = await client.search(queries)
        """
        url = "multi-search"
        if is_pydantic_2():
            response = await self._http_requests.post(
                url,
                body={"queries": [x.model_dump(by_alias=True) for x in queries]},  # type: ignore[attr-defined]
            )
        else:  # pragma: no cover
            warn(
                "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
                DeprecationWarning,
                stacklevel=2,
            )
            response = await self._http_requests.post(
                url,
                body={"queries": [x.dict(by_alias=True) for x in queries]},  # type: ignore[attr-defined]
            )

        return [SearchResultsWithUID(**x) for x in response.json()["results"]]

    async def get_raw_index(self, uid: str) -> IndexInfo | None:
        """Gets the index and returns all the index information rather than an AsyncIndex instance.

        Args:

            uid: The index's unique identifier.

        Returns:

            Index information rather than an AsyncIndex instance.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     index = await client.get_raw_index("movies")
        """
        response = await self.http_client.get(f"indexes/{uid}")

        if response.status_code == 404:
            return None

        return IndexInfo(**response.json())

    async def get_raw_indexes(
        self, *, offset: int | None = None, limit: int | None = None
    ) -> list[IndexInfo] | None:
        """Gets all the indexes.
        Args:

            offset: Number of indexes to skip. The default of None will use the Meilisearch
                default.
            limit: Number of indexes to return. The default of None will use the Meilisearch
                default.

        Returns all the index information rather than an AsyncIndex instance.

        Returns:

            A list of the Index information rather than an AsyncIndex instances.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     index = await client.get_raw_indexes()
        """
        url = _build_offset_limit_url("indexes", offset, limit)
        response = await self._http_requests.get(url)

        if not response.json()["results"]:
            return None

        return [IndexInfo(**x) for x in response.json()["results"]]

    async def get_version(self) -> Version:
        """Get the Meilisearch version.

        Returns:

            Information about the version of Meilisearch.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     version = await client.get_version()
        """
        response = await self._http_requests.get("version")

        return Version(**response.json())

    async def health(self) -> Health:
        """Get health of the Meilisearch server.

        Returns:

            The status of the Meilisearch server.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     health = await client.get_health()
        """
        response = await self._http_requests.get("health")

        return Health(**response.json())

    async def swap_indexes(self, indexes: list[tuple[str, str]]) -> TaskInfo:
        """Swap two indexes.

        Args:

            indexes: A list of tuples, each tuple should contain the indexes to swap.

        Returns:

            The details of the task.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     index = await client.swap_indexes([("index_a", "index_b")])
        """
        processed_indexes = [{"indexes": x} for x in indexes]
        response = await self._http_requests.post("swap-indexes", processed_indexes)

        return TaskInfo(**response.json())

    async def cancel_tasks(
        self,
        *,
        uids: list[str] | None = None,
        index_uids: list[str] | None = None,
        statuses: list[str] | None = None,
        types: list[str] | None = None,
        before_enqueued_at: datetime | None = None,
        after_enqueued_at: datetime | None = None,
        before_started_at: datetime | None = None,
        after_finished_at: datetime | None = None,
    ) -> TaskInfo:
        """Cancel a list of enqueued or processing tasks.

        Defaults to cancelling all tasks.

        Args:

            uids: A list of task UIDs to cancel.
            index_uids: A list of index UIDs for which to cancel tasks.
            statuses: A list of statuses to cancel.
            types: A list of types to cancel.
            before_enqueued_at: Cancel tasks that were enqueued before the specified date time.
            after_enqueued_at: Cancel tasks that were enqueued after the specified date time.
            before_started_at: Cancel tasks that were started before the specified date time.
            after_finished_at: Cancel tasks that were finished after the specified date time.

        Returns:

            The details of the task

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.
            MeilisearchTimeoutError: If the connection times out.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>>
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     await client.cancel_tasks(uids=[1, 2])
        """
        return await _task.async_cancel_tasks(
            self.http_client,
            uids=uids,
            index_uids=index_uids,
            statuses=statuses,
            types=types,
            before_enqueued_at=before_enqueued_at,
            after_enqueued_at=after_enqueued_at,
            before_started_at=before_started_at,
            after_finished_at=after_finished_at,
        )

    async def get_task(self, task_id: int) -> TaskResult:
        """Get a single task from it's task id.

        Args:

            task_id: Identifier of the task to retrieve.

        Returns:

            Results of a task.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.
            MeilisearchTimeoutError: If the connection times out.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> from meilisearch_python_sdk.task import get_task
            >>>
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     await client.get_task(client, 1244)
        """
        return await _task.async_get_task(self.http_client, task_id=task_id)

    async def delete_tasks(
        self,
        *,
        uids: list[str] | None = None,
        index_uids: list[str] | None = None,
        statuses: list[str] | None = None,
        types: list[str] | None = None,
        before_enqueued_at: datetime | None = None,
        after_enqueued_at: datetime | None = None,
        before_started_at: datetime | None = None,
        after_finished_at: datetime | None = None,
    ) -> TaskInfo:
        """Delete a list of tasks.

        Defaults to deleting all tasks.

        Args:

            uids: A list of task UIDs to delete.
            index_uids: A list of index UIDs for which to delete tasks.
            statuses: A list of statuses to delete.
            types: A list of types to delete.
            before_enqueued_at: Delete tasks that were enqueued before the specified date time.
            after_enqueued_at: Delete tasks that were enqueued after the specified date time.
            before_started_at: Delete tasks that were started before the specified date time.
            after_finished_at: Delete tasks that were finished after the specified date time.

        Returns:

            The details of the task

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.
            MeilisearchTimeoutError: If the connection times out.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> from meilisearch_python_sdk.task import delete_tasks
            >>>
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     await client.delete_tasks(uids=[1, 2])
        """
        return await _task.async_delete_tasks(
            self.http_client,
            uids=uids,
            index_uids=index_uids,
            statuses=statuses,
            types=types,
            before_enqueued_at=before_enqueued_at,
            after_enqueued_at=after_enqueued_at,
            before_started_at=before_started_at,
            after_finished_at=after_finished_at,
        )

    async def get_tasks(
        self,
        *,
        index_ids: list[str] | None = None,
        types: str | list[str] | None = None,
    ) -> TaskStatus:
        """Get multiple tasks.

        Args:

            index_ids: A list of index UIDs for which to get the tasks. If provided this will get the
                tasks only for the specified indexes, if not all tasks will be returned. Default = None
            types: Specify specific task types to retrieve. Default = None

        Returns:

            Task statuses.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.
            MeilisearchTimeoutError: If the connection times out.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>>
            >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
            >>>     await client.get_tasks()
        """
        return await _task.async_get_tasks(self.http_client, index_ids=index_ids, types=types)

    async def wait_for_task(
        self,
        task_id: int,
        *,
        timeout_in_ms: int | None = 5000,
        interval_in_ms: int = 50,
        raise_for_status: bool = False,
    ) -> TaskResult:
        """Wait until Meilisearch processes a task, and get its status.

        Args:

            task_id: Identifier of the task to retrieve.
            timeout_in_ms: Amount of time in milliseconds to wait before raising a
                MeilisearchTimeoutError. `None` can also be passed to wait indefinitely. Be aware that
                if the `None` option is used the wait time could be very long. Defaults to 5000.
            interval_in_ms: Time interval in miliseconds to sleep between requests. Defaults to 50.
            raise_for_status: When set to `True` a MeilisearchTaskFailedError will be raised if a task
                has a failed status. Defaults to False.

        Returns:

            Details of the processed update status.

        Raises:

            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.
            MeilisearchTimeoutError: If the connection times out.
            MeilisearchTaskFailedError: If `raise_for_status` is `True` and a task has a failed status.

        Examples:

            >>> from meilisearch_python_sdk import AsyncClient
            >>> >>> documents = [
            >>>     {"id": 1, "title": "Movie 1", "genre": "comedy"},
            >>>     {"id": 2, "title": "Movie 2", "genre": "drama"},
            >>> ]
            >>> async with Client("http://localhost.com", "masterKey") as client:
            >>>     index = client.index("movies")
            >>>     response = await index.add_documents(documents)
            >>>     await client.wait_for_task(client, response.update_id)
        """
        return await _task.async_wait_for_task(
            self.http_client,
            task_id=task_id,
            timeout_in_ms=timeout_in_ms,
            interval_in_ms=interval_in_ms,
            raise_for_status=raise_for_status,
        )

__init__(url, api_key=None, *, timeout=None, verify=True)

Class initializer.

Args:

url: The url to the Meilisearch API (ex: http://localhost:7700)
api_key: The optional API key for Meilisearch. Defaults to None.
timeout: The amount of time in seconds that the client will wait for a response before
    timing out. Defaults to None.
verify: SSL certificates (a.k.a CA bundle) used to
    verify the identity of requested hosts. Either `True` (default CA bundle),
    a path to an SSL certificate file, or `False` (disable verification)
Source code in meilisearch_python_sdk/_client.py
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
def __init__(
    self,
    url: str,
    api_key: str | None = None,
    *,
    timeout: int | None = None,
    verify: str | bool | SSLContext = True,
) -> None:
    """Class initializer.

    Args:

        url: The url to the Meilisearch API (ex: http://localhost:7700)
        api_key: The optional API key for Meilisearch. Defaults to None.
        timeout: The amount of time in seconds that the client will wait for a response before
            timing out. Defaults to None.
        verify: SSL certificates (a.k.a CA bundle) used to
            verify the identity of requested hosts. Either `True` (default CA bundle),
            a path to an SSL certificate file, or `False` (disable verification)
    """
    super().__init__(api_key)

    self.http_client = HttpxAsyncClient(
        base_url=url, timeout=timeout, headers=self._headers, verify=verify
    )
    self._http_requests = AsyncHttpRequests(self.http_client)

aclose() async

Closes the client.

This only needs to be used if the client was not created with a context manager.

Source code in meilisearch_python_sdk/_client.py
161
162
163
164
165
166
async def aclose(self) -> None:
    """Closes the client.

    This only needs to be used if the client was not created with a context manager.
    """
    await self.http_client.aclose()

cancel_tasks(*, uids=None, index_uids=None, statuses=None, types=None, before_enqueued_at=None, after_enqueued_at=None, before_started_at=None, after_finished_at=None) async

Cancel a list of enqueued or processing tasks.

Defaults to cancelling all tasks.

Args:

uids: A list of task UIDs to cancel.
index_uids: A list of index UIDs for which to cancel tasks.
statuses: A list of statuses to cancel.
types: A list of types to cancel.
before_enqueued_at: Cancel tasks that were enqueued before the specified date time.
after_enqueued_at: Cancel tasks that were enqueued after the specified date time.
before_started_at: Cancel tasks that were started before the specified date time.
after_finished_at: Cancel tasks that were finished after the specified date time.

Returns:

The details of the task

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.
MeilisearchTimeoutError: If the connection times out.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>>
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     await client.cancel_tasks(uids=[1, 2])
Source code in meilisearch_python_sdk/_client.py
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
async def cancel_tasks(
    self,
    *,
    uids: list[str] | None = None,
    index_uids: list[str] | None = None,
    statuses: list[str] | None = None,
    types: list[str] | None = None,
    before_enqueued_at: datetime | None = None,
    after_enqueued_at: datetime | None = None,
    before_started_at: datetime | None = None,
    after_finished_at: datetime | None = None,
) -> TaskInfo:
    """Cancel a list of enqueued or processing tasks.

    Defaults to cancelling all tasks.

    Args:

        uids: A list of task UIDs to cancel.
        index_uids: A list of index UIDs for which to cancel tasks.
        statuses: A list of statuses to cancel.
        types: A list of types to cancel.
        before_enqueued_at: Cancel tasks that were enqueued before the specified date time.
        after_enqueued_at: Cancel tasks that were enqueued after the specified date time.
        before_started_at: Cancel tasks that were started before the specified date time.
        after_finished_at: Cancel tasks that were finished after the specified date time.

    Returns:

        The details of the task

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.
        MeilisearchTimeoutError: If the connection times out.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>>
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     await client.cancel_tasks(uids=[1, 2])
    """
    return await _task.async_cancel_tasks(
        self.http_client,
        uids=uids,
        index_uids=index_uids,
        statuses=statuses,
        types=types,
        before_enqueued_at=before_enqueued_at,
        after_enqueued_at=after_enqueued_at,
        before_started_at=before_started_at,
        after_finished_at=after_finished_at,
    )

create_dump() async

Trigger the creation of a Meilisearch dump.

Returns:

The details of the task.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     await client.create_dump()
Source code in meilisearch_python_sdk/_client.py
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
async def create_dump(self) -> TaskInfo:
    """Trigger the creation of a Meilisearch dump.

    Returns:

        The details of the task.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     await client.create_dump()
    """
    response = await self._http_requests.post("dumps")

    return TaskInfo(**response.json())

create_index(uid, primary_key=None, *, settings=None, wait=True, timeout_in_ms=None, plugins=None) async

Creates a new index.

Args:

uid: The index's unique identifier.
primary_key: The primary key of the documents. Defaults to None.
settings: Settings for the index. The settings can also be updated independently of
    creating the index. The advantage to updating them here is updating the settings after
    adding documents will cause the documents to be re-indexed. Because of this it will be
    faster to update them before adding documents. Defaults to None (i.e. default
    Meilisearch index settings).
wait: If set to True and settings are being updated, the index will be returned after
    the settings update has completed. If False it will not wait for settings to complete.
    Default: True
timeout_in_ms: Amount of time in milliseconds to wait before raising a
    MeilisearchTimeoutError. `None` can also be passed to wait indefinitely. Be aware that
    if the `None` option is used the wait time could be very long. Defaults to None.
plugins: Optional plugins can be provided to extend functionality.

Returns:

An instance of AsyncIndex containing the information of the newly created index.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     index = await client.create_index("movies")
Source code in meilisearch_python_sdk/_client.py
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
async def create_index(
    self,
    uid: str,
    primary_key: str | None = None,
    *,
    settings: MeilisearchSettings | None = None,
    wait: bool = True,
    timeout_in_ms: int | None = None,
    plugins: AsyncIndexPlugins | None = None,
) -> AsyncIndex:
    """Creates a new index.

    Args:

        uid: The index's unique identifier.
        primary_key: The primary key of the documents. Defaults to None.
        settings: Settings for the index. The settings can also be updated independently of
            creating the index. The advantage to updating them here is updating the settings after
            adding documents will cause the documents to be re-indexed. Because of this it will be
            faster to update them before adding documents. Defaults to None (i.e. default
            Meilisearch index settings).
        wait: If set to True and settings are being updated, the index will be returned after
            the settings update has completed. If False it will not wait for settings to complete.
            Default: True
        timeout_in_ms: Amount of time in milliseconds to wait before raising a
            MeilisearchTimeoutError. `None` can also be passed to wait indefinitely. Be aware that
            if the `None` option is used the wait time could be very long. Defaults to None.
        plugins: Optional plugins can be provided to extend functionality.

    Returns:

        An instance of AsyncIndex containing the information of the newly created index.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     index = await client.create_index("movies")
    """
    return await AsyncIndex.create(
        self.http_client,
        uid,
        primary_key,
        settings=settings,
        wait=wait,
        timeout_in_ms=timeout_in_ms,
        plugins=plugins,
    )

create_key(key) async

Creates a new API key.

Args:

key: The information to use in creating the key. Note that if an expires_at value
    is included it should be in UTC time.

Returns:

The new API key.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> from meilissearch_async_client.models.client import KeyCreate
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     key_info = KeyCreate(
>>>         description="My new key",
>>>         actions=["search"],
>>>         indexes=["movies"],
>>>     )
>>>     keys = await client.create_key(key_info)
Source code in meilisearch_python_sdk/_client.py
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
async def create_key(self, key: KeyCreate) -> Key:
    """Creates a new API key.

    Args:

        key: The information to use in creating the key. Note that if an expires_at value
            is included it should be in UTC time.

    Returns:

        The new API key.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> from meilissearch_async_client.models.client import KeyCreate
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     key_info = KeyCreate(
        >>>         description="My new key",
        >>>         actions=["search"],
        >>>         indexes=["movies"],
        >>>     )
        >>>     keys = await client.create_key(key_info)
    """
    if is_pydantic_2():
        response = await self._http_requests.post(
            "keys", json.loads(key.model_dump_json(by_alias=True))
        )  # type: ignore[attr-defined]
    else:  # pragma: no cover
        warn(
            "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
            DeprecationWarning,
            stacklevel=2,
        )
        response = await self._http_requests.post("keys", json.loads(key.json(by_alias=True)))  # type: ignore[attr-defined]

    return Key(**response.json())

create_snapshot() async

Trigger the creation of a Meilisearch snapshot.

Returns:

The details of the task.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     await client.create_snapshot()
Source code in meilisearch_python_sdk/_client.py
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
async def create_snapshot(self) -> TaskInfo:
    """Trigger the creation of a Meilisearch snapshot.

    Returns:

        The details of the task.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     await client.create_snapshot()
    """
    response = await self._http_requests.post("snapshots")

    return TaskInfo(**response.json())

delete_index_if_exists(uid) async

Deletes an index if it already exists.

Args:

uid: The index's unique identifier.

Returns:

True if an index was deleted for False if not.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     await client.delete_index_if_exists()
Source code in meilisearch_python_sdk/_client.py
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
async def delete_index_if_exists(self, uid: str) -> bool:
    """Deletes an index if it already exists.

    Args:

        uid: The index's unique identifier.

    Returns:

        True if an index was deleted for False if not.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     await client.delete_index_if_exists()
    """
    response = await self._http_requests.delete(f"indexes/{uid}")
    status = await self.wait_for_task(response.json()["taskUid"], timeout_in_ms=100000)
    if status.status == "succeeded":
        return True
    return False

delete_key(key) async

Deletes an API key.

Args:

key: The key or uid to delete.

Returns:

The Response status code. 204 signifies a successful delete.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     await client.delete_key("abc123")
Source code in meilisearch_python_sdk/_client.py
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
async def delete_key(self, key: str) -> int:
    """Deletes an API key.

    Args:

        key: The key or uid to delete.

    Returns:

        The Response status code. 204 signifies a successful delete.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     await client.delete_key("abc123")
    """
    response = await self._http_requests.delete(f"keys/{key}")
    return response.status_code

delete_tasks(*, uids=None, index_uids=None, statuses=None, types=None, before_enqueued_at=None, after_enqueued_at=None, before_started_at=None, after_finished_at=None) async

Delete a list of tasks.

Defaults to deleting all tasks.

Args:

uids: A list of task UIDs to delete.
index_uids: A list of index UIDs for which to delete tasks.
statuses: A list of statuses to delete.
types: A list of types to delete.
before_enqueued_at: Delete tasks that were enqueued before the specified date time.
after_enqueued_at: Delete tasks that were enqueued after the specified date time.
before_started_at: Delete tasks that were started before the specified date time.
after_finished_at: Delete tasks that were finished after the specified date time.

Returns:

The details of the task

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.
MeilisearchTimeoutError: If the connection times out.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> from meilisearch_python_sdk.task import delete_tasks
>>>
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     await client.delete_tasks(uids=[1, 2])
Source code in meilisearch_python_sdk/_client.py
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
async def delete_tasks(
    self,
    *,
    uids: list[str] | None = None,
    index_uids: list[str] | None = None,
    statuses: list[str] | None = None,
    types: list[str] | None = None,
    before_enqueued_at: datetime | None = None,
    after_enqueued_at: datetime | None = None,
    before_started_at: datetime | None = None,
    after_finished_at: datetime | None = None,
) -> TaskInfo:
    """Delete a list of tasks.

    Defaults to deleting all tasks.

    Args:

        uids: A list of task UIDs to delete.
        index_uids: A list of index UIDs for which to delete tasks.
        statuses: A list of statuses to delete.
        types: A list of types to delete.
        before_enqueued_at: Delete tasks that were enqueued before the specified date time.
        after_enqueued_at: Delete tasks that were enqueued after the specified date time.
        before_started_at: Delete tasks that were started before the specified date time.
        after_finished_at: Delete tasks that were finished after the specified date time.

    Returns:

        The details of the task

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.
        MeilisearchTimeoutError: If the connection times out.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> from meilisearch_python_sdk.task import delete_tasks
        >>>
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     await client.delete_tasks(uids=[1, 2])
    """
    return await _task.async_delete_tasks(
        self.http_client,
        uids=uids,
        index_uids=index_uids,
        statuses=statuses,
        types=types,
        before_enqueued_at=before_enqueued_at,
        after_enqueued_at=after_enqueued_at,
        before_started_at=before_started_at,
        after_finished_at=after_finished_at,
    )

get_all_stats() async

Get stats for all indexes.

Returns:

Information about database size and all indexes.
https://docs.meilisearch.com/reference/api/stats.html

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     stats = await client.get_all_stats()
Source code in meilisearch_python_sdk/_client.py
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
async def get_all_stats(self) -> ClientStats:
    """Get stats for all indexes.

    Returns:

        Information about database size and all indexes.
        https://docs.meilisearch.com/reference/api/stats.html

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     stats = await client.get_all_stats()
    """
    response = await self._http_requests.get("stats")

    return ClientStats(**response.json())

get_index(uid) async

Gets a single index based on the uid of the index.

Args:

uid: The index's unique identifier.

Returns:

An AsyncIndex instance containing the information of the fetched index.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     index = await client.get_index()
Source code in meilisearch_python_sdk/_client.py
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
async def get_index(self, uid: str) -> AsyncIndex:
    """Gets a single index based on the uid of the index.

    Args:

        uid: The index's unique identifier.

    Returns:

        An AsyncIndex instance containing the information of the fetched index.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     index = await client.get_index()
    """
    return await AsyncIndex(self.http_client, uid).fetch_info()

get_indexes(*, offset=None, limit=None) async

Get all indexes. Args:

offset: Number of indexes to skip. The default of None will use the Meilisearch
    default.
limit: Number of indexes to return. The default of None will use the Meilisearch
    default.

Returns:

A list of all indexes.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     indexes = await client.get_indexes()
Source code in meilisearch_python_sdk/_client.py
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
async def get_indexes(
    self, *, offset: int | None = None, limit: int | None = None
) -> list[AsyncIndex] | None:
    """Get all indexes.
    Args:

        offset: Number of indexes to skip. The default of None will use the Meilisearch
            default.
        limit: Number of indexes to return. The default of None will use the Meilisearch
            default.

    Returns:

        A list of all indexes.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     indexes = await client.get_indexes()
    """
    url = _build_offset_limit_url("indexes", offset, limit)
    response = await self._http_requests.get(url)

    if not response.json()["results"]:
        return None

    return [
        AsyncIndex(
            http_client=self.http_client,
            uid=x["uid"],
            primary_key=x["primaryKey"],
            created_at=x["createdAt"],
            updated_at=x["updatedAt"],
        )
        for x in response.json()["results"]
    ]

get_key(key) async

Gets information about a specific API key.

Args:

key: The key for which to retrieve the information.

Returns:

The API key, or `None` if the key is not found.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     keys = await client.get_key("abc123")
Source code in meilisearch_python_sdk/_client.py
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
async def get_key(self, key: str) -> Key:
    """Gets information about a specific API key.

    Args:

        key: The key for which to retrieve the information.

    Returns:

        The API key, or `None` if the key is not found.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     keys = await client.get_key("abc123")
    """
    response = await self._http_requests.get(f"keys/{key}")

    return Key(**response.json())

get_keys(*, offset=None, limit=None) async

Gets the Meilisearch API keys. Args:

offset: Number of indexes to skip. The default of None will use the Meilisearch
    default.
limit: Number of indexes to return. The default of None will use the Meilisearch
    default.

Returns:

API keys.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

from meilisearch_python_sdk import AsyncClient
async with AsyncClient("http://localhost.com", "masterKey") as client:
    keys = await client.get_keys()
Source code in meilisearch_python_sdk/_client.py
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
async def get_keys(self, *, offset: int | None = None, limit: int | None = None) -> KeySearch:
    """Gets the Meilisearch API keys.
    Args:

        offset: Number of indexes to skip. The default of None will use the Meilisearch
            default.
        limit: Number of indexes to return. The default of None will use the Meilisearch
            default.

    Returns:

        API keys.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        from meilisearch_python_sdk import AsyncClient
        async with AsyncClient("http://localhost.com", "masterKey") as client:
            keys = await client.get_keys()
    """
    url = _build_offset_limit_url("keys", offset, limit)
    response = await self._http_requests.get(url)

    return KeySearch(**response.json())

get_or_create_index(uid, primary_key=None, *, plugins=None) async

Get an index, or create it if it doesn't exist.

Args:

uid: The index's unique identifier.
primary_key: The primary key of the documents. Defaults to None.
plugins: Optional plugins can be provided to extend functionality.

Returns:

An instance of AsyncIndex containing the information of the retrieved or newly created index.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.MeilisearchTimeoutError: If the connection times out.
MeilisearchTimeoutError: If the connection times out.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     index = await client.get_or_create_index("movies")
Source code in meilisearch_python_sdk/_client.py
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
async def get_or_create_index(
    self, uid: str, primary_key: str | None = None, *, plugins: AsyncIndexPlugins | None = None
) -> AsyncIndex:
    """Get an index, or create it if it doesn't exist.

    Args:

        uid: The index's unique identifier.
        primary_key: The primary key of the documents. Defaults to None.
        plugins: Optional plugins can be provided to extend functionality.

    Returns:

        An instance of AsyncIndex containing the information of the retrieved or newly created index.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.MeilisearchTimeoutError: If the connection times out.
        MeilisearchTimeoutError: If the connection times out.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     index = await client.get_or_create_index("movies")
    """
    try:
        index_instance = await self.get_index(uid)
    except MeilisearchApiError as err:
        if "index_not_found" not in err.code:
            raise
        index_instance = await self.create_index(uid, primary_key, plugins=plugins)
    return index_instance

get_raw_index(uid) async

Gets the index and returns all the index information rather than an AsyncIndex instance.

Args:

uid: The index's unique identifier.

Returns:

Index information rather than an AsyncIndex instance.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     index = await client.get_raw_index("movies")
Source code in meilisearch_python_sdk/_client.py
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
async def get_raw_index(self, uid: str) -> IndexInfo | None:
    """Gets the index and returns all the index information rather than an AsyncIndex instance.

    Args:

        uid: The index's unique identifier.

    Returns:

        Index information rather than an AsyncIndex instance.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     index = await client.get_raw_index("movies")
    """
    response = await self.http_client.get(f"indexes/{uid}")

    if response.status_code == 404:
        return None

    return IndexInfo(**response.json())

get_raw_indexes(*, offset=None, limit=None) async

Gets all the indexes. Args:

offset: Number of indexes to skip. The default of None will use the Meilisearch
    default.
limit: Number of indexes to return. The default of None will use the Meilisearch
    default.

Returns all the index information rather than an AsyncIndex instance.

Returns:

A list of the Index information rather than an AsyncIndex instances.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     index = await client.get_raw_indexes()
Source code in meilisearch_python_sdk/_client.py
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
async def get_raw_indexes(
    self, *, offset: int | None = None, limit: int | None = None
) -> list[IndexInfo] | None:
    """Gets all the indexes.
    Args:

        offset: Number of indexes to skip. The default of None will use the Meilisearch
            default.
        limit: Number of indexes to return. The default of None will use the Meilisearch
            default.

    Returns all the index information rather than an AsyncIndex instance.

    Returns:

        A list of the Index information rather than an AsyncIndex instances.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     index = await client.get_raw_indexes()
    """
    url = _build_offset_limit_url("indexes", offset, limit)
    response = await self._http_requests.get(url)

    if not response.json()["results"]:
        return None

    return [IndexInfo(**x) for x in response.json()["results"]]

get_task(task_id) async

Get a single task from it's task id.

Args:

task_id: Identifier of the task to retrieve.

Returns:

Results of a task.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.
MeilisearchTimeoutError: If the connection times out.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> from meilisearch_python_sdk.task import get_task
>>>
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     await client.get_task(client, 1244)
Source code in meilisearch_python_sdk/_client.py
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
async def get_task(self, task_id: int) -> TaskResult:
    """Get a single task from it's task id.

    Args:

        task_id: Identifier of the task to retrieve.

    Returns:

        Results of a task.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.
        MeilisearchTimeoutError: If the connection times out.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> from meilisearch_python_sdk.task import get_task
        >>>
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     await client.get_task(client, 1244)
    """
    return await _task.async_get_task(self.http_client, task_id=task_id)

get_tasks(*, index_ids=None, types=None) async

Get multiple tasks.

Args:

index_ids: A list of index UIDs for which to get the tasks. If provided this will get the
    tasks only for the specified indexes, if not all tasks will be returned. Default = None
types: Specify specific task types to retrieve. Default = None

Returns:

Task statuses.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.
MeilisearchTimeoutError: If the connection times out.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>>
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     await client.get_tasks()
Source code in meilisearch_python_sdk/_client.py
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
async def get_tasks(
    self,
    *,
    index_ids: list[str] | None = None,
    types: str | list[str] | None = None,
) -> TaskStatus:
    """Get multiple tasks.

    Args:

        index_ids: A list of index UIDs for which to get the tasks. If provided this will get the
            tasks only for the specified indexes, if not all tasks will be returned. Default = None
        types: Specify specific task types to retrieve. Default = None

    Returns:

        Task statuses.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.
        MeilisearchTimeoutError: If the connection times out.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>>
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     await client.get_tasks()
    """
    return await _task.async_get_tasks(self.http_client, index_ids=index_ids, types=types)

get_version() async

Get the Meilisearch version.

Returns:

Information about the version of Meilisearch.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     version = await client.get_version()
Source code in meilisearch_python_sdk/_client.py
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
async def get_version(self) -> Version:
    """Get the Meilisearch version.

    Returns:

        Information about the version of Meilisearch.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     version = await client.get_version()
    """
    response = await self._http_requests.get("version")

    return Version(**response.json())

health() async

Get health of the Meilisearch server.

Returns:

The status of the Meilisearch server.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     health = await client.get_health()
Source code in meilisearch_python_sdk/_client.py
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
async def health(self) -> Health:
    """Get health of the Meilisearch server.

    Returns:

        The status of the Meilisearch server.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     health = await client.get_health()
    """
    response = await self._http_requests.get("health")

    return Health(**response.json())

index(uid, *, plugins=None)

Create a local reference to an index identified by UID, without making an HTTP call.

Because no network call is made this method is not awaitable.

Args:

uid: The index's unique identifier.
plugins: Optional plugins can be provided to extend functionality.

Returns:

An AsyncIndex instance.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     index = client.index("movies")
Source code in meilisearch_python_sdk/_client.py
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
def index(self, uid: str, *, plugins: AsyncIndexPlugins | None = None) -> AsyncIndex:
    """Create a local reference to an index identified by UID, without making an HTTP call.

    Because no network call is made this method is not awaitable.

    Args:

        uid: The index's unique identifier.
        plugins: Optional plugins can be provided to extend functionality.

    Returns:

        An AsyncIndex instance.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     index = client.index("movies")
    """
    return AsyncIndex(self.http_client, uid=uid, plugins=plugins)

Multi-index search.

Args:

queries: List of SearchParameters

Returns:

Results of the search

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> from meilisearch_python_sdk.models.search import SearchParams
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     queries = [
>>>         SearchParams(index_uid="my_first_index", query"Some search"),
>>>         SearchParams(index_uid="my_second_index", query="Another search")
>>>     ]
>>>     search_results = await client.search(queries)
Source code in meilisearch_python_sdk/_client.py
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
async def multi_search(self, queries: list[SearchParams]) -> list[SearchResultsWithUID]:
    """Multi-index search.

    Args:

        queries: List of SearchParameters

    Returns:

        Results of the search

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> from meilisearch_python_sdk.models.search import SearchParams
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     queries = [
        >>>         SearchParams(index_uid="my_first_index", query"Some search"),
        >>>         SearchParams(index_uid="my_second_index", query="Another search")
        >>>     ]
        >>>     search_results = await client.search(queries)
    """
    url = "multi-search"
    if is_pydantic_2():
        response = await self._http_requests.post(
            url,
            body={"queries": [x.model_dump(by_alias=True) for x in queries]},  # type: ignore[attr-defined]
        )
    else:  # pragma: no cover
        warn(
            "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
            DeprecationWarning,
            stacklevel=2,
        )
        response = await self._http_requests.post(
            url,
            body={"queries": [x.dict(by_alias=True) for x in queries]},  # type: ignore[attr-defined]
        )

    return [SearchResultsWithUID(**x) for x in response.json()["results"]]

swap_indexes(indexes) async

Swap two indexes.

Args:

indexes: A list of tuples, each tuple should contain the indexes to swap.

Returns:

The details of the task.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     index = await client.swap_indexes([("index_a", "index_b")])
Source code in meilisearch_python_sdk/_client.py
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
async def swap_indexes(self, indexes: list[tuple[str, str]]) -> TaskInfo:
    """Swap two indexes.

    Args:

        indexes: A list of tuples, each tuple should contain the indexes to swap.

    Returns:

        The details of the task.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     index = await client.swap_indexes([("index_a", "index_b")])
    """
    processed_indexes = [{"indexes": x} for x in indexes]
    response = await self._http_requests.post("swap-indexes", processed_indexes)

    return TaskInfo(**response.json())

update_key(key) async

Update an API key.

Args:

key: The information to use in updating the key. Note that if an expires_at value
    is included it should be in UTC time.

Returns:

The updated API key.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> from meilissearch_async_client.models.client import KeyUpdate
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>>     key_info = KeyUpdate(
            key="abc123",
>>>         indexes=["*"],
>>>     )
>>>     keys = await client.update_key(key_info)
Source code in meilisearch_python_sdk/_client.py
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
async def update_key(self, key: KeyUpdate) -> Key:
    """Update an API key.

    Args:

        key: The information to use in updating the key. Note that if an expires_at value
            is included it should be in UTC time.

    Returns:

        The updated API key.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> from meilissearch_async_client.models.client import KeyUpdate
        >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
        >>>     key_info = KeyUpdate(
                    key="abc123",
        >>>         indexes=["*"],
        >>>     )
        >>>     keys = await client.update_key(key_info)
    """
    payload = _build_update_key_payload(key)
    response = await self._http_requests.patch(f"keys/{key.key}", payload)

    return Key(**response.json())

wait_for_task(task_id, *, timeout_in_ms=5000, interval_in_ms=50, raise_for_status=False) async

Wait until Meilisearch processes a task, and get its status.

Args:

task_id: Identifier of the task to retrieve.
timeout_in_ms: Amount of time in milliseconds to wait before raising a
    MeilisearchTimeoutError. `None` can also be passed to wait indefinitely. Be aware that
    if the `None` option is used the wait time could be very long. Defaults to 5000.
interval_in_ms: Time interval in miliseconds to sleep between requests. Defaults to 50.
raise_for_status: When set to `True` a MeilisearchTaskFailedError will be raised if a task
    has a failed status. Defaults to False.

Returns:

Details of the processed update status.

Raises:

MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.
MeilisearchTimeoutError: If the connection times out.
MeilisearchTaskFailedError: If `raise_for_status` is `True` and a task has a failed status.

Examples:

>>> from meilisearch_python_sdk import AsyncClient
>>> >>> documents = [
>>>     {"id": 1, "title": "Movie 1", "genre": "comedy"},
>>>     {"id": 2, "title": "Movie 2", "genre": "drama"},
>>> ]
>>> async with Client("http://localhost.com", "masterKey") as client:
>>>     index = client.index("movies")
>>>     response = await index.add_documents(documents)
>>>     await client.wait_for_task(client, response.update_id)
Source code in meilisearch_python_sdk/_client.py
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
async def wait_for_task(
    self,
    task_id: int,
    *,
    timeout_in_ms: int | None = 5000,
    interval_in_ms: int = 50,
    raise_for_status: bool = False,
) -> TaskResult:
    """Wait until Meilisearch processes a task, and get its status.

    Args:

        task_id: Identifier of the task to retrieve.
        timeout_in_ms: Amount of time in milliseconds to wait before raising a
            MeilisearchTimeoutError. `None` can also be passed to wait indefinitely. Be aware that
            if the `None` option is used the wait time could be very long. Defaults to 5000.
        interval_in_ms: Time interval in miliseconds to sleep between requests. Defaults to 50.
        raise_for_status: When set to `True` a MeilisearchTaskFailedError will be raised if a task
            has a failed status. Defaults to False.

    Returns:

        Details of the processed update status.

    Raises:

        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.
        MeilisearchTimeoutError: If the connection times out.
        MeilisearchTaskFailedError: If `raise_for_status` is `True` and a task has a failed status.

    Examples:

        >>> from meilisearch_python_sdk import AsyncClient
        >>> >>> documents = [
        >>>     {"id": 1, "title": "Movie 1", "genre": "comedy"},
        >>>     {"id": 2, "title": "Movie 2", "genre": "drama"},
        >>> ]
        >>> async with Client("http://localhost.com", "masterKey") as client:
        >>>     index = client.index("movies")
        >>>     response = await index.add_documents(documents)
        >>>     await client.wait_for_task(client, response.update_id)
    """
    return await _task.async_wait_for_task(
        self.http_client,
        task_id=task_id,
        timeout_in_ms=timeout_in_ms,
        interval_in_ms=interval_in_ms,
        raise_for_status=raise_for_status,
    )