Skip to content

Index

Index Usage

The Index uses blocking methods, and and should be used when using the Client. When you create a new index with the Client it will create an Index instance.

Index API

Bases: _BaseIndex

Index class gives access to all indexes routes and child routes.

https://docs.meilisearch.com/reference/api/indexes.html

Source code in meilisearch_python_sdk/index.py
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
class Index(_BaseIndex):
    """Index class gives access to all indexes routes and child routes.

    https://docs.meilisearch.com/reference/api/indexes.html
    """

    def __init__(
        self,
        http_client: Client,
        uid: str,
        primary_key: str | None = None,
        created_at: str | datetime | None = None,
        updated_at: str | datetime | None = None,
        plugins: IndexPlugins | None = None,
        json_handler: BuiltinHandler | OrjsonHandler | UjsonHandler | None = None,
        *,
        hits_type: Any = JsonDict,
    ):
        """Class initializer.

        Args:
            http_client: An instance of the Client. This automatically gets passed by the
                Client when creating and Index instance.
            uid: The index's unique identifier.
            primary_key: The primary key of the documents. Defaults to None.
            created_at: The date and time the index was created. Defaults to None.
            updated_at: The date and time the index was last updated. Defaults to None.
            plugins: Optional plugins can be provided to extend functionality.
            json_handler: The module to use for json operations. The options are BuiltinHandler
                (uses the json module from the standard library), OrjsonHandler (uses orjson), or
                UjsonHandler (uses ujson). Note that in order use orjson or ujson the corresponding
                extra needs to be included. Default: BuiltinHandler.
            hits_type: Allows for a custom type to be passed to use for hits. Defaults to
                JsonDict
        """
        super().__init__(
            uid=uid,
            primary_key=primary_key,
            created_at=created_at,
            updated_at=updated_at,
            json_handler=json_handler,
            hits_type=hits_type,
        )
        self.http_client = http_client
        self._http_requests = HttpRequests(http_client, json_handler=self._json_handler)
        self.plugins = plugins

    @cached_property
    def _post_add_documents_plugins(self) -> list[Plugin | DocumentPlugin] | None:
        if not self.plugins or not self.plugins.add_documents_plugins:
            return None

        plugins = [plugin for plugin in self.plugins.add_documents_plugins if plugin.POST_EVENT]

        if not plugins:
            return None

        return plugins

    @cached_property
    def _pre_add_documents_plugins(self) -> list[Plugin | DocumentPlugin] | None:
        if not self.plugins or not self.plugins.add_documents_plugins:
            return None

        plugins = [plugin for plugin in self.plugins.add_documents_plugins if plugin.PRE_EVENT]

        if not plugins:
            return None

        return plugins

    @cached_property
    def _post_delete_all_documents_plugins(self) -> list[Plugin] | None:
        if not self.plugins or not self.plugins.delete_all_documents_plugins:
            return None

        plugins = [
            plugin for plugin in self.plugins.delete_all_documents_plugins if plugin.POST_EVENT
        ]

        if not plugins:
            return None

        return plugins

    @cached_property
    def _pre_delete_all_documents_plugins(self) -> list[Plugin] | None:
        if not self.plugins or not self.plugins.delete_all_documents_plugins:
            return None

        plugins = [
            plugin for plugin in self.plugins.delete_all_documents_plugins if plugin.PRE_EVENT
        ]

        if not plugins:
            return None

        return plugins

    @cached_property
    def _post_delete_document_plugins(self) -> list[Plugin] | None:
        if not self.plugins or not self.plugins.delete_document_plugins:
            return None

        plugins = [plugin for plugin in self.plugins.delete_document_plugins if plugin.POST_EVENT]

        if not plugins:
            return None

        return plugins

    @cached_property
    def _pre_delete_document_plugins(self) -> list[Plugin] | None:
        if not self.plugins or not self.plugins.delete_document_plugins:
            return None

        plugins = [plugin for plugin in self.plugins.delete_document_plugins if plugin.PRE_EVENT]

        if not plugins:
            return None

        return plugins

    @cached_property
    def _post_delete_documents_plugins(self) -> list[Plugin] | None:
        if not self.plugins or not self.plugins.delete_documents_plugins:
            return None

        plugins = [plugin for plugin in self.plugins.delete_documents_plugins if plugin.POST_EVENT]

        if not plugins:
            return None

        return plugins

    @cached_property
    def _pre_delete_documents_plugins(self) -> list[Plugin] | None:
        if not self.plugins or not self.plugins.delete_documents_plugins:
            return None

        plugins = [plugin for plugin in self.plugins.delete_documents_plugins if plugin.PRE_EVENT]

        if not plugins:
            return None

        return plugins

    @cached_property
    def _post_delete_documents_by_filter_plugins(self) -> list[Plugin] | None:
        if not self.plugins or not self.plugins.delete_documents_by_filter_plugins:
            return None

        plugins = [
            plugin
            for plugin in self.plugins.delete_documents_by_filter_plugins
            if plugin.POST_EVENT
        ]

        if not plugins:
            return None

        return plugins

    @cached_property
    def _pre_delete_documents_by_filter_plugins(self) -> list[Plugin] | None:
        if not self.plugins or not self.plugins.delete_documents_by_filter_plugins:
            return None

        plugins = [
            plugin for plugin in self.plugins.delete_documents_by_filter_plugins if plugin.PRE_EVENT
        ]

        if not plugins:
            return None

        return plugins

    @cached_property
    def _post_facet_search_plugins(self) -> list[Plugin] | None:
        if not self.plugins or not self.plugins.facet_search_plugins:
            return None

        plugins = [plugin for plugin in self.plugins.facet_search_plugins if plugin.POST_EVENT]

        if not plugins:
            return None

        return plugins

    @cached_property
    def _pre_facet_search_plugins(self) -> list[Plugin] | None:
        if not self.plugins or not self.plugins.facet_search_plugins:
            return None

        plugins = [plugin for plugin in self.plugins.facet_search_plugins if plugin.PRE_EVENT]

        if not plugins:
            return None

        return plugins

    @cached_property
    def _post_search_plugins(self) -> list[Plugin | PostSearchPlugin] | None:
        if not self.plugins or not self.plugins.search_plugins:
            return None

        plugins = [plugin for plugin in self.plugins.search_plugins if plugin.POST_EVENT]

        if not plugins:
            return None

        return plugins

    @cached_property
    def _pre_search_plugins(self) -> list[Plugin | PostSearchPlugin] | None:
        if not self.plugins or not self.plugins.search_plugins:
            return None

        plugins = [plugin for plugin in self.plugins.search_plugins if plugin.PRE_EVENT]

        if not plugins:
            return None

        return plugins

    @cached_property
    def _post_update_documents_plugins(self) -> list[Plugin | DocumentPlugin] | None:
        if not self.plugins or not self.plugins.update_documents_plugins:
            return None

        plugins = [plugin for plugin in self.plugins.update_documents_plugins if plugin.POST_EVENT]

        if not plugins:
            return None

        return plugins

    @cached_property
    def _pre_update_documents_plugins(self) -> list[Plugin | DocumentPlugin] | None:
        if not self.plugins or not self.plugins.update_documents_plugins:
            return None

        plugins = [plugin for plugin in self.plugins.update_documents_plugins if plugin.PRE_EVENT]

        if not plugins:
            return None

        return plugins

    def delete(self) -> TaskInfo:
        """Deletes the index.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.delete()
        """
        response = self._http_requests.delete(self._base_url_with_uid)
        return TaskInfo(**response.json())

    def delete_if_exists(self) -> bool:
        """Delete the index if it already exists.

        Returns:
            True if the index was deleted or 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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.delete_if_exists()
        """
        response = self.delete()
        status = wait_for_task(self.http_client, response.task_uid, timeout_in_ms=100000)
        if status.status == "succeeded":
            return True

        return False

    def update(self, primary_key: str) -> Self:
        """Update the index primary key.

        Args:
            primary_key: The primary key of the documents.

        Returns:
            An instance of the AsyncIndex with the updated information.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> updated_index = index.update()
        """
        payload = {"primaryKey": primary_key}
        response = self._http_requests.patch(self._base_url_with_uid, payload)
        wait_for_task(self.http_client, response.json()["taskUid"], timeout_in_ms=100000)
        index_response = self._http_requests.get(self._base_url_with_uid)
        self.primary_key = index_response.json()["primaryKey"]
        return self

    def fetch_info(self) -> Self:
        """Gets the infromation about the index.

        Returns:
            An instance of the AsyncIndex containing the retrieved information.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index_info = index.fetch_info()
        """
        response = self._http_requests.get(self._base_url_with_uid)
        index_dict = response.json()
        self._set_fetch_info(
            index_dict["primaryKey"], index_dict["createdAt"], index_dict["updatedAt"]
        )
        return self

    def get_primary_key(self) -> str | None:
        """Get the primary key.

        Returns:
            The primary key for the documents in the 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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> primary_key = index.get_primary_key()
        """
        info = self.fetch_info()
        return info.primary_key

    @classmethod
    def create(
        cls,
        http_client: Client,
        uid: str,
        primary_key: str | None = None,
        *,
        settings: MeilisearchSettings | None = None,
        wait: bool = True,
        timeout_in_ms: int | None = None,
        plugins: IndexPlugins | None = None,
        json_handler: BuiltinHandler | OrjsonHandler | UjsonHandler | None = None,
        hits_type: Any = JsonDict,
    ) -> Self:
        """Creates a new index.

        In general this method should not be used directly and instead the index should be created
        through the `Client`.

        Args:
            http_client: An instance of the Client. This automatically gets passed by the Client
                when creating an Index instance.
            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.
            json_handler: The module to use for json operations. The options are BuiltinHandler
                (uses the json module from the standard library), OrjsonHandler (uses orjson), or
                UjsonHandler (uses ujson). Note that in order use orjson or ujson the corresponding
                extra needs to be included. Default: BuiltinHandler.
            hits_type: Allows for a custom type to be passed to use for hits. Defaults to
                JsonDict

        Returns:
            An instance of Index 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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = index.create(client, "movies")
        """
        if not primary_key:
            payload = {"uid": uid}
        else:
            payload = {"primaryKey": primary_key, "uid": uid}

        url = "indexes"
        handler = json_handler if json_handler else BuiltinHandler()
        http_request = HttpRequests(http_client, handler)
        response = http_request.post(url, payload)
        wait_for_task(http_client, response.json()["taskUid"], timeout_in_ms=timeout_in_ms)
        index_response = http_request.get(f"{url}/{uid}")
        index_dict = index_response.json()
        index = cls(
            http_client=http_client,
            uid=index_dict["uid"],
            primary_key=index_dict["primaryKey"],
            created_at=index_dict["createdAt"],
            updated_at=index_dict["updatedAt"],
            plugins=plugins,
            json_handler=json_handler,
            hits_type=hits_type,
        )

        if settings:
            settings_task = index.update_settings(settings)
            if wait:
                wait_for_task(http_client, settings_task.task_uid, timeout_in_ms=timeout_in_ms)

        return index

    def get_stats(self) -> IndexStats:
        """Get stats of the index.

        Returns:
            Stats of the 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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> stats = index.get_stats()
        """
        response = self._http_requests.get(self._stats_url)

        return IndexStats(**response.json())

    def search(
        self,
        query: str | None = None,
        *,
        offset: int = 0,
        limit: int = 20,
        filter: Filter | None = None,
        facets: list[str] | None = None,
        attributes_to_retrieve: list[str] | None = None,
        attributes_to_crop: list[str] | None = None,
        crop_length: int = 200,
        attributes_to_highlight: list[str] | None = None,
        sort: list[str] | None = None,
        show_matches_position: bool = False,
        highlight_pre_tag: str = "<em>",
        highlight_post_tag: str = "</em>",
        crop_marker: str = "...",
        matching_strategy: Literal["all", "last", "frequency"] = "last",
        hits_per_page: int | None = None,
        page: int | None = None,
        attributes_to_search_on: list[str] | None = None,
        distinct: str | None = None,
        show_ranking_score: bool = False,
        show_ranking_score_details: bool = False,
        ranking_score_threshold: float | None = None,
        vector: list[float] | None = None,
        hybrid: Hybrid | None = None,
        locales: list[str] | None = None,
    ) -> SearchResults:
        """Search the index.

        Args:
            query: String containing the word(s) to search
            offset: Number of documents to skip. Defaults to 0.
            limit: Maximum number of documents returned. Defaults to 20.
            filter: Filter queries by an attribute value. Defaults to None.
            facets: Facets for which to retrieve the matching count. Defaults to None.
            attributes_to_retrieve: Attributes to display in the returned documents.
                Defaults to ["*"].
            attributes_to_crop: Attributes whose values have to be cropped. Defaults to None.
            crop_length: The maximun number of words to display. Defaults to 200.
            attributes_to_highlight: Attributes whose values will contain highlighted matching terms.
                Defaults to None.
            sort: Attributes by which to sort the results. Defaults to None.
            show_matches_position: Defines whether an object that contains information about the
                matches should be returned or not. Defaults to False.
            highlight_pre_tag: The opening tag for highlighting text. Defaults to <em>.
            highlight_post_tag: The closing tag for highlighting text. Defaults to </em>
            crop_marker: Marker to display when the number of words excedes the `crop_length`.
                Defaults to ...
            matching_strategy: Specifies the matching strategy Meilisearch should use. Defaults to
                `last`.
            hits_per_page: Sets the number of results returned per page.
            page: Sets the specific results page to fetch.
            attributes_to_search_on: List of field names. Allow search over a subset of searchable
                attributes without modifying the index settings. Defaults to None.
            distinct: If set the distinct value will return at most one result for the
                filterable attribute. Note that a filterable attributes must be set for this work.
                Defaults to None.
            show_ranking_score: If set to True the ranking score will be returned with each document
                in the search. Defaults to False.
            show_ranking_score_details: If set to True the ranking details will be returned with
                each document in the search. Defaults to False. Note: This parameter can only be
                used with Meilisearch >= v1.3.0, and is experimental in Meilisearch v1.3.0. In order
                to use this feature in Meilisearch v1.3.0 you first need to enable the feature by
                sending a PATCH request to /experimental-features with { "scoreDetails": true }.
                Because this feature is experimental it may be removed or updated causing breaking
                changes in this library without a major version bump so use with caution. This
                feature became stable in Meiliseach v1.7.0.
            ranking_score_threshold: If set, no document whose _rankingScore is under the
                rankingScoreThreshold is returned. The value must be between 0.0 and 1.0. Defaults
                to None.
            vector: List of vectors for vector search. Defaults to None. Note: This parameter can
                only be used with Meilisearch >= v1.3.0, and is experimental in Meilisearch v1.3.0.
                In order to use this feature in Meilisearch v1.3.0 you first need to enable the
                feature by sending a PATCH request to /experimental-features with
                { "vectorStore": true }. Because this feature is experimental it may be removed or
                updated causing breaking changes in this library without a major version bump so use
                with caution.
            hybrid: Hybrid search information. Defaults to None. Note: This parameter can
                only be used with Meilisearch >= v1.6.0, and is experimental in Meilisearch v1.6.0.
                In order to use this feature in Meilisearch v1.6.0 you first need to enable the
                feature by sending a PATCH request to /experimental-features with
                { "vectorStore": true }. Because this feature is experimental it may be removed or
                updated causing breaking changes in this library without a major version bump so use
                with caution.
            locales: Specifies the languages for the search. This parameter can only be used with
                Milisearch >= v1.10.0. Defaults to None letting the Meilisearch pick.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> search_results = index.search("Tron")
        """
        if ranking_score_threshold:
            _validate_ranking_score_threshold(ranking_score_threshold)

        body = _process_search_parameters(
            q=query,
            offset=offset,
            limit=limit,
            filter=filter,
            facets=facets,
            attributes_to_retrieve=attributes_to_retrieve,
            attributes_to_crop=attributes_to_crop,
            crop_length=crop_length,
            attributes_to_highlight=attributes_to_highlight,
            sort=sort,
            show_matches_position=show_matches_position,
            highlight_pre_tag=highlight_pre_tag,
            highlight_post_tag=highlight_post_tag,
            crop_marker=crop_marker,
            matching_strategy=matching_strategy,
            hits_per_page=hits_per_page,
            page=page,
            attributes_to_search_on=attributes_to_search_on,
            distinct=distinct,
            show_ranking_score=show_ranking_score,
            show_ranking_score_details=show_ranking_score_details,
            vector=vector,
            hybrid=hybrid,
            ranking_score_threshold=ranking_score_threshold,
            locales=locales,
        )

        if self._pre_search_plugins:
            Index._run_plugins(
                self._pre_search_plugins,
                Event.PRE,
                query=query,
                offset=offset,
                limit=limit,
                filter=filter,
                facets=facets,
                attributes_to_retrieve=attributes_to_retrieve,
                attributes_to_crop=attributes_to_crop,
                crop_length=crop_length,
                attributes_to_highlight=attributes_to_highlight,
                sort=sort,
                show_matches_position=show_matches_position,
                highlight_pre_tag=highlight_pre_tag,
                highlight_post_tag=highlight_post_tag,
                crop_marker=crop_marker,
                matching_strategy=matching_strategy,
                hits_per_page=hits_per_page,
                page=page,
                attributes_to_search_on=attributes_to_search_on,
                distinct=distinct,
                show_ranking_score=show_ranking_score,
                show_ranking_score_details=show_ranking_score_details,
                vector=vector,
                hybrid=hybrid,
            )

        response = self._http_requests.post(f"{self._base_url_with_uid}/search", body=body)
        result = SearchResults[self.hits_type](**response.json())  # type: ignore[name-defined]
        if self._post_search_plugins:
            post = Index._run_plugins(self._post_search_plugins, Event.POST, search_results=result)
            if post.get("search_result"):
                result = post["search_result"]

        return result

    def facet_search(
        self,
        query: str | None = None,
        *,
        facet_name: str,
        facet_query: str,
        offset: int = 0,
        limit: int = 20,
        filter: Filter | None = None,
        facets: list[str] | None = None,
        attributes_to_retrieve: list[str] | None = None,
        attributes_to_crop: list[str] | None = None,
        crop_length: int = 200,
        attributes_to_highlight: list[str] | None = None,
        sort: list[str] | None = None,
        show_matches_position: bool = False,
        highlight_pre_tag: str = "<em>",
        highlight_post_tag: str = "</em>",
        crop_marker: str = "...",
        matching_strategy: Literal["all", "last", "frequency"] = "last",
        hits_per_page: int | None = None,
        page: int | None = None,
        attributes_to_search_on: list[str] | None = None,
        show_ranking_score: bool = False,
        show_ranking_score_details: bool = False,
        ranking_score_threshold: float | None = None,
        vector: list[float] | None = None,
        locales: list[str] | None = None,
    ) -> FacetSearchResults:
        """Search the index.

        Args:
            query: String containing the word(s) to search
            facet_name: The name of the facet to search
            facet_query: The facet search value
            offset: Number of documents to skip. Defaults to 0.
            limit: Maximum number of documents returned. Defaults to 20.
            filter: Filter queries by an attribute value. Defaults to None.
            facets: Facets for which to retrieve the matching count. Defaults to None.
            attributes_to_retrieve: Attributes to display in the returned documents.
                Defaults to ["*"].
            attributes_to_crop: Attributes whose values have to be cropped. Defaults to None.
            crop_length: The maximun number of words to display. Defaults to 200.
            attributes_to_highlight: Attributes whose values will contain highlighted matching terms.
                Defaults to None.
            sort: Attributes by which to sort the results. Defaults to None.
            show_matches_position: Defines whether an object that contains information about the
                matches should be returned or not. Defaults to False.
            highlight_pre_tag: The opening tag for highlighting text. Defaults to <em>.
            highlight_post_tag: The closing tag for highlighting text. Defaults to </em>
            crop_marker: Marker to display when the number of words excedes the `crop_length`.
                Defaults to ...
            matching_strategy: Specifies the matching strategy Meilisearch should use. Defaults to
                `last`.
            hits_per_page: Sets the number of results returned per page.
            page: Sets the specific results page to fetch.
            attributes_to_search_on: List of field names. Allow search over a subset of searchable
                attributes without modifying the index settings. Defaults to None.
            show_ranking_score: If set to True the ranking score will be returned with each document
                in the search. Defaults to False.
            show_ranking_score_details: If set to True the ranking details will be returned with
                each document in the search. Defaults to False. Note: This parameter can only be
                used with Meilisearch >= v1.3.0, and is experimental in Meilisearch v1.3.0. In order
                to use this feature in Meilisearch v1.3.0 you first need to enable the feature by
                sending a PATCH request to /experimental-features with { "scoreDetails": true }.
                Because this feature is experimental it may be removed or updated causing breaking
                changes in this library without a major version bump so use with caution. This
                feature became stable in Meiliseach v1.7.0.
            ranking_score_threshold: If set, no document whose _rankingScore is under the
                rankingScoreThreshold is returned. The value must be between 0.0 and 1.0. Defaults
                to None.
            vector: List of vectors for vector search. Defaults to None. Note: This parameter can
                only be used with Meilisearch >= v1.3.0, and is experimental in Meilisearch v1.3.0.
                In order to use this feature in Meilisearch v1.3.0 you first need to enable the
                feature by sending a PATCH request to /experimental-features with
                { "vectorStore": true }. Because this feature is experimental it may be removed or
                updated causing breaking changes in this library without a major version bump so use
                with caution.
            locales: Specifies the languages for the search. This parameter can only be used with
                Milisearch >= v1.10.0. Defaults to None letting the Meilisearch pick.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> search_results = index.search(
            >>>     "Tron",
            >>>     facet_name="genre",
            >>>     facet_query="Sci-fi"
            >>> )
        """
        if ranking_score_threshold:
            _validate_ranking_score_threshold(ranking_score_threshold)

        body = _process_search_parameters(
            q=query,
            facet_name=facet_name,
            facet_query=facet_query,
            offset=offset,
            limit=limit,
            filter=filter,
            facets=facets,
            attributes_to_retrieve=attributes_to_retrieve,
            attributes_to_crop=attributes_to_crop,
            crop_length=crop_length,
            attributes_to_highlight=attributes_to_highlight,
            sort=sort,
            show_matches_position=show_matches_position,
            highlight_pre_tag=highlight_pre_tag,
            highlight_post_tag=highlight_post_tag,
            crop_marker=crop_marker,
            matching_strategy=matching_strategy,
            hits_per_page=hits_per_page,
            page=page,
            attributes_to_search_on=attributes_to_search_on,
            show_ranking_score=show_ranking_score,
            show_ranking_score_details=show_ranking_score_details,
            ranking_score_threshold=ranking_score_threshold,
            vector=vector,
            locales=locales,
        )

        if self._pre_facet_search_plugins:
            Index._run_plugins(
                self._pre_facet_search_plugins,
                Event.PRE,
                query=query,
                offset=offset,
                limit=limit,
                filter=filter,
                facets=facets,
                attributes_to_retrieve=attributes_to_retrieve,
                attributes_to_crop=attributes_to_crop,
                crop_length=crop_length,
                attributes_to_highlight=attributes_to_highlight,
                sort=sort,
                show_matches_position=show_matches_position,
                highlight_pre_tag=highlight_pre_tag,
                highlight_post_tag=highlight_post_tag,
                crop_marker=crop_marker,
                matching_strategy=matching_strategy,
                hits_per_page=hits_per_page,
                page=page,
                attributes_to_search_on=attributes_to_search_on,
                show_ranking_score=show_ranking_score,
                show_ranking_score_details=show_ranking_score_details,
                ranking_score_threshold=ranking_score_threshold,
                vector=vector,
            )

        response = self._http_requests.post(f"{self._base_url_with_uid}/facet-search", body=body)
        result = FacetSearchResults(**response.json())
        if self._post_facet_search_plugins:
            post = Index._run_plugins(self._post_facet_search_plugins, Event.POST, result=result)
            if isinstance(post["generic_result"], FacetSearchResults):
                result = post["generic_result"]

        return result

    def search_similar_documents(
        self,
        id: str,
        *,
        offset: int | None = None,
        limit: int | None = None,
        filter: str | None = None,
        embedder: str = "default",
        attributes_to_retrieve: list[str] | None = None,
        show_ranking_score: bool = False,
        show_ranking_score_details: bool = False,
        ranking_score_threshold: float | None = None,
    ) -> SimilarSearchResults:
        """Search the index.

        Args:
            id: The id for the target document that is being used to find similar documents.
            offset: Number of documents to skip. Defaults to 0.
            limit: Maximum number of documents returned. Defaults to 20.
            filter: Filter queries by an attribute value. Defaults to None.
            embedder: The vector DB to use for the search.
            attributes_to_retrieve: Attributes to display in the returned documents.
                Defaults to ["*"].
            show_ranking_score: If set to True the ranking score will be returned with each document
                in the search. Defaults to False.
            show_ranking_score_details: If set to True the ranking details will be returned with
                each document in the search. Defaults to False.
            ranking_score_threshold: If set, no document whose _rankingScore is under the
                rankingScoreThreshold is returned. The value must be between 0.0 and 1.0. Defaults
                to None.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> search_results = index.search_similar_documents("123")
        """
        payload = {
            "id": id,
            "filter": filter,
            "embedder": embedder,
            "attributesToRetrieve": attributes_to_retrieve,
            "showRankingScore": show_ranking_score,
            "showRankingScoreDetails": show_ranking_score_details,
            "rankingScoreThreshold": ranking_score_threshold,
        }

        if offset:
            payload["offset"] = offset

        if limit:
            payload["limit"] = limit

        response = self._http_requests.post(f"{self._base_url_with_uid}/similar", body=payload)

        return SimilarSearchResults[self.hits_type](**response.json())  # type: ignore[name-defined]

    def get_document(self, document_id: str) -> JsonDict:
        """Get one document with given document identifier.

        Args:
            document_id: Unique identifier of the document.

        Returns:
            The document information

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> document = index.get_document("1234")
        """
        response = self._http_requests.get(f"{self._documents_url}/{document_id}")

        return response.json()

    def get_documents(
        self,
        *,
        offset: int = 0,
        limit: int = 20,
        fields: list[str] | None = None,
        filter: Filter | None = None,
    ) -> DocumentsInfo:
        """Get a batch documents from the index.

        Args:
            offset: Number of documents to skip. Defaults to 0.
            limit: Maximum number of documents returnedd. Defaults to 20.
            fields: Document attributes to show. If this value is None then all
                attributes are retrieved. Defaults to None.
            filter: Filter value information. Defaults to None. Note: This parameter can only be
                used with Meilisearch >= v1.2.0

        Returns:
            Documents info.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> documents = index.get_documents()
        """
        parameters: JsonDict = {
            "offset": offset,
            "limit": limit,
        }

        if not filter:
            if fields:
                parameters["fields"] = ",".join(fields)

            url = _build_encoded_url(self._documents_url, parameters)
            response = self._http_requests.get(url)

            return DocumentsInfo(**response.json())

        if fields:
            parameters["fields"] = fields

        parameters["filter"] = filter
        response = self._http_requests.post(f"{self._documents_url}/fetch", body=parameters)

        return DocumentsInfo(**response.json())

    def add_documents(
        self,
        documents: Sequence[JsonMapping],
        primary_key: str | None = None,
        *,
        compress: bool = False,
    ) -> TaskInfo:
        """Add documents to the index.

        Args:
            documents: List of documents.
            primary_key: The primary key of the documents. This will be ignored if already set.
                Defaults to None.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        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 Client
            >>> documents = [
            >>>     {"id": 1, "title": "Movie 1", "genre": "comedy"},
            >>>     {"id": 2, "title": "Movie 2", "genre": "drama"},
            >>> ]
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.add_documents(documents)
        """
        if primary_key:
            url = _build_encoded_url(self._documents_url, {"primaryKey": primary_key})
        else:
            url = self._documents_url

        if self._pre_add_documents_plugins:
            pre = Index._run_plugins(
                self._pre_add_documents_plugins,
                Event.PRE,
                documents=documents,
                primary_key=primary_key,
            )
            if pre.get("document_result"):
                documents = pre["document_result"]

        response = self._http_requests.post(url, documents, compress=compress)
        result = TaskInfo(**response.json())
        if self._post_add_documents_plugins:
            post = Index._run_plugins(self._post_add_documents_plugins, Event.POST, result=result)
            if isinstance(post.get("generic_result"), TaskInfo):
                result = post["generic_result"]

        return result

    def add_documents_in_batches(
        self,
        documents: Sequence[JsonMapping],
        *,
        batch_size: int = 1000,
        primary_key: str | None = None,
        compress: bool = False,
    ) -> list[TaskInfo]:
        """Adds documents in batches to reduce RAM usage with indexing.

        Args:
            documents: List of documents.
            batch_size: The number of documents that should be included in each batch.
                Defaults to 1000.
            primary_key: The primary key of the documents. This will be ignored if already set.
                Defaults to None.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            List of update ids to track the action.

        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 Client
            >>> >>> documents = [
            >>>     {"id": 1, "title": "Movie 1", "genre": "comedy"},
            >>>     {"id": 2, "title": "Movie 2", "genre": "drama"},
            >>> ]
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.add_documents_in_batches(documents)
        """
        return [
            self.add_documents(x, primary_key, compress=compress)
            for x in _batch(documents, batch_size)
        ]

    def add_documents_from_directory(
        self,
        directory_path: Path | str,
        *,
        primary_key: str | None = None,
        document_type: str = "json",
        csv_delimiter: str | None = None,
        combine_documents: bool = True,
        compress: bool = False,
    ) -> list[TaskInfo]:
        """Load all json files from a directory and add the documents to the index.

        Args:
            directory_path: Path to the directory that contains the json files.
            primary_key: The primary key of the documents. This will be ignored if already set.
                Defaults to None.
            document_type: The type of document being added. Accepted types are json, csv, and
                ndjson. For csv files the first row of the document should be a header row contining
                the field names, and ever for should have a title.
            csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
                can only be used if the file is a csv file. Defaults to comma.
            combine_documents: If set to True this will combine the documents from all the files
                before indexing them. Defaults to True.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            The details of the task status.

        Raises:
            InvalidDocumentError: If the docucment is not a valid format for Meilisearch.
            MeilisearchError: If the file path is not valid
            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples
            >>> from pathlib import Path
            >>> from meilisearch_python_sdk import Client
            >>> directory_path = Path("/path/to/directory/containing/files")
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.add_documents_from_directory(directory_path)
        """
        directory = Path(directory_path) if isinstance(directory_path, str) else directory_path

        if combine_documents:
            all_documents = []
            for path in directory.iterdir():
                if path.suffix == f".{document_type}":
                    documents = _load_documents_from_file(
                        path, csv_delimiter, json_handler=self._json_handler
                    )
                    all_documents.append(documents)

            _raise_on_no_documents(all_documents, document_type, directory_path)

            combined = _combine_documents(all_documents)

            response = self.add_documents(combined, primary_key, compress=compress)

            return [response]

        responses = []
        for path in directory.iterdir():
            if path.suffix == f".{document_type}":
                documents = _load_documents_from_file(
                    path, csv_delimiter, json_handler=self._json_handler
                )
                responses.append(self.add_documents(documents, primary_key, compress=compress))

        _raise_on_no_documents(responses, document_type, directory_path)

        return responses

    def add_documents_from_directory_in_batches(
        self,
        directory_path: Path | str,
        *,
        batch_size: int = 1000,
        primary_key: str | None = None,
        document_type: str = "json",
        csv_delimiter: str | None = None,
        combine_documents: bool = True,
        compress: bool = False,
    ) -> list[TaskInfo]:
        """Load all json files from a directory and add the documents to the index in batches.

        Args:
            directory_path: Path to the directory that contains the json files.
            batch_size: The number of documents that should be included in each batch.
                Defaults to 1000.
            primary_key: The primary key of the documents. This will be ignored if already set.
                Defaults to None.
            document_type: The type of document being added. Accepted types are json, csv, and
                ndjson. For csv files the first row of the document should be a header row contining
                the field names, and ever for should have a title.
            csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
                can only be used if the file is a csv file. Defaults to comma.
            combine_documents: If set to True this will combine the documents from all the files
                before indexing them. Defaults to True.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            List of update ids to track the action.

        Raises:
            InvalidDocumentError: If the docucment is not a valid format for Meilisearch.
            MeilisearchError: If the file path is not valid
            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples
            >>> from pathlib import Path
            >>> from meilisearch_python_sdk import Client
            >>> directory_path = Path("/path/to/directory/containing/files")
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.add_documents_from_directory_in_batches(directory_path)
        """
        directory = Path(directory_path) if isinstance(directory_path, str) else directory_path

        if combine_documents:
            all_documents = []
            for path in directory.iterdir():
                if path.suffix == f".{document_type}":
                    documents = _load_documents_from_file(
                        path, csv_delimiter=csv_delimiter, json_handler=self._json_handler
                    )
                    all_documents.append(documents)

            _raise_on_no_documents(all_documents, document_type, directory_path)

            combined = _combine_documents(all_documents)

            return self.add_documents_in_batches(
                combined,
                batch_size=batch_size,
                primary_key=primary_key,
                compress=compress,
            )

        responses: list[TaskInfo] = []
        for path in directory.iterdir():
            if path.suffix == f".{document_type}":
                documents = _load_documents_from_file(
                    path, csv_delimiter, json_handler=self._json_handler
                )
                responses.extend(
                    self.add_documents_in_batches(
                        documents,
                        batch_size=batch_size,
                        primary_key=primary_key,
                        compress=compress,
                    )
                )

        _raise_on_no_documents(responses, document_type, directory_path)

        return responses

    def add_documents_from_file(
        self,
        file_path: Path | str,
        primary_key: str | None = None,
        *,
        compress: bool = False,
    ) -> TaskInfo:
        """Add documents to the index from a json file.

        Args:
            file_path: Path to the json file.
            primary_key: The primary key of the documents. This will be ignored if already set.
                Defaults to None.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            The details of the task status.

        Raises:
            InvalidDocumentError: If the docucment is not a valid format for Meilisearch.
            MeilisearchError: If the file path is not valid
            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples
            >>> from pathlib import Path
            >>> from meilisearch_python_sdk import Client
            >>> file_path = Path("/path/to/file.json")
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.add_documents_from_file(file_path)
        """
        documents = _load_documents_from_file(file_path, json_handler=self._json_handler)

        return self.add_documents(documents, primary_key=primary_key, compress=compress)

    def add_documents_from_file_in_batches(
        self,
        file_path: Path | str,
        *,
        batch_size: int = 1000,
        primary_key: str | None = None,
        csv_delimiter: str | None = None,
        compress: bool = False,
    ) -> list[TaskInfo]:
        """Adds documents form a json file in batches to reduce RAM usage with indexing.

        Args:
            file_path: Path to the json file.
            batch_size: The number of documents that should be included in each batch.
                Defaults to 1000.
            primary_key: The primary key of the documents. This will be ignored if already set.
                Defaults to None.
            csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
                can only be used if the file is a csv file. Defaults to comma.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            List of update ids to track the action.

        Raises:
            InvalidDocumentError: If the docucment is not a valid format for Meilisearch.
            MeilisearchError: If the file path is not valid
            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples
            >>> from pathlib import Path
            >>> from meilisearch_python_sdk import Client
            >>> file_path = Path("/path/to/file.json")
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.add_documents_from_file_in_batches(file_path)
        """
        documents = _load_documents_from_file(
            file_path, csv_delimiter, json_handler=self._json_handler
        )

        return self.add_documents_in_batches(
            documents,
            batch_size=batch_size,
            primary_key=primary_key,
            compress=compress,
        )

    def add_documents_from_raw_file(
        self,
        file_path: Path | str,
        primary_key: str | None = None,
        *,
        csv_delimiter: str | None = None,
        compress: bool = False,
    ) -> TaskInfo:
        """Directly send csv or ndjson files to Meilisearch without pre-processing.

        The can reduce RAM usage from Meilisearch during indexing, but does not include the option
        for batching.

        Args:
            file_path: The path to the file to send to Meilisearch. Only csv and ndjson files are
                allowed.
            primary_key: The primary key of the documents. This will be ignored if already set.
                Defaults to None.
            csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
                can only be used if the file is a csv file. Defaults to comma.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            The details of the task.

        Raises:
            ValueError: If the file is not a csv or ndjson file, or if a csv_delimiter is sent for
                a non-csv file.
            MeilisearchError: If the file path is not valid
            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples
            >>> from pathlib import Path
            >>> from meilisearch_python_sdk import Client
            >>> file_path = Path("/path/to/file.csv")
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.add_documents_from_raw_file(file_path)
        """
        upload_path = Path(file_path) if isinstance(file_path, str) else file_path
        if not upload_path.exists():
            raise MeilisearchError("No file found at the specified path")

        if upload_path.suffix not in (".csv", ".ndjson"):
            raise ValueError("Only csv and ndjson files can be sent as binary files")

        if csv_delimiter and upload_path.suffix != ".csv":
            raise ValueError("A csv_delimiter can only be used with csv files")

        if (
            csv_delimiter
            and len(csv_delimiter) != 1
            or csv_delimiter
            and not csv_delimiter.isascii()
        ):
            raise ValueError("csv_delimiter must be a single ascii character")

        content_type = "text/csv" if upload_path.suffix == ".csv" else "application/x-ndjson"
        parameters = {}

        if primary_key:
            parameters["primaryKey"] = primary_key
        if csv_delimiter:
            parameters["csvDelimiter"] = csv_delimiter

        if parameters:
            url = _build_encoded_url(self._documents_url, parameters)
        else:
            url = self._documents_url

        with open(upload_path) as f:
            data = f.read()

        response = self._http_requests.post(
            url, body=data, content_type=content_type, compress=compress
        )

        return TaskInfo(**response.json())

    def edit_documents(
        self, function: str, *, context: JsonDict | None = None, filter: str | None = None
    ) -> TaskInfo:
        """Edit documents with a function.

        Edit documents is only available in Meilisearch >= v1.10.0, and is experimental in
        Meilisearch v1.10.0. In order to use this feature you first need to enable it by
        sending a PATCH request to /experimental-features with { "editDocumentsByFunction": true }.

        Args:
            function: Rhai function to use to update the documents.
            context: Parameters to use in the function. Defaults to None.
            filter: Filter the documents before applying the function. Defaults to None.

        Returns:
            The details of the task.

        Raises:
            MeilisearchError: If the file path is not valid
            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples
            >>> from meilisearch_python_sdk import Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.edit_documents("doc.title = `${doc.title.to_upper()}`")
        """
        url = f"{self._documents_url}/edit"
        payload: JsonDict = {"function": function}

        if context:
            payload["context"] = context

        if filter:
            payload["filter"] = filter

        response = self._http_requests.post(url, payload)

        return TaskInfo(**response.json())

    def update_documents(
        self,
        documents: Sequence[JsonMapping],
        primary_key: str | None = None,
        *,
        compress: bool = False,
    ) -> TaskInfo:
        """Update documents in the index.

        Args:
            documents: List of documents.
            primary_key: The primary key of the documents. This will be ignored if already set.
                Defaults to None.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        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 Client
            >>> documents = [
            >>>     {"id": 1, "title": "Movie 1", "genre": "comedy"},
            >>>     {"id": 2, "title": "Movie 2", "genre": "drama"},
            >>> ]
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_documents(documents)
        """
        if primary_key:
            url = _build_encoded_url(self._documents_url, {"primaryKey": primary_key})
        else:
            url = self._documents_url

        if self._pre_update_documents_plugins:
            pre = Index._run_plugins(
                self._pre_update_documents_plugins,
                Event.PRE,
                documents=documents,
                primary_key=primary_key,
            )
            if pre.get("document_result"):
                documents = pre["document_result"]

        response = self._http_requests.put(url, documents, compress=compress)
        result = TaskInfo(**response.json())
        if self._post_update_documents_plugins:
            post = Index._run_plugins(
                self._post_update_documents_plugins, Event.POST, result=result
            )
            if isinstance(post.get("generic_result"), TaskInfo):
                result = post["generic_result"]

        return result

    def update_documents_in_batches(
        self,
        documents: Sequence[JsonMapping],
        *,
        batch_size: int = 1000,
        primary_key: str | None = None,
        compress: bool = False,
    ) -> list[TaskInfo]:
        """Update documents in batches to reduce RAM usage with indexing.

        Each batch tries to fill the max_payload_size

        Args:
            documents: List of documents.
            batch_size: The number of documents that should be included in each batch.
                Defaults to 1000.
            primary_key: The primary key of the documents. This will be ignored if already set.
                Defaults to None.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            List of update ids to track the action.

        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 Client
            >>> documents = [
            >>>     {"id": 1, "title": "Movie 1", "genre": "comedy"},
            >>>     {"id": 2, "title": "Movie 2", "genre": "drama"},
            >>> ]
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_documents_in_batches(documents)
        """
        return [
            self.update_documents(x, primary_key, compress=compress)
            for x in _batch(documents, batch_size)
        ]

    def update_documents_from_directory(
        self,
        directory_path: Path | str,
        *,
        primary_key: str | None = None,
        document_type: str = "json",
        csv_delimiter: str | None = None,
        combine_documents: bool = True,
        compress: bool = False,
    ) -> list[TaskInfo]:
        """Load all json files from a directory and update the documents.

        Args:
            directory_path: Path to the directory that contains the json files.
            primary_key: The primary key of the documents. This will be ignored if already set.
                Defaults to None.
            document_type: The type of document being added. Accepted types are json, csv, and
                ndjson. For csv files the first row of the document should be a header row contining
                the field names, and ever for should have a title.
            csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
                can only be used if the file is a csv file. Defaults to comma.
            combine_documents: If set to True this will combine the documents from all the files
                before indexing them. Defaults to True.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            The details of the task status.

        Raises:
            InvalidDocumentError: If the docucment is not a valid format for Meilisearch.
            MeilisearchError: If the file path is not valid
            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples
            >>> from pathlib import Path
            >>> from meilisearch_python_sdk import Client
            >>> directory_path = Path("/path/to/directory/containing/files")
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_documents_from_directory(directory_path)
        """
        directory = Path(directory_path) if isinstance(directory_path, str) else directory_path

        if combine_documents:
            all_documents = []
            for path in directory.iterdir():
                if path.suffix == f".{document_type}":
                    documents = _load_documents_from_file(
                        path, csv_delimiter, json_handler=self._json_handler
                    )
                    all_documents.append(documents)

            _raise_on_no_documents(all_documents, document_type, directory_path)

            combined = _combine_documents(all_documents)

            response = self.update_documents(combined, primary_key, compress=compress)
            return [response]

        responses = []
        for path in directory.iterdir():
            if path.suffix == f".{document_type}":
                documents = _load_documents_from_file(
                    path, csv_delimiter, json_handler=self._json_handler
                )
                responses.append(self.update_documents(documents, primary_key, compress=compress))

        _raise_on_no_documents(responses, document_type, directory_path)

        return responses

    def update_documents_from_directory_in_batches(
        self,
        directory_path: Path | str,
        *,
        batch_size: int = 1000,
        primary_key: str | None = None,
        document_type: str = "json",
        csv_delimiter: str | None = None,
        combine_documents: bool = True,
        compress: bool = False,
    ) -> list[TaskInfo]:
        """Load all json files from a directory and update the documents.

        Args:
            directory_path: Path to the directory that contains the json files.
            batch_size: The number of documents that should be included in each batch.
                Defaults to 1000.
            primary_key: The primary key of the documents. This will be ignored if already set.
                Defaults to None.
            document_type: The type of document being added. Accepted types are json, csv, and
                ndjson. For csv files the first row of the document should be a header row contining
                the field names, and ever for should have a title.
            csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
                can only be used if the file is a csv file. Defaults to comma.
            combine_documents: If set to True this will combine the documents from all the files
                before indexing them. Defaults to True.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            List of update ids to track the action.

        Raises:
            InvalidDocumentError: If the docucment is not a valid format for Meilisearch.
            MeilisearchError: If the file path is not valid
            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples
            >>> from pathlib import Path
            >>> from meilisearch_python_sdk import Client
            >>> directory_path = Path("/path/to/directory/containing/files")
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_documents_from_directory_in_batches(directory_path)
        """
        directory = Path(directory_path) if isinstance(directory_path, str) else directory_path

        if combine_documents:
            all_documents = []
            for path in directory.iterdir():
                if path.suffix == f".{document_type}":
                    documents = _load_documents_from_file(
                        path, csv_delimiter, json_handler=self._json_handler
                    )
                    all_documents.append(documents)

            _raise_on_no_documents(all_documents, document_type, directory_path)

            combined = _combine_documents(all_documents)

            return self.update_documents_in_batches(
                combined,
                batch_size=batch_size,
                primary_key=primary_key,
                compress=compress,
            )

        responses: list[TaskInfo] = []

        for path in directory.iterdir():
            if path.suffix == f".{document_type}":
                documents = _load_documents_from_file(
                    path, csv_delimiter, json_handler=self._json_handler
                )
                responses.extend(
                    self.update_documents_in_batches(
                        documents,
                        batch_size=batch_size,
                        primary_key=primary_key,
                        compress=compress,
                    )
                )

        _raise_on_no_documents(responses, document_type, directory_path)

        return responses

    def update_documents_from_file(
        self,
        file_path: Path | str,
        primary_key: str | None = None,
        csv_delimiter: str | None = None,
        *,
        compress: bool = False,
    ) -> TaskInfo:
        """Add documents in the index from a json file.

        Args:
            file_path: Path to the json file.
            primary_key: The primary key of the documents. This will be ignored if already set.
                Defaults to None.
            csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
                can only be used if the file is a csv file. Defaults to comma.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            The details of the task status.

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

        Examples
            >>> from pathlib import Path
            >>> from meilisearch_python_sdk import Client
            >>> file_path = Path("/path/to/file.json")
            >>> client = Client("http://localhost.com", "masterKey") as client:
            >>> index = client.index("movies")
            >>> index.update_documents_from_file(file_path)
        """
        documents = _load_documents_from_file(
            file_path, csv_delimiter, json_handler=self._json_handler
        )

        return self.update_documents(documents, primary_key=primary_key, compress=compress)

    def update_documents_from_file_in_batches(
        self,
        file_path: Path | str,
        *,
        batch_size: int = 1000,
        primary_key: str | None = None,
        compress: bool = False,
    ) -> list[TaskInfo]:
        """Updates documents form a json file in batches to reduce RAM usage with indexing.

        Args:
            file_path: Path to the json file.
            batch_size: The number of documents that should be included in each batch.
                Defaults to 1000.
            primary_key: The primary key of the documents. This will be ignored if already set.
                Defaults to None.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            List of update ids to track the action.

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

        Examples
            >>> from pathlib import Path
            >>> from meilisearch_python_sdk import Client
            >>> file_path = Path("/path/to/file.json")
            >>> client = Client("http://localhost.com", "masterKey") as client:
            >>> index = client.index("movies")
            >>> index.update_documents_from_file_in_batches(file_path)
        """
        documents = _load_documents_from_file(file_path, json_handler=self._json_handler)

        return self.update_documents_in_batches(
            documents,
            batch_size=batch_size,
            primary_key=primary_key,
            compress=compress,
        )

    def update_documents_from_raw_file(
        self,
        file_path: Path | str,
        primary_key: str | None = None,
        csv_delimiter: str | None = None,
        *,
        compress: bool = False,
    ) -> TaskInfo:
        """Directly send csv or ndjson files to Meilisearch without pre-processing.

        The can reduce RAM usage from Meilisearch during indexing, but does not include the option
        for batching.

        Args:
            file_path: The path to the file to send to Meilisearch. Only csv and ndjson files are
                allowed.
            primary_key: The primary key of the documents. This will be ignored if already set.
                Defaults to None.
            csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
                can only be used if the file is a csv file. Defaults to comma.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            The details of the task status.

        Raises:
            ValueError: If the file is not a csv or ndjson file, or if a csv_delimiter is sent for
                a non-csv file.
            MeilisearchError: If the file path is not valid
            MeilisearchCommunicationError: If there was an error communicating with the server.
            MeilisearchApiError: If the Meilisearch API returned an error.

        Examples
            >>> from pathlib import Path
            >>> from meilisearch_python_sdk import Client
            >>> file_path = Path("/path/to/file.csv")
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_documents_from_raw_file(file_path)
        """
        upload_path = Path(file_path) if isinstance(file_path, str) else file_path
        if not upload_path.exists():
            raise MeilisearchError("No file found at the specified path")

        if upload_path.suffix not in (".csv", ".ndjson"):
            raise ValueError("Only csv and ndjson files can be sent as binary files")

        if csv_delimiter and upload_path.suffix != ".csv":
            raise ValueError("A csv_delimiter can only be used with csv files")

        if (
            csv_delimiter
            and len(csv_delimiter) != 1
            or csv_delimiter
            and not csv_delimiter.isascii()
        ):
            raise ValueError("csv_delimiter must be a single ascii character")

        content_type = "text/csv" if upload_path.suffix == ".csv" else "application/x-ndjson"
        parameters = {}

        if primary_key:
            parameters["primaryKey"] = primary_key
        if csv_delimiter:
            parameters["csvDelimiter"] = csv_delimiter

        if parameters:
            url = _build_encoded_url(self._documents_url, parameters)
        else:
            url = self._documents_url

        with open(upload_path) as f:
            data = f.read()

        response = self._http_requests.put(
            url, body=data, content_type=content_type, compress=compress
        )

        return TaskInfo(**response.json())

    def delete_document(self, document_id: str) -> TaskInfo:
        """Delete one document from the index.

        Args:
            document_id: Unique identifier of the document.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.delete_document("1234")
        """
        if self._pre_delete_document_plugins:
            Index._run_plugins(
                self._pre_delete_document_plugins, Event.PRE, document_id=document_id
            )

        response = self._http_requests.delete(f"{self._documents_url}/{document_id}")
        result = TaskInfo(**response.json())
        if self._post_delete_document_plugins:
            post = Index._run_plugins(self._post_delete_document_plugins, Event.POST, result=result)
            if isinstance(post.get("generic_result"), TaskInfo):
                result = post["generic_result"]

        return result

    def delete_documents(self, ids: list[str]) -> TaskInfo:
        """Delete multiple documents from the index.

        Args:
            ids: List of unique identifiers of documents.

        Returns:
            List of update ids to track the action.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.delete_documents(["1234", "5678"])
        """
        if self._pre_delete_documents_plugins:
            Index._run_plugins(self._pre_delete_documents_plugins, Event.PRE, ids=ids)

        response = self._http_requests.post(f"{self._documents_url}/delete-batch", ids)
        result = TaskInfo(**response.json())
        if self._post_delete_documents_plugins:
            post = Index._run_plugins(
                self._post_delete_documents_plugins, Event.POST, result=result
            )
            if isinstance(post.get("generic_result"), TaskInfo):
                result = post["generic_result"]

        return result

    def delete_documents_by_filter(self, filter: Filter) -> TaskInfo:
        """Delete documents from the index by filter.

        Args:
            filter: The filter value information.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.delete_documents_by_filter("genre=horor"))
        """
        if self._pre_delete_documents_by_filter_plugins:
            Index._run_plugins(
                self._pre_delete_documents_by_filter_plugins, Event.PRE, filter=filter
            )

        response = self._http_requests.post(
            f"{self._documents_url}/delete", body={"filter": filter}
        )
        result = TaskInfo(**response.json())
        if self._post_delete_documents_by_filter_plugins:
            post = Index._run_plugins(
                self._post_delete_documents_by_filter_plugins, Event.POST, result=result
            )
            if isinstance(post.get("generic_result"), TaskInfo):
                result = post["generic_result"]

        return result

    def delete_documents_in_batches_by_filter(
        self, filters: list[str | list[str | list[str]]]
    ) -> list[TaskInfo]:
        """Delete batches of documents from the index by filter.

        Args:
            filters: A list of filter value information.

        Returns:
            The a list of details of the task statuses.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.delete_documents_in_batches_by_filter(
            >>>     [
            >>>         "genre=horor"),
            >>>         "release_date=1520035200"),
            >>>     ]
            >>> )
        """
        return [self.delete_documents_by_filter(filter) for filter in filters]

    def delete_all_documents(self) -> TaskInfo:
        """Delete all documents from the index.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.delete_all_document()
        """
        if self._pre_delete_all_documents_plugins:
            Index._run_plugins(self._pre_delete_all_documents_plugins, Event.PRE)

        response = self._http_requests.delete(self._documents_url)
        result = TaskInfo(**response.json())
        if self._post_delete_all_documents_plugins:
            post = Index._run_plugins(
                self._post_delete_all_documents_plugins, Event.POST, result=result
            )
            if isinstance(post.get("generic_result"), TaskInfo):
                result = post["generic_result"]

        return result

    def get_settings(self) -> MeilisearchSettings:
        """Get settings of the index.

        Returns:
            Settings of the 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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> settings = index.get_settings()
        """
        response = self._http_requests.get(self._settings_url)
        response_json = response.json()
        settings = MeilisearchSettings(**response_json)

        if response_json.get("embedders"):
            # TODO: Add back after embedder setting issue fixed https://github.com/meilisearch/meilisearch/issues/4585
            settings.embedders = _embedder_json_to_settings_model(  # pragma: no cover
                response_json["embedders"]
            )

        return settings

    def update_settings(self, body: MeilisearchSettings, *, compress: bool = False) -> TaskInfo:
        """Update settings of the index.

        Args:
            body: Settings of the index.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            The details of the task status.

        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 Client
            >>> from meilisearch_python_sdk import MeilisearchSettings
            >>> new_settings = MeilisearchSettings(
            >>>     synonyms={"wolverine": ["xmen", "logan"], "logan": ["wolverine"]},
            >>>     stop_words=["the", "a", "an"],
            >>>     ranking_rules=[
            >>>         "words",
            >>>         "typo",
            >>>         "proximity",
            >>>         "attribute",
            >>>         "sort",
            >>>         "exactness",
            >>>         "release_date:desc",
            >>>         "rank:desc",
            >>>    ],
            >>>    filterable_attributes=["genre", "director"],
            >>>    distinct_attribute="url",
            >>>    searchable_attributes=["title", "description", "genre"],
            >>>    displayed_attributes=["title", "description", "genre", "release_date"],
            >>>    sortable_attributes=["title", "release_date"],
            >>> )
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_settings(new_settings)
        """
        body_dict = {
            k: v
            for k, v in body.model_dump(by_alias=True, exclude_none=True).items()
            if v is not None
        }
        response = self._http_requests.patch(self._settings_url, body_dict, compress=compress)

        return TaskInfo(**response.json())

    def reset_settings(self) -> TaskInfo:
        """Reset settings of the index to default values.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.reset_settings()
        """
        response = self._http_requests.delete(self._settings_url)

        return TaskInfo(**response.json())

    def get_ranking_rules(self) -> list[str]:
        """Get ranking rules of the index.

        Returns:
            List containing the ranking rules of the 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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> ranking_rules = index.get_ranking_rules()
        """
        response = self._http_requests.get(f"{self._settings_url}/ranking-rules")

        return response.json()

    def update_ranking_rules(self, ranking_rules: list[str], *, compress: bool = False) -> TaskInfo:
        """Update ranking rules of the index.

        Args:
            ranking_rules: List containing the ranking rules.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            The details of the task status.

        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 Client
            >>> ranking_rules=[
            >>>      "words",
            >>>      "typo",
            >>>      "proximity",
            >>>      "attribute",
            >>>      "sort",
            >>>      "exactness",
            >>>      "release_date:desc",
            >>>      "rank:desc",
            >>> ],
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_ranking_rules(ranking_rules)
        """
        response = self._http_requests.put(
            f"{self._settings_url}/ranking-rules", ranking_rules, compress=compress
        )

        return TaskInfo(**response.json())

    def reset_ranking_rules(self) -> TaskInfo:
        """Reset ranking rules of the index to default values.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.reset_ranking_rules()
        """
        response = self._http_requests.delete(f"{self._settings_url}/ranking-rules")

        return TaskInfo(**response.json())

    def get_distinct_attribute(self) -> str | None:
        """Get distinct attribute of the index.

        Returns:
            String containing the distinct attribute of the index. If no distinct attribute
                `None` is returned.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> distinct_attribute = index.get_distinct_attribute()
        """
        response = self._http_requests.get(f"{self._settings_url}/distinct-attribute")

        if not response.json():
            return None

        return response.json()

    def update_distinct_attribute(self, body: str, *, compress: bool = False) -> TaskInfo:
        """Update distinct attribute of the index.

        Args:
            body: Distinct attribute.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_distinct_attribute("url")
        """
        response = self._http_requests.put(
            f"{self._settings_url}/distinct-attribute", body, compress=compress
        )

        return TaskInfo(**response.json())

    def reset_distinct_attribute(self) -> TaskInfo:
        """Reset distinct attribute of the index to default values.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.reset_distinct_attributes()
        """
        response = self._http_requests.delete(f"{self._settings_url}/distinct-attribute")

        return TaskInfo(**response.json())

    def get_searchable_attributes(self) -> list[str]:
        """Get searchable attributes of the index.

        Returns:
            List containing the searchable attributes of the 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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> searchable_attributes = index.get_searchable_attributes()
        """
        response = self._http_requests.get(f"{self._settings_url}/searchable-attributes")

        return response.json()

    def update_searchable_attributes(self, body: list[str], *, compress: bool = False) -> TaskInfo:
        """Update searchable attributes of the index.

        Args:
            body: List containing the searchable attributes.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_searchable_attributes(["title", "description", "genre"])
        """
        response = self._http_requests.put(
            f"{self._settings_url}/searchable-attributes", body, compress=compress
        )

        return TaskInfo(**response.json())

    def reset_searchable_attributes(self) -> TaskInfo:
        """Reset searchable attributes of the index to default values.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.reset_searchable_attributes()
        """
        response = self._http_requests.delete(f"{self._settings_url}/searchable-attributes")

        return TaskInfo(**response.json())

    def get_displayed_attributes(self) -> list[str]:
        """Get displayed attributes of the index.

        Returns:
            List containing the displayed attributes of the 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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> displayed_attributes = index.get_displayed_attributes()
        """
        response = self._http_requests.get(f"{self._settings_url}/displayed-attributes")

        return response.json()

    def update_displayed_attributes(self, body: list[str], *, compress: bool = False) -> TaskInfo:
        """Update displayed attributes of the index.

        Args:
            body: List containing the displayed attributes.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_displayed_attributes(
            >>>     ["title", "description", "genre", "release_date"]
            >>> )
        """
        response = self._http_requests.put(
            f"{self._settings_url}/displayed-attributes", body, compress=compress
        )

        return TaskInfo(**response.json())

    def reset_displayed_attributes(self) -> TaskInfo:
        """Reset displayed attributes of the index to default values.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.reset_displayed_attributes()
        """
        response = self._http_requests.delete(f"{self._settings_url}/displayed-attributes")

        return TaskInfo(**response.json())

    def get_stop_words(self) -> list[str] | None:
        """Get stop words of the index.

        Returns:
            List containing the stop words of the 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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> stop_words = index.get_stop_words()
        """
        response = self._http_requests.get(f"{self._settings_url}/stop-words")

        if not response.json():
            return None

        return response.json()

    def update_stop_words(self, body: list[str], *, compress: bool = False) -> TaskInfo:
        """Update stop words of the index.

        Args:
            body: List containing the stop words of the index.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_stop_words(["the", "a", "an"])
        """
        response = self._http_requests.put(
            f"{self._settings_url}/stop-words", body, compress=compress
        )

        return TaskInfo(**response.json())

    def reset_stop_words(self) -> TaskInfo:
        """Reset stop words of the index to default values.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.reset_stop_words()
        """
        response = self._http_requests.delete(f"{self._settings_url}/stop-words")

        return TaskInfo(**response.json())

    def get_synonyms(self) -> dict[str, list[str]] | None:
        """Get synonyms of the index.

        Returns:
            The synonyms of the 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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> synonyms = index.get_synonyms()
        """
        response = self._http_requests.get(f"{self._settings_url}/synonyms")

        if not response.json():
            return None

        return response.json()

    def update_synonyms(self, body: dict[str, list[str]], *, compress: bool = False) -> TaskInfo:
        """Update synonyms of the index.

        Args:
            body: The synonyms of the index.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey") as client:
            >>> index = client.index("movies")
            >>> index.update_synonyms(
            >>>     {"wolverine": ["xmen", "logan"], "logan": ["wolverine"]}
            >>> )
        """
        response = self._http_requests.put(
            f"{self._settings_url}/synonyms", body, compress=compress
        )

        return TaskInfo(**response.json())

    def reset_synonyms(self) -> TaskInfo:
        """Reset synonyms of the index to default values.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.reset_synonyms()
        """
        response = self._http_requests.delete(f"{self._settings_url}/synonyms")

        return TaskInfo(**response.json())

    def get_filterable_attributes(self) -> list[str] | None:
        """Get filterable attributes of the index.

        Returns:
            List containing the filterable attributes of the 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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> filterable_attributes = index.get_filterable_attributes()
        """
        response = self._http_requests.get(f"{self._settings_url}/filterable-attributes")

        if not response.json():
            return None

        return response.json()

    def update_filterable_attributes(self, body: list[str], *, compress: bool = False) -> TaskInfo:
        """Update filterable attributes of the index.

        Args:
            body: List containing the filterable attributes of the index.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_filterable_attributes(["genre", "director"])
        """
        response = self._http_requests.put(
            f"{self._settings_url}/filterable-attributes", body, compress=compress
        )

        return TaskInfo(**response.json())

    def reset_filterable_attributes(self) -> TaskInfo:
        """Reset filterable attributes of the index to default values.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.reset_filterable_attributes()
        """
        response = self._http_requests.delete(f"{self._settings_url}/filterable-attributes")

        return TaskInfo(**response.json())

    def get_sortable_attributes(self) -> list[str]:
        """Get sortable attributes of the AsyncIndex.

        Returns:
            List containing the sortable attributes of the AsyncIndex.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> sortable_attributes = index.get_sortable_attributes()
        """
        response = self._http_requests.get(f"{self._settings_url}/sortable-attributes")

        return response.json()

    def update_sortable_attributes(
        self, sortable_attributes: list[str], *, compress: bool = False
    ) -> TaskInfo:
        """Get sortable attributes of the AsyncIndex.

        Args:
            sortable_attributes: List of attributes for searching.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_sortable_attributes(["title", "release_date"])
        """
        response = self._http_requests.put(
            f"{self._settings_url}/sortable-attributes", sortable_attributes, compress=compress
        )

        return TaskInfo(**response.json())

    def reset_sortable_attributes(self) -> TaskInfo:
        """Reset sortable attributes of the index to default values.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.reset_sortable_attributes()
        """
        response = self._http_requests.delete(f"{self._settings_url}/sortable-attributes")

        return TaskInfo(**response.json())

    def get_typo_tolerance(self) -> TypoTolerance:
        """Get typo tolerance for the index.

        Returns:
            TypoTolerance for the 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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> sortable_attributes = index.get_typo_tolerance()
        """
        response = self._http_requests.get(f"{self._settings_url}/typo-tolerance")

        return TypoTolerance(**response.json())

    def update_typo_tolerance(
        self, typo_tolerance: TypoTolerance, *, compress: bool = False
    ) -> TaskInfo:
        """Update typo tolerance.

        Args:
            typo_tolerance: Typo tolerance settings.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            Task to track the action.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> TypoTolerance(enabled=False)
            >>> index.update_typo_tolerance()
        """
        response = self._http_requests.patch(
            f"{self._settings_url}/typo-tolerance",
            typo_tolerance.model_dump(by_alias=True),
            compress=compress,
        )

        return TaskInfo(**response.json())

    def reset_typo_tolerance(self) -> TaskInfo:
        """Reset typo tolerance to default values.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.reset_typo_tolerance()
        """
        response = self._http_requests.delete(f"{self._settings_url}/typo-tolerance")

        return TaskInfo(**response.json())

    def get_faceting(self) -> Faceting:
        """Get faceting for the index.

        Returns:
            Faceting for the 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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> faceting = index.get_faceting()
        """
        response = self._http_requests.get(f"{self._settings_url}/faceting")

        return Faceting(**response.json())

    def update_faceting(self, faceting: Faceting, *, compress: bool = False) -> TaskInfo:
        """Partially update the faceting settings for an index.

        Args:
            faceting: Faceting values.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            Task to track the action.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_faceting(faceting=Faceting(max_values_per_facet=100))
        """
        response = self._http_requests.patch(
            f"{self._settings_url}/faceting",
            faceting.model_dump(by_alias=True),
            compress=compress,
        )

        return TaskInfo(**response.json())

    def reset_faceting(self) -> TaskInfo:
        """Reset an index's faceting settings to their default value.

        Returns:
            The details of the task status.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.reset_faceting()
        """
        response = self._http_requests.delete(f"{self._settings_url}/faceting")

        return TaskInfo(**response.json())

    def get_pagination(self) -> Pagination:
        """Get pagination settings for the index.

        Returns:
            Pagination for the index.

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

        Examples
            >>> from meilisearch_async_client import Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> pagination_settings = index.get_pagination()
        """
        response = self._http_requests.get(f"{self._settings_url}/pagination")

        return Pagination(**response.json())

    def update_pagination(self, settings: Pagination, *, compress: bool = False) -> TaskInfo:
        """Partially update the pagination settings for an index.

        Args:
            settings: settings for pagination.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            Task to track the action.

        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 Client
            >>> from meilisearch_python_sdk.models.settings import Pagination
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_pagination(settings=Pagination(max_total_hits=123))
        """
        response = self._http_requests.patch(
            f"{self._settings_url}/pagination",
            settings.model_dump(by_alias=True),
            compress=compress,
        )

        return TaskInfo(**response.json())

    def reset_pagination(self) -> TaskInfo:
        """Reset an index's pagination settings to their default value.

        Returns:
            The details of the task status.

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

        Examples
            >>> from meilisearch_async_client import Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.reset_pagination()
        """
        response = self._http_requests.delete(f"{self._settings_url}/pagination")

        return TaskInfo(**response.json())

    def get_separator_tokens(self) -> list[str]:
        """Get separator token settings for the index.

        Returns:
            Separator tokens for the index.

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

        Examples
            >>> from meilisearch_async_client import Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> separator_token_settings = index.get_separator_tokens()
        """
        response = self._http_requests.get(f"{self._settings_url}/separator-tokens")

        return response.json()

    def update_separator_tokens(
        self, separator_tokens: list[str], *, compress: bool = False
    ) -> TaskInfo:
        """Update the separator tokens settings for an index.

        Args:
            separator_tokens: List of separator tokens.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            Task to track the action.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_separator_tokens(separator_tokenes=["|", "/")
        """
        response = self._http_requests.put(
            f"{self._settings_url}/separator-tokens", separator_tokens, compress=compress
        )

        return TaskInfo(**response.json())

    def reset_separator_tokens(self) -> TaskInfo:
        """Reset an index's separator tokens settings to the default value.

        Returns:
            The details of the task status.

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

        Examples
            >>> from meilisearch_async_client import Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.reset_separator_tokens()
        """
        response = self._http_requests.delete(f"{self._settings_url}/separator-tokens")

        return TaskInfo(**response.json())

    def get_non_separator_tokens(self) -> list[str]:
        """Get non-separator token settings for the index.

        Returns:
            Non-separator tokens for the index.

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

        Examples
            >>> from meilisearch_async_client import Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> non_separator_token_settings = index.get_non_separator_tokens()
        """
        response = self._http_requests.get(f"{self._settings_url}/non-separator-tokens")

        return response.json()

    def update_non_separator_tokens(
        self, non_separator_tokens: list[str], *, compress: bool = False
    ) -> TaskInfo:
        """Update the non-separator tokens settings for an index.

        Args:
            non_separator_tokens: List of non-separator tokens.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            Task to track the action.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_non_separator_tokens(non_separator_tokens=["@", "#")
        """
        response = self._http_requests.put(
            f"{self._settings_url}/non-separator-tokens", non_separator_tokens, compress=compress
        )

        return TaskInfo(**response.json())

    def reset_non_separator_tokens(self) -> TaskInfo:
        """Reset an index's non-separator tokens settings to the default value.

        Returns:
            The details of the task status.

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

        Examples
            >>> from meilisearch_async_client import Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.reset_non_separator_tokens()
        """
        response = self._http_requests.delete(f"{self._settings_url}/non-separator-tokens")

        return TaskInfo(**response.json())

    def get_search_cutoff_ms(self) -> int | None:
        """Get search cutoff time in ms.

        Returns:
            Integer representing the search cutoff time in ms, or None.

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

        Examples
            >>> from meilisearch_async_client import Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> search_cutoff_ms_settings = index.get_search_cutoff_ms()
        """
        response = self._http_requests.get(f"{self._settings_url}/search-cutoff-ms")

        return response.json()

    def update_search_cutoff_ms(self, search_cutoff_ms: int, *, compress: bool = False) -> TaskInfo:
        """Update the search cutoff for an index.

        Args:
            search_cutoff_ms: Integer value of the search cutoff time in ms.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            Task to track the action.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_search_cutoff_ms(100)
        """
        response = self._http_requests.put(
            f"{self._settings_url}/search-cutoff-ms", search_cutoff_ms, compress=compress
        )

        return TaskInfo(**response.json())

    def reset_search_cutoff_ms(self) -> TaskInfo:
        """Reset the search cutoff time to the default value.

        Returns:
            The details of the task status.

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

        Examples
            >>> from meilisearch_async_client import Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.reset_search_cutoff_ms()
        """
        response = self._http_requests.delete(f"{self._settings_url}/search-cutoff-ms")

        return TaskInfo(**response.json())

    def get_word_dictionary(self) -> list[str]:
        """Get word dictionary settings for the index.

        Returns:
            Word dictionary for the index.

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

        Examples
            >>> from meilisearch_async_client import Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> word_dictionary = index.get_word_dictionary()
        """
        response = self._http_requests.get(f"{self._settings_url}/dictionary")

        return response.json()

    def update_word_dictionary(self, dictionary: list[str], *, compress: bool = False) -> TaskInfo:
        """Update the word dictionary settings for an index.

        Args:
            dictionary: List of dictionary values.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            Task to track the action.

        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 Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_word_dictionary(dictionary=["S.O.S", "S.O")
        """
        response = self._http_requests.put(
            f"{self._settings_url}/dictionary", dictionary, compress=compress
        )

        return TaskInfo(**response.json())

    def reset_word_dictionary(self) -> TaskInfo:
        """Reset an index's word dictionary settings to the default value.

        Returns:
            The details of the task status.

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

        Examples
            >>> from meilisearch_async_client import Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.reset_word_dictionary()
        """
        response = self._http_requests.delete(f"{self._settings_url}/dictionary")

        return TaskInfo(**response.json())

    def get_proximity_precision(self) -> ProximityPrecision:
        """Get proximity precision settings for the index.

        Returns:
            Proximity precision for the index.

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

        Examples
            >>> from meilisearch_async_client import Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> proximity_precision = index.get_proximity_precision()
        """
        response = self._http_requests.get(f"{self._settings_url}/proximity-precision")

        return ProximityPrecision[to_snake(response.json()).upper()]

    def update_proximity_precision(
        self, proximity_precision: ProximityPrecision, *, compress: bool = False
    ) -> TaskInfo:
        """Update the proximity precision settings for an index.

        Args:
            proximity_precision: The proximity precision value.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            Task to track the action.

        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 Client
            >>> from meilisearch_python_sdk.models.settings import ProximityPrecision
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_proximity_precision(ProximityPrecision.BY_ATTRIBUTE)
        """
        response = self._http_requests.put(
            f"{self._settings_url}/proximity-precision",
            proximity_precision.value,
            compress=compress,
        )

        return TaskInfo(**response.json())

    def reset_proximity_precision(self) -> TaskInfo:
        """Reset an index's proximity precision settings to the default value.

        Returns:
            The details of the task status.

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

        Examples
            >>> from meilisearch_async_client import Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.reset_proximity_precision()
        """
        response = self._http_requests.delete(f"{self._settings_url}/proximity-precision")

        return TaskInfo(**response.json())

    def get_embedders(self) -> Embedders | None:
        """Get embedder settings for the index.

        Returns:
            Embedders for the index.

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

        Examples
            >>> from meilisearch_async_client import Client
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> embedders = await index.get_embedders()
        """
        response = self._http_requests.get(f"{self._settings_url}/embedders")

        return _embedder_json_to_embedders_model(response.json())

    def update_embedders(self, embedders: Embedders, *, compress: bool = False) -> TaskInfo:
        """Update the embedders settings for an index.

        Args:
            embedders: The embedders value.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            Task to track the action.

        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 Client
            >>> from meilisearch_python_sdk.models.settings import Embedders, UserProvidedEmbedder
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_embedders(
            >>>     Embedders(embedders={dimensions=512)})
            >>> )
        """
        payload = {}
        for key, embedder in embedders.embedders.items():
            payload[key] = {
                k: v
                for k, v in embedder.model_dump(by_alias=True, exclude_none=True).items()
                if v is not None
            }

        response = self._http_requests.patch(
            f"{self._settings_url}/embedders", payload, compress=compress
        )

        return TaskInfo(**response.json())

    # TODO: Add back after embedder setting issue fixed https://github.com/meilisearch/meilisearch/issues/4585
    def reset_embedders(self) -> TaskInfo:  # pragma: no cover
        """Reset an index's embedders settings to the default value.

        Returns:
            The details of the task status.

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

        Examples
            >>> from meilisearch_async_client import Client
            >>> client = AsyncClient("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.reset_embedders()
        """
        response = self._http_requests.delete(f"{self._settings_url}/embedders")

        return TaskInfo(**response.json())

    def get_localized_attributes(self) -> list[LocalizedAttributes] | None:
        """Get localized attributes settings for the index.

        Returns:
            Localized attributes for the index.

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

        Examples
            >>> from meilisearch_async_client import AsyncClient
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> localized_attributes = await index.get_localized_attributes()
        """
        response = self._http_requests.get(f"{self._settings_url}/localized-attributes")

        if not response.json():
            return None

        return [LocalizedAttributes(**x) for x in response.json()]

    def update_localized_attributes(
        self, localized_attributes: list[LocalizedAttributes], *, compress: bool = False
    ) -> TaskInfo:
        """Update the localized attributes settings for an index.

        Args:
            localized_attributes: The localized attributes value.
            compress: If set to True the data will be sent in gzip format. Defaults to False.

        Returns:
            Task to track the action.

        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.settings import LocalizedAttributes
            >>>
            >>>
            >>> client = Client("http://localhost.com", "masterKey")
            >>> index = client.index("movies")
            >>> index.update_localized_attributes([
            >>>     LocalizedAttributes(locales=["eng", "spa"], attribute_patterns=["*"]),
            >>>     LocalizedAttributes(locales=["ita"], attribute_patterns=["*_it"]),
            >>> ])
        """
        payload = [x.model_dump(by_alias=True) for x in localized_attributes]
        response = self._http_requests.put(
            f"{self._settings_url}/localized-attributes", payload, compress=compress
        )

        return TaskInfo(**response.json())

    def reset_localized_attributes(self) -> TaskInfo:
        """Reset an index's localized attributes settings to the default value.

        Returns:
            The details of the task status.

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

        Examples
            >>> from meilisearch_async_client import AsyncClient
            >>> Client("http://localhost.com", "masterKey") as client:
            >>> index = client.index("movies")
            >>> index.reset_localized_attributes()
        """
        response = self._http_requests.delete(f"{self._settings_url}/localized-attributes")

        return TaskInfo(**response.json())

    @staticmethod
    def _run_plugins(
        plugins: Sequence[Plugin | DocumentPlugin | PostSearchPlugin],
        event: Event,
        **kwargs: Any,
    ) -> dict[str, Any]:
        results: dict[str, Any] = {
            "generic_result": None,
            "document_result": None,
            "search_result": None,
        }
        generic_tasks = []
        document_tasks = []
        search_tasks = []
        for plugin in plugins:
            if _plugin_has_method(plugin, "run_plugin"):
                generic_tasks.append(plugin.run_plugin(event=event, **kwargs))  # type: ignore[union-attr]
            if _plugin_has_method(plugin, "run_document_plugin"):
                document_tasks.append(
                    plugin.run_document_plugin(event=event, **kwargs)  # type: ignore[union-attr]
                )
            if _plugin_has_method(plugin, "run_post_search_plugin"):
                search_tasks.append(
                    plugin.run_post_search_plugin(event=event, **kwargs)  # type: ignore[union-attr]
                )

        if generic_tasks:
            for result in reversed(generic_tasks):
                if result:
                    results["generic_result"] = result
                    break

        if document_tasks:
            results["document_result"] = document_tasks[-1]

        if search_tasks:
            results["search_result"] = search_tasks[-1]

        return results

__init__(http_client, uid, primary_key=None, created_at=None, updated_at=None, plugins=None, json_handler=None, *, hits_type=JsonDict)

Class initializer.

Parameters:

Name Type Description Default
http_client Client

An instance of the Client. This automatically gets passed by the Client when creating and Index instance.

required
uid str

The index's unique identifier.

required
primary_key str | None

The primary key of the documents. Defaults to None.

None
created_at str | datetime | None

The date and time the index was created. Defaults to None.

None
updated_at str | datetime | None

The date and time the index was last updated. Defaults to None.

None
plugins IndexPlugins | None

Optional plugins can be provided to extend functionality.

None
json_handler BuiltinHandler | OrjsonHandler | UjsonHandler | None

The module to use for json operations. The options are BuiltinHandler (uses the json module from the standard library), OrjsonHandler (uses orjson), or UjsonHandler (uses ujson). Note that in order use orjson or ujson the corresponding extra needs to be included. Default: BuiltinHandler.

None
hits_type Any

Allows for a custom type to be passed to use for hits. Defaults to JsonDict

JsonDict
Source code in meilisearch_python_sdk/index.py
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
def __init__(
    self,
    http_client: Client,
    uid: str,
    primary_key: str | None = None,
    created_at: str | datetime | None = None,
    updated_at: str | datetime | None = None,
    plugins: IndexPlugins | None = None,
    json_handler: BuiltinHandler | OrjsonHandler | UjsonHandler | None = None,
    *,
    hits_type: Any = JsonDict,
):
    """Class initializer.

    Args:
        http_client: An instance of the Client. This automatically gets passed by the
            Client when creating and Index instance.
        uid: The index's unique identifier.
        primary_key: The primary key of the documents. Defaults to None.
        created_at: The date and time the index was created. Defaults to None.
        updated_at: The date and time the index was last updated. Defaults to None.
        plugins: Optional plugins can be provided to extend functionality.
        json_handler: The module to use for json operations. The options are BuiltinHandler
            (uses the json module from the standard library), OrjsonHandler (uses orjson), or
            UjsonHandler (uses ujson). Note that in order use orjson or ujson the corresponding
            extra needs to be included. Default: BuiltinHandler.
        hits_type: Allows for a custom type to be passed to use for hits. Defaults to
            JsonDict
    """
    super().__init__(
        uid=uid,
        primary_key=primary_key,
        created_at=created_at,
        updated_at=updated_at,
        json_handler=json_handler,
        hits_type=hits_type,
    )
    self.http_client = http_client
    self._http_requests = HttpRequests(http_client, json_handler=self._json_handler)
    self.plugins = plugins

add_documents(documents, primary_key=None, *, compress=False)

Add documents to the index.

Parameters:

Name Type Description Default
documents Sequence[JsonMapping]

List of documents.

required
primary_key str | None

The primary key of the documents. This will be ignored if already set. Defaults to None.

None
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

The details of the task.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> documents = [ >>> {"id": 1, "title": "Movie 1", "genre": "comedy"}, >>> {"id": 2, "title": "Movie 2", "genre": "drama"}, >>> ] >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.add_documents(documents)

Source code in meilisearch_python_sdk/index.py
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
def add_documents(
    self,
    documents: Sequence[JsonMapping],
    primary_key: str | None = None,
    *,
    compress: bool = False,
) -> TaskInfo:
    """Add documents to the index.

    Args:
        documents: List of documents.
        primary_key: The primary key of the documents. This will be ignored if already set.
            Defaults to None.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    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 Client
        >>> documents = [
        >>>     {"id": 1, "title": "Movie 1", "genre": "comedy"},
        >>>     {"id": 2, "title": "Movie 2", "genre": "drama"},
        >>> ]
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.add_documents(documents)
    """
    if primary_key:
        url = _build_encoded_url(self._documents_url, {"primaryKey": primary_key})
    else:
        url = self._documents_url

    if self._pre_add_documents_plugins:
        pre = Index._run_plugins(
            self._pre_add_documents_plugins,
            Event.PRE,
            documents=documents,
            primary_key=primary_key,
        )
        if pre.get("document_result"):
            documents = pre["document_result"]

    response = self._http_requests.post(url, documents, compress=compress)
    result = TaskInfo(**response.json())
    if self._post_add_documents_plugins:
        post = Index._run_plugins(self._post_add_documents_plugins, Event.POST, result=result)
        if isinstance(post.get("generic_result"), TaskInfo):
            result = post["generic_result"]

    return result

add_documents_from_directory(directory_path, *, primary_key=None, document_type='json', csv_delimiter=None, combine_documents=True, compress=False)

Load all json files from a directory and add the documents to the index.

Parameters:

Name Type Description Default
directory_path Path | str

Path to the directory that contains the json files.

required
primary_key str | None

The primary key of the documents. This will be ignored if already set. Defaults to None.

None
document_type str

The type of document being added. Accepted types are json, csv, and ndjson. For csv files the first row of the document should be a header row contining the field names, and ever for should have a title.

'json'
csv_delimiter str | None

A single ASCII character to specify the delimiter for csv files. This can only be used if the file is a csv file. Defaults to comma.

None
combine_documents bool

If set to True this will combine the documents from all the files before indexing them. Defaults to True.

True
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
list[TaskInfo]

The details of the task status.

Raises:

Type Description
InvalidDocumentError

If the docucment is not a valid format for Meilisearch.

MeilisearchError

If the file path is not valid

MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from pathlib import Path >>> from meilisearch_python_sdk import Client >>> directory_path = Path("/path/to/directory/containing/files") >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.add_documents_from_directory(directory_path)

Source code in meilisearch_python_sdk/index.py
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
def add_documents_from_directory(
    self,
    directory_path: Path | str,
    *,
    primary_key: str | None = None,
    document_type: str = "json",
    csv_delimiter: str | None = None,
    combine_documents: bool = True,
    compress: bool = False,
) -> list[TaskInfo]:
    """Load all json files from a directory and add the documents to the index.

    Args:
        directory_path: Path to the directory that contains the json files.
        primary_key: The primary key of the documents. This will be ignored if already set.
            Defaults to None.
        document_type: The type of document being added. Accepted types are json, csv, and
            ndjson. For csv files the first row of the document should be a header row contining
            the field names, and ever for should have a title.
        csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
            can only be used if the file is a csv file. Defaults to comma.
        combine_documents: If set to True this will combine the documents from all the files
            before indexing them. Defaults to True.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        The details of the task status.

    Raises:
        InvalidDocumentError: If the docucment is not a valid format for Meilisearch.
        MeilisearchError: If the file path is not valid
        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples
        >>> from pathlib import Path
        >>> from meilisearch_python_sdk import Client
        >>> directory_path = Path("/path/to/directory/containing/files")
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.add_documents_from_directory(directory_path)
    """
    directory = Path(directory_path) if isinstance(directory_path, str) else directory_path

    if combine_documents:
        all_documents = []
        for path in directory.iterdir():
            if path.suffix == f".{document_type}":
                documents = _load_documents_from_file(
                    path, csv_delimiter, json_handler=self._json_handler
                )
                all_documents.append(documents)

        _raise_on_no_documents(all_documents, document_type, directory_path)

        combined = _combine_documents(all_documents)

        response = self.add_documents(combined, primary_key, compress=compress)

        return [response]

    responses = []
    for path in directory.iterdir():
        if path.suffix == f".{document_type}":
            documents = _load_documents_from_file(
                path, csv_delimiter, json_handler=self._json_handler
            )
            responses.append(self.add_documents(documents, primary_key, compress=compress))

    _raise_on_no_documents(responses, document_type, directory_path)

    return responses

add_documents_from_directory_in_batches(directory_path, *, batch_size=1000, primary_key=None, document_type='json', csv_delimiter=None, combine_documents=True, compress=False)

Load all json files from a directory and add the documents to the index in batches.

Parameters:

Name Type Description Default
directory_path Path | str

Path to the directory that contains the json files.

required
batch_size int

The number of documents that should be included in each batch. Defaults to 1000.

1000
primary_key str | None

The primary key of the documents. This will be ignored if already set. Defaults to None.

None
document_type str

The type of document being added. Accepted types are json, csv, and ndjson. For csv files the first row of the document should be a header row contining the field names, and ever for should have a title.

'json'
csv_delimiter str | None

A single ASCII character to specify the delimiter for csv files. This can only be used if the file is a csv file. Defaults to comma.

None
combine_documents bool

If set to True this will combine the documents from all the files before indexing them. Defaults to True.

True
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
list[TaskInfo]

List of update ids to track the action.

Raises:

Type Description
InvalidDocumentError

If the docucment is not a valid format for Meilisearch.

MeilisearchError

If the file path is not valid

MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from pathlib import Path >>> from meilisearch_python_sdk import Client >>> directory_path = Path("/path/to/directory/containing/files") >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.add_documents_from_directory_in_batches(directory_path)

Source code in meilisearch_python_sdk/index.py
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
def add_documents_from_directory_in_batches(
    self,
    directory_path: Path | str,
    *,
    batch_size: int = 1000,
    primary_key: str | None = None,
    document_type: str = "json",
    csv_delimiter: str | None = None,
    combine_documents: bool = True,
    compress: bool = False,
) -> list[TaskInfo]:
    """Load all json files from a directory and add the documents to the index in batches.

    Args:
        directory_path: Path to the directory that contains the json files.
        batch_size: The number of documents that should be included in each batch.
            Defaults to 1000.
        primary_key: The primary key of the documents. This will be ignored if already set.
            Defaults to None.
        document_type: The type of document being added. Accepted types are json, csv, and
            ndjson. For csv files the first row of the document should be a header row contining
            the field names, and ever for should have a title.
        csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
            can only be used if the file is a csv file. Defaults to comma.
        combine_documents: If set to True this will combine the documents from all the files
            before indexing them. Defaults to True.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        List of update ids to track the action.

    Raises:
        InvalidDocumentError: If the docucment is not a valid format for Meilisearch.
        MeilisearchError: If the file path is not valid
        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples
        >>> from pathlib import Path
        >>> from meilisearch_python_sdk import Client
        >>> directory_path = Path("/path/to/directory/containing/files")
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.add_documents_from_directory_in_batches(directory_path)
    """
    directory = Path(directory_path) if isinstance(directory_path, str) else directory_path

    if combine_documents:
        all_documents = []
        for path in directory.iterdir():
            if path.suffix == f".{document_type}":
                documents = _load_documents_from_file(
                    path, csv_delimiter=csv_delimiter, json_handler=self._json_handler
                )
                all_documents.append(documents)

        _raise_on_no_documents(all_documents, document_type, directory_path)

        combined = _combine_documents(all_documents)

        return self.add_documents_in_batches(
            combined,
            batch_size=batch_size,
            primary_key=primary_key,
            compress=compress,
        )

    responses: list[TaskInfo] = []
    for path in directory.iterdir():
        if path.suffix == f".{document_type}":
            documents = _load_documents_from_file(
                path, csv_delimiter, json_handler=self._json_handler
            )
            responses.extend(
                self.add_documents_in_batches(
                    documents,
                    batch_size=batch_size,
                    primary_key=primary_key,
                    compress=compress,
                )
            )

    _raise_on_no_documents(responses, document_type, directory_path)

    return responses

add_documents_from_file(file_path, primary_key=None, *, compress=False)

Add documents to the index from a json file.

Parameters:

Name Type Description Default
file_path Path | str

Path to the json file.

required
primary_key str | None

The primary key of the documents. This will be ignored if already set. Defaults to None.

None
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
InvalidDocumentError

If the docucment is not a valid format for Meilisearch.

MeilisearchError

If the file path is not valid

MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from pathlib import Path >>> from meilisearch_python_sdk import Client >>> file_path = Path("/path/to/file.json") >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.add_documents_from_file(file_path)

Source code in meilisearch_python_sdk/index.py
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
def add_documents_from_file(
    self,
    file_path: Path | str,
    primary_key: str | None = None,
    *,
    compress: bool = False,
) -> TaskInfo:
    """Add documents to the index from a json file.

    Args:
        file_path: Path to the json file.
        primary_key: The primary key of the documents. This will be ignored if already set.
            Defaults to None.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        The details of the task status.

    Raises:
        InvalidDocumentError: If the docucment is not a valid format for Meilisearch.
        MeilisearchError: If the file path is not valid
        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples
        >>> from pathlib import Path
        >>> from meilisearch_python_sdk import Client
        >>> file_path = Path("/path/to/file.json")
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.add_documents_from_file(file_path)
    """
    documents = _load_documents_from_file(file_path, json_handler=self._json_handler)

    return self.add_documents(documents, primary_key=primary_key, compress=compress)

add_documents_from_file_in_batches(file_path, *, batch_size=1000, primary_key=None, csv_delimiter=None, compress=False)

Adds documents form a json file in batches to reduce RAM usage with indexing.

Parameters:

Name Type Description Default
file_path Path | str

Path to the json file.

required
batch_size int

The number of documents that should be included in each batch. Defaults to 1000.

1000
primary_key str | None

The primary key of the documents. This will be ignored if already set. Defaults to None.

None
csv_delimiter str | None

A single ASCII character to specify the delimiter for csv files. This can only be used if the file is a csv file. Defaults to comma.

None
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
list[TaskInfo]

List of update ids to track the action.

Raises:

Type Description
InvalidDocumentError

If the docucment is not a valid format for Meilisearch.

MeilisearchError

If the file path is not valid

MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from pathlib import Path >>> from meilisearch_python_sdk import Client >>> file_path = Path("/path/to/file.json") >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.add_documents_from_file_in_batches(file_path)

Source code in meilisearch_python_sdk/index.py
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
def add_documents_from_file_in_batches(
    self,
    file_path: Path | str,
    *,
    batch_size: int = 1000,
    primary_key: str | None = None,
    csv_delimiter: str | None = None,
    compress: bool = False,
) -> list[TaskInfo]:
    """Adds documents form a json file in batches to reduce RAM usage with indexing.

    Args:
        file_path: Path to the json file.
        batch_size: The number of documents that should be included in each batch.
            Defaults to 1000.
        primary_key: The primary key of the documents. This will be ignored if already set.
            Defaults to None.
        csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
            can only be used if the file is a csv file. Defaults to comma.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        List of update ids to track the action.

    Raises:
        InvalidDocumentError: If the docucment is not a valid format for Meilisearch.
        MeilisearchError: If the file path is not valid
        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples
        >>> from pathlib import Path
        >>> from meilisearch_python_sdk import Client
        >>> file_path = Path("/path/to/file.json")
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.add_documents_from_file_in_batches(file_path)
    """
    documents = _load_documents_from_file(
        file_path, csv_delimiter, json_handler=self._json_handler
    )

    return self.add_documents_in_batches(
        documents,
        batch_size=batch_size,
        primary_key=primary_key,
        compress=compress,
    )

add_documents_from_raw_file(file_path, primary_key=None, *, csv_delimiter=None, compress=False)

Directly send csv or ndjson files to Meilisearch without pre-processing.

The can reduce RAM usage from Meilisearch during indexing, but does not include the option for batching.

Parameters:

Name Type Description Default
file_path Path | str

The path to the file to send to Meilisearch. Only csv and ndjson files are allowed.

required
primary_key str | None

The primary key of the documents. This will be ignored if already set. Defaults to None.

None
csv_delimiter str | None

A single ASCII character to specify the delimiter for csv files. This can only be used if the file is a csv file. Defaults to comma.

None
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

The details of the task.

Raises:

Type Description
ValueError

If the file is not a csv or ndjson file, or if a csv_delimiter is sent for a non-csv file.

MeilisearchError

If the file path is not valid

MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from pathlib import Path >>> from meilisearch_python_sdk import Client >>> file_path = Path("/path/to/file.csv") >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.add_documents_from_raw_file(file_path)

Source code in meilisearch_python_sdk/index.py
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
def add_documents_from_raw_file(
    self,
    file_path: Path | str,
    primary_key: str | None = None,
    *,
    csv_delimiter: str | None = None,
    compress: bool = False,
) -> TaskInfo:
    """Directly send csv or ndjson files to Meilisearch without pre-processing.

    The can reduce RAM usage from Meilisearch during indexing, but does not include the option
    for batching.

    Args:
        file_path: The path to the file to send to Meilisearch. Only csv and ndjson files are
            allowed.
        primary_key: The primary key of the documents. This will be ignored if already set.
            Defaults to None.
        csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
            can only be used if the file is a csv file. Defaults to comma.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        The details of the task.

    Raises:
        ValueError: If the file is not a csv or ndjson file, or if a csv_delimiter is sent for
            a non-csv file.
        MeilisearchError: If the file path is not valid
        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples
        >>> from pathlib import Path
        >>> from meilisearch_python_sdk import Client
        >>> file_path = Path("/path/to/file.csv")
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.add_documents_from_raw_file(file_path)
    """
    upload_path = Path(file_path) if isinstance(file_path, str) else file_path
    if not upload_path.exists():
        raise MeilisearchError("No file found at the specified path")

    if upload_path.suffix not in (".csv", ".ndjson"):
        raise ValueError("Only csv and ndjson files can be sent as binary files")

    if csv_delimiter and upload_path.suffix != ".csv":
        raise ValueError("A csv_delimiter can only be used with csv files")

    if (
        csv_delimiter
        and len(csv_delimiter) != 1
        or csv_delimiter
        and not csv_delimiter.isascii()
    ):
        raise ValueError("csv_delimiter must be a single ascii character")

    content_type = "text/csv" if upload_path.suffix == ".csv" else "application/x-ndjson"
    parameters = {}

    if primary_key:
        parameters["primaryKey"] = primary_key
    if csv_delimiter:
        parameters["csvDelimiter"] = csv_delimiter

    if parameters:
        url = _build_encoded_url(self._documents_url, parameters)
    else:
        url = self._documents_url

    with open(upload_path) as f:
        data = f.read()

    response = self._http_requests.post(
        url, body=data, content_type=content_type, compress=compress
    )

    return TaskInfo(**response.json())

add_documents_in_batches(documents, *, batch_size=1000, primary_key=None, compress=False)

Adds documents in batches to reduce RAM usage with indexing.

Parameters:

Name Type Description Default
documents Sequence[JsonMapping]

List of documents.

required
batch_size int

The number of documents that should be included in each batch. Defaults to 1000.

1000
primary_key str | None

The primary key of the documents. This will be ignored if already set. Defaults to None.

None
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
list[TaskInfo]

List of update ids to track the action.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> >>> documents = [ >>> {"id": 1, "title": "Movie 1", "genre": "comedy"}, >>> {"id": 2, "title": "Movie 2", "genre": "drama"}, >>> ] >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.add_documents_in_batches(documents)

Source code in meilisearch_python_sdk/index.py
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
def add_documents_in_batches(
    self,
    documents: Sequence[JsonMapping],
    *,
    batch_size: int = 1000,
    primary_key: str | None = None,
    compress: bool = False,
) -> list[TaskInfo]:
    """Adds documents in batches to reduce RAM usage with indexing.

    Args:
        documents: List of documents.
        batch_size: The number of documents that should be included in each batch.
            Defaults to 1000.
        primary_key: The primary key of the documents. This will be ignored if already set.
            Defaults to None.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        List of update ids to track the action.

    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 Client
        >>> >>> documents = [
        >>>     {"id": 1, "title": "Movie 1", "genre": "comedy"},
        >>>     {"id": 2, "title": "Movie 2", "genre": "drama"},
        >>> ]
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.add_documents_in_batches(documents)
    """
    return [
        self.add_documents(x, primary_key, compress=compress)
        for x in _batch(documents, batch_size)
    ]

create(http_client, uid, primary_key=None, *, settings=None, wait=True, timeout_in_ms=None, plugins=None, json_handler=None, hits_type=JsonDict) classmethod

Creates a new index.

In general this method should not be used directly and instead the index should be created through the Client.

Parameters:

Name Type Description Default
http_client Client

An instance of the Client. This automatically gets passed by the Client when creating an Index instance.

required
uid str

The index's unique identifier.

required
primary_key str | None

The primary key of the documents. Defaults to None.

None
settings MeilisearchSettings | None

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).

None
wait bool

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

True
timeout_in_ms int | None

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.

None
plugins IndexPlugins | None

Optional plugins can be provided to extend functionality.

None
json_handler BuiltinHandler | OrjsonHandler | UjsonHandler | None

The module to use for json operations. The options are BuiltinHandler (uses the json module from the standard library), OrjsonHandler (uses orjson), or UjsonHandler (uses ujson). Note that in order use orjson or ujson the corresponding extra needs to be included. Default: BuiltinHandler.

None
hits_type Any

Allows for a custom type to be passed to use for hits. Defaults to JsonDict

JsonDict

Returns:

Type Description
Self

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

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = index.create(client, "movies")

Source code in meilisearch_python_sdk/index.py
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
@classmethod
def create(
    cls,
    http_client: Client,
    uid: str,
    primary_key: str | None = None,
    *,
    settings: MeilisearchSettings | None = None,
    wait: bool = True,
    timeout_in_ms: int | None = None,
    plugins: IndexPlugins | None = None,
    json_handler: BuiltinHandler | OrjsonHandler | UjsonHandler | None = None,
    hits_type: Any = JsonDict,
) -> Self:
    """Creates a new index.

    In general this method should not be used directly and instead the index should be created
    through the `Client`.

    Args:
        http_client: An instance of the Client. This automatically gets passed by the Client
            when creating an Index instance.
        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.
        json_handler: The module to use for json operations. The options are BuiltinHandler
            (uses the json module from the standard library), OrjsonHandler (uses orjson), or
            UjsonHandler (uses ujson). Note that in order use orjson or ujson the corresponding
            extra needs to be included. Default: BuiltinHandler.
        hits_type: Allows for a custom type to be passed to use for hits. Defaults to
            JsonDict

    Returns:
        An instance of Index 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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = index.create(client, "movies")
    """
    if not primary_key:
        payload = {"uid": uid}
    else:
        payload = {"primaryKey": primary_key, "uid": uid}

    url = "indexes"
    handler = json_handler if json_handler else BuiltinHandler()
    http_request = HttpRequests(http_client, handler)
    response = http_request.post(url, payload)
    wait_for_task(http_client, response.json()["taskUid"], timeout_in_ms=timeout_in_ms)
    index_response = http_request.get(f"{url}/{uid}")
    index_dict = index_response.json()
    index = cls(
        http_client=http_client,
        uid=index_dict["uid"],
        primary_key=index_dict["primaryKey"],
        created_at=index_dict["createdAt"],
        updated_at=index_dict["updatedAt"],
        plugins=plugins,
        json_handler=json_handler,
        hits_type=hits_type,
    )

    if settings:
        settings_task = index.update_settings(settings)
        if wait:
            wait_for_task(http_client, settings_task.task_uid, timeout_in_ms=timeout_in_ms)

    return index

delete()

Deletes the index.

Returns:

Type Description
TaskInfo

The details of the task.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.delete()

Source code in meilisearch_python_sdk/index.py
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
def delete(self) -> TaskInfo:
    """Deletes the index.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.delete()
    """
    response = self._http_requests.delete(self._base_url_with_uid)
    return TaskInfo(**response.json())

delete_all_documents()

Delete all documents from the index.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.delete_all_document()

Source code in meilisearch_python_sdk/index.py
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
def delete_all_documents(self) -> TaskInfo:
    """Delete all documents from the index.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.delete_all_document()
    """
    if self._pre_delete_all_documents_plugins:
        Index._run_plugins(self._pre_delete_all_documents_plugins, Event.PRE)

    response = self._http_requests.delete(self._documents_url)
    result = TaskInfo(**response.json())
    if self._post_delete_all_documents_plugins:
        post = Index._run_plugins(
            self._post_delete_all_documents_plugins, Event.POST, result=result
        )
        if isinstance(post.get("generic_result"), TaskInfo):
            result = post["generic_result"]

    return result

delete_document(document_id)

Delete one document from the index.

Parameters:

Name Type Description Default
document_id str

Unique identifier of the document.

required

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.delete_document("1234")

Source code in meilisearch_python_sdk/index.py
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
def delete_document(self, document_id: str) -> TaskInfo:
    """Delete one document from the index.

    Args:
        document_id: Unique identifier of the document.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.delete_document("1234")
    """
    if self._pre_delete_document_plugins:
        Index._run_plugins(
            self._pre_delete_document_plugins, Event.PRE, document_id=document_id
        )

    response = self._http_requests.delete(f"{self._documents_url}/{document_id}")
    result = TaskInfo(**response.json())
    if self._post_delete_document_plugins:
        post = Index._run_plugins(self._post_delete_document_plugins, Event.POST, result=result)
        if isinstance(post.get("generic_result"), TaskInfo):
            result = post["generic_result"]

    return result

delete_documents(ids)

Delete multiple documents from the index.

Parameters:

Name Type Description Default
ids list[str]

List of unique identifiers of documents.

required

Returns:

Type Description
TaskInfo

List of update ids to track the action.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.delete_documents(["1234", "5678"])

Source code in meilisearch_python_sdk/index.py
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
def delete_documents(self, ids: list[str]) -> TaskInfo:
    """Delete multiple documents from the index.

    Args:
        ids: List of unique identifiers of documents.

    Returns:
        List of update ids to track the action.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.delete_documents(["1234", "5678"])
    """
    if self._pre_delete_documents_plugins:
        Index._run_plugins(self._pre_delete_documents_plugins, Event.PRE, ids=ids)

    response = self._http_requests.post(f"{self._documents_url}/delete-batch", ids)
    result = TaskInfo(**response.json())
    if self._post_delete_documents_plugins:
        post = Index._run_plugins(
            self._post_delete_documents_plugins, Event.POST, result=result
        )
        if isinstance(post.get("generic_result"), TaskInfo):
            result = post["generic_result"]

    return result

delete_documents_by_filter(filter)

Delete documents from the index by filter.

Parameters:

Name Type Description Default
filter Filter

The filter value information.

required

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.delete_documents_by_filter("genre=horor"))

Source code in meilisearch_python_sdk/index.py
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
def delete_documents_by_filter(self, filter: Filter) -> TaskInfo:
    """Delete documents from the index by filter.

    Args:
        filter: The filter value information.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.delete_documents_by_filter("genre=horor"))
    """
    if self._pre_delete_documents_by_filter_plugins:
        Index._run_plugins(
            self._pre_delete_documents_by_filter_plugins, Event.PRE, filter=filter
        )

    response = self._http_requests.post(
        f"{self._documents_url}/delete", body={"filter": filter}
    )
    result = TaskInfo(**response.json())
    if self._post_delete_documents_by_filter_plugins:
        post = Index._run_plugins(
            self._post_delete_documents_by_filter_plugins, Event.POST, result=result
        )
        if isinstance(post.get("generic_result"), TaskInfo):
            result = post["generic_result"]

    return result

delete_documents_in_batches_by_filter(filters)

Delete batches of documents from the index by filter.

Parameters:

Name Type Description Default
filters list[str | list[str | list[str]]]

A list of filter value information.

required

Returns:

Type Description
list[TaskInfo]

The a list of details of the task statuses.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.delete_documents_in_batches_by_filter( >>> [ >>> "genre=horor"), >>> "release_date=1520035200"), >>> ] >>> )

Source code in meilisearch_python_sdk/index.py
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
def delete_documents_in_batches_by_filter(
    self, filters: list[str | list[str | list[str]]]
) -> list[TaskInfo]:
    """Delete batches of documents from the index by filter.

    Args:
        filters: A list of filter value information.

    Returns:
        The a list of details of the task statuses.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.delete_documents_in_batches_by_filter(
        >>>     [
        >>>         "genre=horor"),
        >>>         "release_date=1520035200"),
        >>>     ]
        >>> )
    """
    return [self.delete_documents_by_filter(filter) for filter in filters]

delete_if_exists()

Delete the index if it already exists.

Returns:

Type Description
bool

True if the index was deleted or False if not.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.delete_if_exists()

Source code in meilisearch_python_sdk/index.py
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
def delete_if_exists(self) -> bool:
    """Delete the index if it already exists.

    Returns:
        True if the index was deleted or 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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.delete_if_exists()
    """
    response = self.delete()
    status = wait_for_task(self.http_client, response.task_uid, timeout_in_ms=100000)
    if status.status == "succeeded":
        return True

    return False

edit_documents(function, *, context=None, filter=None)

Edit documents with a function.

Edit documents is only available in Meilisearch >= v1.10.0, and is experimental in Meilisearch v1.10.0. In order to use this feature you first need to enable it by sending a PATCH request to /experimental-features with { "editDocumentsByFunction": true }.

Parameters:

Name Type Description Default
function str

Rhai function to use to update the documents.

required
context JsonDict | None

Parameters to use in the function. Defaults to None.

None
filter str | None

Filter the documents before applying the function. Defaults to None.

None

Returns:

Type Description
TaskInfo

The details of the task.

Raises:

Type Description
MeilisearchError

If the file path is not valid

MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.edit_documents("doc.title = ${doc.title.to_upper()}")

Source code in meilisearch_python_sdk/index.py
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
def edit_documents(
    self, function: str, *, context: JsonDict | None = None, filter: str | None = None
) -> TaskInfo:
    """Edit documents with a function.

    Edit documents is only available in Meilisearch >= v1.10.0, and is experimental in
    Meilisearch v1.10.0. In order to use this feature you first need to enable it by
    sending a PATCH request to /experimental-features with { "editDocumentsByFunction": true }.

    Args:
        function: Rhai function to use to update the documents.
        context: Parameters to use in the function. Defaults to None.
        filter: Filter the documents before applying the function. Defaults to None.

    Returns:
        The details of the task.

    Raises:
        MeilisearchError: If the file path is not valid
        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples
        >>> from meilisearch_python_sdk import Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.edit_documents("doc.title = `${doc.title.to_upper()}`")
    """
    url = f"{self._documents_url}/edit"
    payload: JsonDict = {"function": function}

    if context:
        payload["context"] = context

    if filter:
        payload["filter"] = filter

    response = self._http_requests.post(url, payload)

    return TaskInfo(**response.json())

Search the index.

Parameters:

Name Type Description Default
query str | None

String containing the word(s) to search

None
facet_name str

The name of the facet to search

required
facet_query str

The facet search value

required
offset int

Number of documents to skip. Defaults to 0.

0
limit int

Maximum number of documents returned. Defaults to 20.

20
filter Filter | None

Filter queries by an attribute value. Defaults to None.

None
facets list[str] | None

Facets for which to retrieve the matching count. Defaults to None.

None
attributes_to_retrieve list[str] | None

Attributes to display in the returned documents. Defaults to ["*"].

None
attributes_to_crop list[str] | None

Attributes whose values have to be cropped. Defaults to None.

None
crop_length int

The maximun number of words to display. Defaults to 200.

200
attributes_to_highlight list[str] | None

Attributes whose values will contain highlighted matching terms. Defaults to None.

None
sort list[str] | None

Attributes by which to sort the results. Defaults to None.

None
show_matches_position bool

Defines whether an object that contains information about the matches should be returned or not. Defaults to False.

False
highlight_pre_tag str

The opening tag for highlighting text. Defaults to .

'<em>'
highlight_post_tag str

The closing tag for highlighting text. Defaults to

'</em>'
crop_marker str

Marker to display when the number of words excedes the crop_length. Defaults to ...

'...'
matching_strategy Literal['all', 'last', 'frequency']

Specifies the matching strategy Meilisearch should use. Defaults to last.

'last'
hits_per_page int | None

Sets the number of results returned per page.

None
page int | None

Sets the specific results page to fetch.

None
attributes_to_search_on list[str] | None

List of field names. Allow search over a subset of searchable attributes without modifying the index settings. Defaults to None.

None
show_ranking_score bool

If set to True the ranking score will be returned with each document in the search. Defaults to False.

False
show_ranking_score_details bool

If set to True the ranking details will be returned with each document in the search. Defaults to False. Note: This parameter can only be used with Meilisearch >= v1.3.0, and is experimental in Meilisearch v1.3.0. In order to use this feature in Meilisearch v1.3.0 you first need to enable the feature by sending a PATCH request to /experimental-features with { "scoreDetails": true }. Because this feature is experimental it may be removed or updated causing breaking changes in this library without a major version bump so use with caution. This feature became stable in Meiliseach v1.7.0.

False
ranking_score_threshold float | None

If set, no document whose _rankingScore is under the rankingScoreThreshold is returned. The value must be between 0.0 and 1.0. Defaults to None.

None
vector list[float] | None

List of vectors for vector search. Defaults to None. Note: This parameter can only be used with Meilisearch >= v1.3.0, and is experimental in Meilisearch v1.3.0. In order to use this feature in Meilisearch v1.3.0 you first need to enable the feature by sending a PATCH request to /experimental-features with { "vectorStore": true }. Because this feature is experimental it may be removed or updated causing breaking changes in this library without a major version bump so use with caution.

None
locales list[str] | None

Specifies the languages for the search. This parameter can only be used with Milisearch >= v1.10.0. Defaults to None letting the Meilisearch pick.

None

Returns:

Type Description
FacetSearchResults

Results of the search

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> search_results = index.search( >>> "Tron", >>> facet_name="genre", >>> facet_query="Sci-fi" >>> )

Source code in meilisearch_python_sdk/index.py
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
def facet_search(
    self,
    query: str | None = None,
    *,
    facet_name: str,
    facet_query: str,
    offset: int = 0,
    limit: int = 20,
    filter: Filter | None = None,
    facets: list[str] | None = None,
    attributes_to_retrieve: list[str] | None = None,
    attributes_to_crop: list[str] | None = None,
    crop_length: int = 200,
    attributes_to_highlight: list[str] | None = None,
    sort: list[str] | None = None,
    show_matches_position: bool = False,
    highlight_pre_tag: str = "<em>",
    highlight_post_tag: str = "</em>",
    crop_marker: str = "...",
    matching_strategy: Literal["all", "last", "frequency"] = "last",
    hits_per_page: int | None = None,
    page: int | None = None,
    attributes_to_search_on: list[str] | None = None,
    show_ranking_score: bool = False,
    show_ranking_score_details: bool = False,
    ranking_score_threshold: float | None = None,
    vector: list[float] | None = None,
    locales: list[str] | None = None,
) -> FacetSearchResults:
    """Search the index.

    Args:
        query: String containing the word(s) to search
        facet_name: The name of the facet to search
        facet_query: The facet search value
        offset: Number of documents to skip. Defaults to 0.
        limit: Maximum number of documents returned. Defaults to 20.
        filter: Filter queries by an attribute value. Defaults to None.
        facets: Facets for which to retrieve the matching count. Defaults to None.
        attributes_to_retrieve: Attributes to display in the returned documents.
            Defaults to ["*"].
        attributes_to_crop: Attributes whose values have to be cropped. Defaults to None.
        crop_length: The maximun number of words to display. Defaults to 200.
        attributes_to_highlight: Attributes whose values will contain highlighted matching terms.
            Defaults to None.
        sort: Attributes by which to sort the results. Defaults to None.
        show_matches_position: Defines whether an object that contains information about the
            matches should be returned or not. Defaults to False.
        highlight_pre_tag: The opening tag for highlighting text. Defaults to <em>.
        highlight_post_tag: The closing tag for highlighting text. Defaults to </em>
        crop_marker: Marker to display when the number of words excedes the `crop_length`.
            Defaults to ...
        matching_strategy: Specifies the matching strategy Meilisearch should use. Defaults to
            `last`.
        hits_per_page: Sets the number of results returned per page.
        page: Sets the specific results page to fetch.
        attributes_to_search_on: List of field names. Allow search over a subset of searchable
            attributes without modifying the index settings. Defaults to None.
        show_ranking_score: If set to True the ranking score will be returned with each document
            in the search. Defaults to False.
        show_ranking_score_details: If set to True the ranking details will be returned with
            each document in the search. Defaults to False. Note: This parameter can only be
            used with Meilisearch >= v1.3.0, and is experimental in Meilisearch v1.3.0. In order
            to use this feature in Meilisearch v1.3.0 you first need to enable the feature by
            sending a PATCH request to /experimental-features with { "scoreDetails": true }.
            Because this feature is experimental it may be removed or updated causing breaking
            changes in this library without a major version bump so use with caution. This
            feature became stable in Meiliseach v1.7.0.
        ranking_score_threshold: If set, no document whose _rankingScore is under the
            rankingScoreThreshold is returned. The value must be between 0.0 and 1.0. Defaults
            to None.
        vector: List of vectors for vector search. Defaults to None. Note: This parameter can
            only be used with Meilisearch >= v1.3.0, and is experimental in Meilisearch v1.3.0.
            In order to use this feature in Meilisearch v1.3.0 you first need to enable the
            feature by sending a PATCH request to /experimental-features with
            { "vectorStore": true }. Because this feature is experimental it may be removed or
            updated causing breaking changes in this library without a major version bump so use
            with caution.
        locales: Specifies the languages for the search. This parameter can only be used with
            Milisearch >= v1.10.0. Defaults to None letting the Meilisearch pick.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> search_results = index.search(
        >>>     "Tron",
        >>>     facet_name="genre",
        >>>     facet_query="Sci-fi"
        >>> )
    """
    if ranking_score_threshold:
        _validate_ranking_score_threshold(ranking_score_threshold)

    body = _process_search_parameters(
        q=query,
        facet_name=facet_name,
        facet_query=facet_query,
        offset=offset,
        limit=limit,
        filter=filter,
        facets=facets,
        attributes_to_retrieve=attributes_to_retrieve,
        attributes_to_crop=attributes_to_crop,
        crop_length=crop_length,
        attributes_to_highlight=attributes_to_highlight,
        sort=sort,
        show_matches_position=show_matches_position,
        highlight_pre_tag=highlight_pre_tag,
        highlight_post_tag=highlight_post_tag,
        crop_marker=crop_marker,
        matching_strategy=matching_strategy,
        hits_per_page=hits_per_page,
        page=page,
        attributes_to_search_on=attributes_to_search_on,
        show_ranking_score=show_ranking_score,
        show_ranking_score_details=show_ranking_score_details,
        ranking_score_threshold=ranking_score_threshold,
        vector=vector,
        locales=locales,
    )

    if self._pre_facet_search_plugins:
        Index._run_plugins(
            self._pre_facet_search_plugins,
            Event.PRE,
            query=query,
            offset=offset,
            limit=limit,
            filter=filter,
            facets=facets,
            attributes_to_retrieve=attributes_to_retrieve,
            attributes_to_crop=attributes_to_crop,
            crop_length=crop_length,
            attributes_to_highlight=attributes_to_highlight,
            sort=sort,
            show_matches_position=show_matches_position,
            highlight_pre_tag=highlight_pre_tag,
            highlight_post_tag=highlight_post_tag,
            crop_marker=crop_marker,
            matching_strategy=matching_strategy,
            hits_per_page=hits_per_page,
            page=page,
            attributes_to_search_on=attributes_to_search_on,
            show_ranking_score=show_ranking_score,
            show_ranking_score_details=show_ranking_score_details,
            ranking_score_threshold=ranking_score_threshold,
            vector=vector,
        )

    response = self._http_requests.post(f"{self._base_url_with_uid}/facet-search", body=body)
    result = FacetSearchResults(**response.json())
    if self._post_facet_search_plugins:
        post = Index._run_plugins(self._post_facet_search_plugins, Event.POST, result=result)
        if isinstance(post["generic_result"], FacetSearchResults):
            result = post["generic_result"]

    return result

fetch_info()

Gets the infromation about the index.

Returns:

Type Description
Self

An instance of the AsyncIndex containing the retrieved information.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index_info = index.fetch_info()

Source code in meilisearch_python_sdk/index.py
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
def fetch_info(self) -> Self:
    """Gets the infromation about the index.

    Returns:
        An instance of the AsyncIndex containing the retrieved information.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index_info = index.fetch_info()
    """
    response = self._http_requests.get(self._base_url_with_uid)
    index_dict = response.json()
    self._set_fetch_info(
        index_dict["primaryKey"], index_dict["createdAt"], index_dict["updatedAt"]
    )
    return self

get_displayed_attributes()

Get displayed attributes of the index.

Returns:

Type Description
list[str]

List containing the displayed attributes of the index.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> displayed_attributes = index.get_displayed_attributes()

Source code in meilisearch_python_sdk/index.py
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
def get_displayed_attributes(self) -> list[str]:
    """Get displayed attributes of the index.

    Returns:
        List containing the displayed attributes of the 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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> displayed_attributes = index.get_displayed_attributes()
    """
    response = self._http_requests.get(f"{self._settings_url}/displayed-attributes")

    return response.json()

get_distinct_attribute()

Get distinct attribute of the index.

Returns:

Type Description
str | None

String containing the distinct attribute of the index. If no distinct attribute None is returned.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> distinct_attribute = index.get_distinct_attribute()

Source code in meilisearch_python_sdk/index.py
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
def get_distinct_attribute(self) -> str | None:
    """Get distinct attribute of the index.

    Returns:
        String containing the distinct attribute of the index. If no distinct attribute
            `None` is returned.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> distinct_attribute = index.get_distinct_attribute()
    """
    response = self._http_requests.get(f"{self._settings_url}/distinct-attribute")

    if not response.json():
        return None

    return response.json()

get_document(document_id)

Get one document with given document identifier.

Parameters:

Name Type Description Default
document_id str

Unique identifier of the document.

required

Returns:

Type Description
JsonDict

The document information

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> document = index.get_document("1234")

Source code in meilisearch_python_sdk/index.py
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
def get_document(self, document_id: str) -> JsonDict:
    """Get one document with given document identifier.

    Args:
        document_id: Unique identifier of the document.

    Returns:
        The document information

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> document = index.get_document("1234")
    """
    response = self._http_requests.get(f"{self._documents_url}/{document_id}")

    return response.json()

get_documents(*, offset=0, limit=20, fields=None, filter=None)

Get a batch documents from the index.

Parameters:

Name Type Description Default
offset int

Number of documents to skip. Defaults to 0.

0
limit int

Maximum number of documents returnedd. Defaults to 20.

20
fields list[str] | None

Document attributes to show. If this value is None then all attributes are retrieved. Defaults to None.

None
filter Filter | None

Filter value information. Defaults to None. Note: This parameter can only be used with Meilisearch >= v1.2.0

None

Returns:

Type Description
DocumentsInfo

Documents info.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> documents = index.get_documents()

Source code in meilisearch_python_sdk/index.py
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
def get_documents(
    self,
    *,
    offset: int = 0,
    limit: int = 20,
    fields: list[str] | None = None,
    filter: Filter | None = None,
) -> DocumentsInfo:
    """Get a batch documents from the index.

    Args:
        offset: Number of documents to skip. Defaults to 0.
        limit: Maximum number of documents returnedd. Defaults to 20.
        fields: Document attributes to show. If this value is None then all
            attributes are retrieved. Defaults to None.
        filter: Filter value information. Defaults to None. Note: This parameter can only be
            used with Meilisearch >= v1.2.0

    Returns:
        Documents info.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> documents = index.get_documents()
    """
    parameters: JsonDict = {
        "offset": offset,
        "limit": limit,
    }

    if not filter:
        if fields:
            parameters["fields"] = ",".join(fields)

        url = _build_encoded_url(self._documents_url, parameters)
        response = self._http_requests.get(url)

        return DocumentsInfo(**response.json())

    if fields:
        parameters["fields"] = fields

    parameters["filter"] = filter
    response = self._http_requests.post(f"{self._documents_url}/fetch", body=parameters)

    return DocumentsInfo(**response.json())

get_embedders()

Get embedder settings for the index.

Returns:

Type Description
Embedders | None

Embedders for the index.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_async_client import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> embedders = await index.get_embedders()

Source code in meilisearch_python_sdk/index.py
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
def get_embedders(self) -> Embedders | None:
    """Get embedder settings for the index.

    Returns:
        Embedders for the index.

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

    Examples
        >>> from meilisearch_async_client import Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> embedders = await index.get_embedders()
    """
    response = self._http_requests.get(f"{self._settings_url}/embedders")

    return _embedder_json_to_embedders_model(response.json())

get_faceting()

Get faceting for the index.

Returns:

Type Description
Faceting

Faceting for the index.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> faceting = index.get_faceting()

Source code in meilisearch_python_sdk/index.py
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
def get_faceting(self) -> Faceting:
    """Get faceting for the index.

    Returns:
        Faceting for the 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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> faceting = index.get_faceting()
    """
    response = self._http_requests.get(f"{self._settings_url}/faceting")

    return Faceting(**response.json())

get_filterable_attributes()

Get filterable attributes of the index.

Returns:

Type Description
list[str] | None

List containing the filterable attributes of the index.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> filterable_attributes = index.get_filterable_attributes()

Source code in meilisearch_python_sdk/index.py
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
def get_filterable_attributes(self) -> list[str] | None:
    """Get filterable attributes of the index.

    Returns:
        List containing the filterable attributes of the 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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> filterable_attributes = index.get_filterable_attributes()
    """
    response = self._http_requests.get(f"{self._settings_url}/filterable-attributes")

    if not response.json():
        return None

    return response.json()

get_localized_attributes()

Get localized attributes settings for the index.

Returns:

Type Description
list[LocalizedAttributes] | None

Localized attributes for the index.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_async_client import AsyncClient >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> localized_attributes = await index.get_localized_attributes()

Source code in meilisearch_python_sdk/index.py
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
def get_localized_attributes(self) -> list[LocalizedAttributes] | None:
    """Get localized attributes settings for the index.

    Returns:
        Localized attributes for the index.

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

    Examples
        >>> from meilisearch_async_client import AsyncClient
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> localized_attributes = await index.get_localized_attributes()
    """
    response = self._http_requests.get(f"{self._settings_url}/localized-attributes")

    if not response.json():
        return None

    return [LocalizedAttributes(**x) for x in response.json()]

get_non_separator_tokens()

Get non-separator token settings for the index.

Returns:

Type Description
list[str]

Non-separator tokens for the index.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_async_client import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> non_separator_token_settings = index.get_non_separator_tokens()

Source code in meilisearch_python_sdk/index.py
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
def get_non_separator_tokens(self) -> list[str]:
    """Get non-separator token settings for the index.

    Returns:
        Non-separator tokens for the index.

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

    Examples
        >>> from meilisearch_async_client import Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> non_separator_token_settings = index.get_non_separator_tokens()
    """
    response = self._http_requests.get(f"{self._settings_url}/non-separator-tokens")

    return response.json()

get_pagination()

Get pagination settings for the index.

Returns:

Type Description
Pagination

Pagination for the index.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_async_client import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> pagination_settings = index.get_pagination()

Source code in meilisearch_python_sdk/index.py
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
def get_pagination(self) -> Pagination:
    """Get pagination settings for the index.

    Returns:
        Pagination for the index.

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

    Examples
        >>> from meilisearch_async_client import Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> pagination_settings = index.get_pagination()
    """
    response = self._http_requests.get(f"{self._settings_url}/pagination")

    return Pagination(**response.json())

get_primary_key()

Get the primary key.

Returns:

Type Description
str | None

The primary key for the documents in the index.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> primary_key = index.get_primary_key()

Source code in meilisearch_python_sdk/index.py
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
def get_primary_key(self) -> str | None:
    """Get the primary key.

    Returns:
        The primary key for the documents in the 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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> primary_key = index.get_primary_key()
    """
    info = self.fetch_info()
    return info.primary_key

get_proximity_precision()

Get proximity precision settings for the index.

Returns:

Type Description
ProximityPrecision

Proximity precision for the index.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_async_client import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> proximity_precision = index.get_proximity_precision()

Source code in meilisearch_python_sdk/index.py
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
def get_proximity_precision(self) -> ProximityPrecision:
    """Get proximity precision settings for the index.

    Returns:
        Proximity precision for the index.

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

    Examples
        >>> from meilisearch_async_client import Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> proximity_precision = index.get_proximity_precision()
    """
    response = self._http_requests.get(f"{self._settings_url}/proximity-precision")

    return ProximityPrecision[to_snake(response.json()).upper()]

get_ranking_rules()

Get ranking rules of the index.

Returns:

Type Description
list[str]

List containing the ranking rules of the index.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> ranking_rules = index.get_ranking_rules()

Source code in meilisearch_python_sdk/index.py
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
def get_ranking_rules(self) -> list[str]:
    """Get ranking rules of the index.

    Returns:
        List containing the ranking rules of the 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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> ranking_rules = index.get_ranking_rules()
    """
    response = self._http_requests.get(f"{self._settings_url}/ranking-rules")

    return response.json()

get_search_cutoff_ms()

Get search cutoff time in ms.

Returns:

Type Description
int | None

Integer representing the search cutoff time in ms, or None.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_async_client import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> search_cutoff_ms_settings = index.get_search_cutoff_ms()

Source code in meilisearch_python_sdk/index.py
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
def get_search_cutoff_ms(self) -> int | None:
    """Get search cutoff time in ms.

    Returns:
        Integer representing the search cutoff time in ms, or None.

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

    Examples
        >>> from meilisearch_async_client import Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> search_cutoff_ms_settings = index.get_search_cutoff_ms()
    """
    response = self._http_requests.get(f"{self._settings_url}/search-cutoff-ms")

    return response.json()

get_searchable_attributes()

Get searchable attributes of the index.

Returns:

Type Description
list[str]

List containing the searchable attributes of the index.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> searchable_attributes = index.get_searchable_attributes()

Source code in meilisearch_python_sdk/index.py
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
def get_searchable_attributes(self) -> list[str]:
    """Get searchable attributes of the index.

    Returns:
        List containing the searchable attributes of the 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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> searchable_attributes = index.get_searchable_attributes()
    """
    response = self._http_requests.get(f"{self._settings_url}/searchable-attributes")

    return response.json()

get_separator_tokens()

Get separator token settings for the index.

Returns:

Type Description
list[str]

Separator tokens for the index.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_async_client import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> separator_token_settings = index.get_separator_tokens()

Source code in meilisearch_python_sdk/index.py
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
def get_separator_tokens(self) -> list[str]:
    """Get separator token settings for the index.

    Returns:
        Separator tokens for the index.

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

    Examples
        >>> from meilisearch_async_client import Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> separator_token_settings = index.get_separator_tokens()
    """
    response = self._http_requests.get(f"{self._settings_url}/separator-tokens")

    return response.json()

get_settings()

Get settings of the index.

Returns:

Type Description
MeilisearchSettings

Settings of the index.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> settings = index.get_settings()

Source code in meilisearch_python_sdk/index.py
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
def get_settings(self) -> MeilisearchSettings:
    """Get settings of the index.

    Returns:
        Settings of the 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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> settings = index.get_settings()
    """
    response = self._http_requests.get(self._settings_url)
    response_json = response.json()
    settings = MeilisearchSettings(**response_json)

    if response_json.get("embedders"):
        # TODO: Add back after embedder setting issue fixed https://github.com/meilisearch/meilisearch/issues/4585
        settings.embedders = _embedder_json_to_settings_model(  # pragma: no cover
            response_json["embedders"]
        )

    return settings

get_sortable_attributes()

Get sortable attributes of the AsyncIndex.

Returns:

Type Description
list[str]

List containing the sortable attributes of the AsyncIndex.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> sortable_attributes = index.get_sortable_attributes()

Source code in meilisearch_python_sdk/index.py
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
def get_sortable_attributes(self) -> list[str]:
    """Get sortable attributes of the AsyncIndex.

    Returns:
        List containing the sortable attributes of the AsyncIndex.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> sortable_attributes = index.get_sortable_attributes()
    """
    response = self._http_requests.get(f"{self._settings_url}/sortable-attributes")

    return response.json()

get_stats()

Get stats of the index.

Returns:

Type Description
IndexStats

Stats of the index.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> stats = index.get_stats()

Source code in meilisearch_python_sdk/index.py
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
def get_stats(self) -> IndexStats:
    """Get stats of the index.

    Returns:
        Stats of the 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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> stats = index.get_stats()
    """
    response = self._http_requests.get(self._stats_url)

    return IndexStats(**response.json())

get_stop_words()

Get stop words of the index.

Returns:

Type Description
list[str] | None

List containing the stop words of the index.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> stop_words = index.get_stop_words()

Source code in meilisearch_python_sdk/index.py
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
def get_stop_words(self) -> list[str] | None:
    """Get stop words of the index.

    Returns:
        List containing the stop words of the 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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> stop_words = index.get_stop_words()
    """
    response = self._http_requests.get(f"{self._settings_url}/stop-words")

    if not response.json():
        return None

    return response.json()

get_synonyms()

Get synonyms of the index.

Returns:

Type Description
dict[str, list[str]] | None

The synonyms of the index.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> synonyms = index.get_synonyms()

Source code in meilisearch_python_sdk/index.py
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
def get_synonyms(self) -> dict[str, list[str]] | None:
    """Get synonyms of the index.

    Returns:
        The synonyms of the 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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> synonyms = index.get_synonyms()
    """
    response = self._http_requests.get(f"{self._settings_url}/synonyms")

    if not response.json():
        return None

    return response.json()

get_typo_tolerance()

Get typo tolerance for the index.

Returns:

Type Description
TypoTolerance

TypoTolerance for the index.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> sortable_attributes = index.get_typo_tolerance()

Source code in meilisearch_python_sdk/index.py
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
def get_typo_tolerance(self) -> TypoTolerance:
    """Get typo tolerance for the index.

    Returns:
        TypoTolerance for the 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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> sortable_attributes = index.get_typo_tolerance()
    """
    response = self._http_requests.get(f"{self._settings_url}/typo-tolerance")

    return TypoTolerance(**response.json())

get_word_dictionary()

Get word dictionary settings for the index.

Returns:

Type Description
list[str]

Word dictionary for the index.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_async_client import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> word_dictionary = index.get_word_dictionary()

Source code in meilisearch_python_sdk/index.py
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
def get_word_dictionary(self) -> list[str]:
    """Get word dictionary settings for the index.

    Returns:
        Word dictionary for the index.

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

    Examples
        >>> from meilisearch_async_client import Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> word_dictionary = index.get_word_dictionary()
    """
    response = self._http_requests.get(f"{self._settings_url}/dictionary")

    return response.json()

reset_displayed_attributes()

Reset displayed attributes of the index to default values.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.reset_displayed_attributes()

Source code in meilisearch_python_sdk/index.py
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
def reset_displayed_attributes(self) -> TaskInfo:
    """Reset displayed attributes of the index to default values.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.reset_displayed_attributes()
    """
    response = self._http_requests.delete(f"{self._settings_url}/displayed-attributes")

    return TaskInfo(**response.json())

reset_distinct_attribute()

Reset distinct attribute of the index to default values.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.reset_distinct_attributes()

Source code in meilisearch_python_sdk/index.py
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
def reset_distinct_attribute(self) -> TaskInfo:
    """Reset distinct attribute of the index to default values.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.reset_distinct_attributes()
    """
    response = self._http_requests.delete(f"{self._settings_url}/distinct-attribute")

    return TaskInfo(**response.json())

reset_embedders()

Reset an index's embedders settings to the default value.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_async_client import Client >>> client = AsyncClient("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.reset_embedders()

Source code in meilisearch_python_sdk/index.py
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
def reset_embedders(self) -> TaskInfo:  # pragma: no cover
    """Reset an index's embedders settings to the default value.

    Returns:
        The details of the task status.

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

    Examples
        >>> from meilisearch_async_client import Client
        >>> client = AsyncClient("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.reset_embedders()
    """
    response = self._http_requests.delete(f"{self._settings_url}/embedders")

    return TaskInfo(**response.json())

reset_faceting()

Reset an index's faceting settings to their default value.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.reset_faceting()

Source code in meilisearch_python_sdk/index.py
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
def reset_faceting(self) -> TaskInfo:
    """Reset an index's faceting settings to their default value.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.reset_faceting()
    """
    response = self._http_requests.delete(f"{self._settings_url}/faceting")

    return TaskInfo(**response.json())

reset_filterable_attributes()

Reset filterable attributes of the index to default values.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.reset_filterable_attributes()

Source code in meilisearch_python_sdk/index.py
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
def reset_filterable_attributes(self) -> TaskInfo:
    """Reset filterable attributes of the index to default values.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.reset_filterable_attributes()
    """
    response = self._http_requests.delete(f"{self._settings_url}/filterable-attributes")

    return TaskInfo(**response.json())

reset_localized_attributes()

Reset an index's localized attributes settings to the default value.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_async_client import AsyncClient >>> Client("http://localhost.com", "masterKey") as client: >>> index = client.index("movies") >>> index.reset_localized_attributes()

Source code in meilisearch_python_sdk/index.py
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
def reset_localized_attributes(self) -> TaskInfo:
    """Reset an index's localized attributes settings to the default value.

    Returns:
        The details of the task status.

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

    Examples
        >>> from meilisearch_async_client import AsyncClient
        >>> Client("http://localhost.com", "masterKey") as client:
        >>> index = client.index("movies")
        >>> index.reset_localized_attributes()
    """
    response = self._http_requests.delete(f"{self._settings_url}/localized-attributes")

    return TaskInfo(**response.json())

reset_non_separator_tokens()

Reset an index's non-separator tokens settings to the default value.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_async_client import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.reset_non_separator_tokens()

Source code in meilisearch_python_sdk/index.py
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
def reset_non_separator_tokens(self) -> TaskInfo:
    """Reset an index's non-separator tokens settings to the default value.

    Returns:
        The details of the task status.

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

    Examples
        >>> from meilisearch_async_client import Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.reset_non_separator_tokens()
    """
    response = self._http_requests.delete(f"{self._settings_url}/non-separator-tokens")

    return TaskInfo(**response.json())

reset_pagination()

Reset an index's pagination settings to their default value.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_async_client import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.reset_pagination()

Source code in meilisearch_python_sdk/index.py
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
def reset_pagination(self) -> TaskInfo:
    """Reset an index's pagination settings to their default value.

    Returns:
        The details of the task status.

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

    Examples
        >>> from meilisearch_async_client import Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.reset_pagination()
    """
    response = self._http_requests.delete(f"{self._settings_url}/pagination")

    return TaskInfo(**response.json())

reset_proximity_precision()

Reset an index's proximity precision settings to the default value.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_async_client import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.reset_proximity_precision()

Source code in meilisearch_python_sdk/index.py
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
def reset_proximity_precision(self) -> TaskInfo:
    """Reset an index's proximity precision settings to the default value.

    Returns:
        The details of the task status.

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

    Examples
        >>> from meilisearch_async_client import Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.reset_proximity_precision()
    """
    response = self._http_requests.delete(f"{self._settings_url}/proximity-precision")

    return TaskInfo(**response.json())

reset_ranking_rules()

Reset ranking rules of the index to default values.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.reset_ranking_rules()

Source code in meilisearch_python_sdk/index.py
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
def reset_ranking_rules(self) -> TaskInfo:
    """Reset ranking rules of the index to default values.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.reset_ranking_rules()
    """
    response = self._http_requests.delete(f"{self._settings_url}/ranking-rules")

    return TaskInfo(**response.json())

reset_search_cutoff_ms()

Reset the search cutoff time to the default value.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_async_client import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.reset_search_cutoff_ms()

Source code in meilisearch_python_sdk/index.py
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
def reset_search_cutoff_ms(self) -> TaskInfo:
    """Reset the search cutoff time to the default value.

    Returns:
        The details of the task status.

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

    Examples
        >>> from meilisearch_async_client import Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.reset_search_cutoff_ms()
    """
    response = self._http_requests.delete(f"{self._settings_url}/search-cutoff-ms")

    return TaskInfo(**response.json())

reset_searchable_attributes()

Reset searchable attributes of the index to default values.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.reset_searchable_attributes()

Source code in meilisearch_python_sdk/index.py
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
def reset_searchable_attributes(self) -> TaskInfo:
    """Reset searchable attributes of the index to default values.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.reset_searchable_attributes()
    """
    response = self._http_requests.delete(f"{self._settings_url}/searchable-attributes")

    return TaskInfo(**response.json())

reset_separator_tokens()

Reset an index's separator tokens settings to the default value.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_async_client import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.reset_separator_tokens()

Source code in meilisearch_python_sdk/index.py
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
def reset_separator_tokens(self) -> TaskInfo:
    """Reset an index's separator tokens settings to the default value.

    Returns:
        The details of the task status.

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

    Examples
        >>> from meilisearch_async_client import Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.reset_separator_tokens()
    """
    response = self._http_requests.delete(f"{self._settings_url}/separator-tokens")

    return TaskInfo(**response.json())

reset_settings()

Reset settings of the index to default values.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.reset_settings()

Source code in meilisearch_python_sdk/index.py
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
def reset_settings(self) -> TaskInfo:
    """Reset settings of the index to default values.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.reset_settings()
    """
    response = self._http_requests.delete(self._settings_url)

    return TaskInfo(**response.json())

reset_sortable_attributes()

Reset sortable attributes of the index to default values.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.reset_sortable_attributes()

Source code in meilisearch_python_sdk/index.py
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
def reset_sortable_attributes(self) -> TaskInfo:
    """Reset sortable attributes of the index to default values.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.reset_sortable_attributes()
    """
    response = self._http_requests.delete(f"{self._settings_url}/sortable-attributes")

    return TaskInfo(**response.json())

reset_stop_words()

Reset stop words of the index to default values.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.reset_stop_words()

Source code in meilisearch_python_sdk/index.py
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
def reset_stop_words(self) -> TaskInfo:
    """Reset stop words of the index to default values.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.reset_stop_words()
    """
    response = self._http_requests.delete(f"{self._settings_url}/stop-words")

    return TaskInfo(**response.json())

reset_synonyms()

Reset synonyms of the index to default values.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.reset_synonyms()

Source code in meilisearch_python_sdk/index.py
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
def reset_synonyms(self) -> TaskInfo:
    """Reset synonyms of the index to default values.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.reset_synonyms()
    """
    response = self._http_requests.delete(f"{self._settings_url}/synonyms")

    return TaskInfo(**response.json())

reset_typo_tolerance()

Reset typo tolerance to default values.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.reset_typo_tolerance()

Source code in meilisearch_python_sdk/index.py
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
def reset_typo_tolerance(self) -> TaskInfo:
    """Reset typo tolerance to default values.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.reset_typo_tolerance()
    """
    response = self._http_requests.delete(f"{self._settings_url}/typo-tolerance")

    return TaskInfo(**response.json())

reset_word_dictionary()

Reset an index's word dictionary settings to the default value.

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_async_client import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.reset_word_dictionary()

Source code in meilisearch_python_sdk/index.py
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
def reset_word_dictionary(self) -> TaskInfo:
    """Reset an index's word dictionary settings to the default value.

    Returns:
        The details of the task status.

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

    Examples
        >>> from meilisearch_async_client import Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.reset_word_dictionary()
    """
    response = self._http_requests.delete(f"{self._settings_url}/dictionary")

    return TaskInfo(**response.json())

search(query=None, *, offset=0, limit=20, filter=None, facets=None, attributes_to_retrieve=None, attributes_to_crop=None, crop_length=200, attributes_to_highlight=None, sort=None, show_matches_position=False, highlight_pre_tag='<em>', highlight_post_tag='</em>', crop_marker='...', matching_strategy='last', hits_per_page=None, page=None, attributes_to_search_on=None, distinct=None, show_ranking_score=False, show_ranking_score_details=False, ranking_score_threshold=None, vector=None, hybrid=None, locales=None)

Search the index.

Parameters:

Name Type Description Default
query str | None

String containing the word(s) to search

None
offset int

Number of documents to skip. Defaults to 0.

0
limit int

Maximum number of documents returned. Defaults to 20.

20
filter Filter | None

Filter queries by an attribute value. Defaults to None.

None
facets list[str] | None

Facets for which to retrieve the matching count. Defaults to None.

None
attributes_to_retrieve list[str] | None

Attributes to display in the returned documents. Defaults to ["*"].

None
attributes_to_crop list[str] | None

Attributes whose values have to be cropped. Defaults to None.

None
crop_length int

The maximun number of words to display. Defaults to 200.

200
attributes_to_highlight list[str] | None

Attributes whose values will contain highlighted matching terms. Defaults to None.

None
sort list[str] | None

Attributes by which to sort the results. Defaults to None.

None
show_matches_position bool

Defines whether an object that contains information about the matches should be returned or not. Defaults to False.

False
highlight_pre_tag str

The opening tag for highlighting text. Defaults to .

'<em>'
highlight_post_tag str

The closing tag for highlighting text. Defaults to

'</em>'
crop_marker str

Marker to display when the number of words excedes the crop_length. Defaults to ...

'...'
matching_strategy Literal['all', 'last', 'frequency']

Specifies the matching strategy Meilisearch should use. Defaults to last.

'last'
hits_per_page int | None

Sets the number of results returned per page.

None
page int | None

Sets the specific results page to fetch.

None
attributes_to_search_on list[str] | None

List of field names. Allow search over a subset of searchable attributes without modifying the index settings. Defaults to None.

None
distinct str | None

If set the distinct value will return at most one result for the filterable attribute. Note that a filterable attributes must be set for this work. Defaults to None.

None
show_ranking_score bool

If set to True the ranking score will be returned with each document in the search. Defaults to False.

False
show_ranking_score_details bool

If set to True the ranking details will be returned with each document in the search. Defaults to False. Note: This parameter can only be used with Meilisearch >= v1.3.0, and is experimental in Meilisearch v1.3.0. In order to use this feature in Meilisearch v1.3.0 you first need to enable the feature by sending a PATCH request to /experimental-features with { "scoreDetails": true }. Because this feature is experimental it may be removed or updated causing breaking changes in this library without a major version bump so use with caution. This feature became stable in Meiliseach v1.7.0.

False
ranking_score_threshold float | None

If set, no document whose _rankingScore is under the rankingScoreThreshold is returned. The value must be between 0.0 and 1.0. Defaults to None.

None
vector list[float] | None

List of vectors for vector search. Defaults to None. Note: This parameter can only be used with Meilisearch >= v1.3.0, and is experimental in Meilisearch v1.3.0. In order to use this feature in Meilisearch v1.3.0 you first need to enable the feature by sending a PATCH request to /experimental-features with { "vectorStore": true }. Because this feature is experimental it may be removed or updated causing breaking changes in this library without a major version bump so use with caution.

None
hybrid Hybrid | None

Hybrid search information. Defaults to None. Note: This parameter can only be used with Meilisearch >= v1.6.0, and is experimental in Meilisearch v1.6.0. In order to use this feature in Meilisearch v1.6.0 you first need to enable the feature by sending a PATCH request to /experimental-features with { "vectorStore": true }. Because this feature is experimental it may be removed or updated causing breaking changes in this library without a major version bump so use with caution.

None
locales list[str] | None

Specifies the languages for the search. This parameter can only be used with Milisearch >= v1.10.0. Defaults to None letting the Meilisearch pick.

None

Returns:

Type Description
SearchResults

Results of the search

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> search_results = index.search("Tron")

Source code in meilisearch_python_sdk/index.py
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
def search(
    self,
    query: str | None = None,
    *,
    offset: int = 0,
    limit: int = 20,
    filter: Filter | None = None,
    facets: list[str] | None = None,
    attributes_to_retrieve: list[str] | None = None,
    attributes_to_crop: list[str] | None = None,
    crop_length: int = 200,
    attributes_to_highlight: list[str] | None = None,
    sort: list[str] | None = None,
    show_matches_position: bool = False,
    highlight_pre_tag: str = "<em>",
    highlight_post_tag: str = "</em>",
    crop_marker: str = "...",
    matching_strategy: Literal["all", "last", "frequency"] = "last",
    hits_per_page: int | None = None,
    page: int | None = None,
    attributes_to_search_on: list[str] | None = None,
    distinct: str | None = None,
    show_ranking_score: bool = False,
    show_ranking_score_details: bool = False,
    ranking_score_threshold: float | None = None,
    vector: list[float] | None = None,
    hybrid: Hybrid | None = None,
    locales: list[str] | None = None,
) -> SearchResults:
    """Search the index.

    Args:
        query: String containing the word(s) to search
        offset: Number of documents to skip. Defaults to 0.
        limit: Maximum number of documents returned. Defaults to 20.
        filter: Filter queries by an attribute value. Defaults to None.
        facets: Facets for which to retrieve the matching count. Defaults to None.
        attributes_to_retrieve: Attributes to display in the returned documents.
            Defaults to ["*"].
        attributes_to_crop: Attributes whose values have to be cropped. Defaults to None.
        crop_length: The maximun number of words to display. Defaults to 200.
        attributes_to_highlight: Attributes whose values will contain highlighted matching terms.
            Defaults to None.
        sort: Attributes by which to sort the results. Defaults to None.
        show_matches_position: Defines whether an object that contains information about the
            matches should be returned or not. Defaults to False.
        highlight_pre_tag: The opening tag for highlighting text. Defaults to <em>.
        highlight_post_tag: The closing tag for highlighting text. Defaults to </em>
        crop_marker: Marker to display when the number of words excedes the `crop_length`.
            Defaults to ...
        matching_strategy: Specifies the matching strategy Meilisearch should use. Defaults to
            `last`.
        hits_per_page: Sets the number of results returned per page.
        page: Sets the specific results page to fetch.
        attributes_to_search_on: List of field names. Allow search over a subset of searchable
            attributes without modifying the index settings. Defaults to None.
        distinct: If set the distinct value will return at most one result for the
            filterable attribute. Note that a filterable attributes must be set for this work.
            Defaults to None.
        show_ranking_score: If set to True the ranking score will be returned with each document
            in the search. Defaults to False.
        show_ranking_score_details: If set to True the ranking details will be returned with
            each document in the search. Defaults to False. Note: This parameter can only be
            used with Meilisearch >= v1.3.0, and is experimental in Meilisearch v1.3.0. In order
            to use this feature in Meilisearch v1.3.0 you first need to enable the feature by
            sending a PATCH request to /experimental-features with { "scoreDetails": true }.
            Because this feature is experimental it may be removed or updated causing breaking
            changes in this library without a major version bump so use with caution. This
            feature became stable in Meiliseach v1.7.0.
        ranking_score_threshold: If set, no document whose _rankingScore is under the
            rankingScoreThreshold is returned. The value must be between 0.0 and 1.0. Defaults
            to None.
        vector: List of vectors for vector search. Defaults to None. Note: This parameter can
            only be used with Meilisearch >= v1.3.0, and is experimental in Meilisearch v1.3.0.
            In order to use this feature in Meilisearch v1.3.0 you first need to enable the
            feature by sending a PATCH request to /experimental-features with
            { "vectorStore": true }. Because this feature is experimental it may be removed or
            updated causing breaking changes in this library without a major version bump so use
            with caution.
        hybrid: Hybrid search information. Defaults to None. Note: This parameter can
            only be used with Meilisearch >= v1.6.0, and is experimental in Meilisearch v1.6.0.
            In order to use this feature in Meilisearch v1.6.0 you first need to enable the
            feature by sending a PATCH request to /experimental-features with
            { "vectorStore": true }. Because this feature is experimental it may be removed or
            updated causing breaking changes in this library without a major version bump so use
            with caution.
        locales: Specifies the languages for the search. This parameter can only be used with
            Milisearch >= v1.10.0. Defaults to None letting the Meilisearch pick.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> search_results = index.search("Tron")
    """
    if ranking_score_threshold:
        _validate_ranking_score_threshold(ranking_score_threshold)

    body = _process_search_parameters(
        q=query,
        offset=offset,
        limit=limit,
        filter=filter,
        facets=facets,
        attributes_to_retrieve=attributes_to_retrieve,
        attributes_to_crop=attributes_to_crop,
        crop_length=crop_length,
        attributes_to_highlight=attributes_to_highlight,
        sort=sort,
        show_matches_position=show_matches_position,
        highlight_pre_tag=highlight_pre_tag,
        highlight_post_tag=highlight_post_tag,
        crop_marker=crop_marker,
        matching_strategy=matching_strategy,
        hits_per_page=hits_per_page,
        page=page,
        attributes_to_search_on=attributes_to_search_on,
        distinct=distinct,
        show_ranking_score=show_ranking_score,
        show_ranking_score_details=show_ranking_score_details,
        vector=vector,
        hybrid=hybrid,
        ranking_score_threshold=ranking_score_threshold,
        locales=locales,
    )

    if self._pre_search_plugins:
        Index._run_plugins(
            self._pre_search_plugins,
            Event.PRE,
            query=query,
            offset=offset,
            limit=limit,
            filter=filter,
            facets=facets,
            attributes_to_retrieve=attributes_to_retrieve,
            attributes_to_crop=attributes_to_crop,
            crop_length=crop_length,
            attributes_to_highlight=attributes_to_highlight,
            sort=sort,
            show_matches_position=show_matches_position,
            highlight_pre_tag=highlight_pre_tag,
            highlight_post_tag=highlight_post_tag,
            crop_marker=crop_marker,
            matching_strategy=matching_strategy,
            hits_per_page=hits_per_page,
            page=page,
            attributes_to_search_on=attributes_to_search_on,
            distinct=distinct,
            show_ranking_score=show_ranking_score,
            show_ranking_score_details=show_ranking_score_details,
            vector=vector,
            hybrid=hybrid,
        )

    response = self._http_requests.post(f"{self._base_url_with_uid}/search", body=body)
    result = SearchResults[self.hits_type](**response.json())  # type: ignore[name-defined]
    if self._post_search_plugins:
        post = Index._run_plugins(self._post_search_plugins, Event.POST, search_results=result)
        if post.get("search_result"):
            result = post["search_result"]

    return result

search_similar_documents(id, *, offset=None, limit=None, filter=None, embedder='default', attributes_to_retrieve=None, show_ranking_score=False, show_ranking_score_details=False, ranking_score_threshold=None)

Search the index.

Parameters:

Name Type Description Default
id str

The id for the target document that is being used to find similar documents.

required
offset int | None

Number of documents to skip. Defaults to 0.

None
limit int | None

Maximum number of documents returned. Defaults to 20.

None
filter str | None

Filter queries by an attribute value. Defaults to None.

None
embedder str

The vector DB to use for the search.

'default'
attributes_to_retrieve list[str] | None

Attributes to display in the returned documents. Defaults to ["*"].

None
show_ranking_score bool

If set to True the ranking score will be returned with each document in the search. Defaults to False.

False
show_ranking_score_details bool

If set to True the ranking details will be returned with each document in the search. Defaults to False.

False
ranking_score_threshold float | None

If set, no document whose _rankingScore is under the rankingScoreThreshold is returned. The value must be between 0.0 and 1.0. Defaults to None.

None

Returns:

Type Description
SimilarSearchResults

Results of the search

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> search_results = index.search_similar_documents("123")

Source code in meilisearch_python_sdk/index.py
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
def search_similar_documents(
    self,
    id: str,
    *,
    offset: int | None = None,
    limit: int | None = None,
    filter: str | None = None,
    embedder: str = "default",
    attributes_to_retrieve: list[str] | None = None,
    show_ranking_score: bool = False,
    show_ranking_score_details: bool = False,
    ranking_score_threshold: float | None = None,
) -> SimilarSearchResults:
    """Search the index.

    Args:
        id: The id for the target document that is being used to find similar documents.
        offset: Number of documents to skip. Defaults to 0.
        limit: Maximum number of documents returned. Defaults to 20.
        filter: Filter queries by an attribute value. Defaults to None.
        embedder: The vector DB to use for the search.
        attributes_to_retrieve: Attributes to display in the returned documents.
            Defaults to ["*"].
        show_ranking_score: If set to True the ranking score will be returned with each document
            in the search. Defaults to False.
        show_ranking_score_details: If set to True the ranking details will be returned with
            each document in the search. Defaults to False.
        ranking_score_threshold: If set, no document whose _rankingScore is under the
            rankingScoreThreshold is returned. The value must be between 0.0 and 1.0. Defaults
            to None.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> search_results = index.search_similar_documents("123")
    """
    payload = {
        "id": id,
        "filter": filter,
        "embedder": embedder,
        "attributesToRetrieve": attributes_to_retrieve,
        "showRankingScore": show_ranking_score,
        "showRankingScoreDetails": show_ranking_score_details,
        "rankingScoreThreshold": ranking_score_threshold,
    }

    if offset:
        payload["offset"] = offset

    if limit:
        payload["limit"] = limit

    response = self._http_requests.post(f"{self._base_url_with_uid}/similar", body=payload)

    return SimilarSearchResults[self.hits_type](**response.json())  # type: ignore[name-defined]

update(primary_key)

Update the index primary key.

Parameters:

Name Type Description Default
primary_key str

The primary key of the documents.

required

Returns:

Type Description
Self

An instance of the AsyncIndex with the updated information.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> updated_index = index.update()

Source code in meilisearch_python_sdk/index.py
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
def update(self, primary_key: str) -> Self:
    """Update the index primary key.

    Args:
        primary_key: The primary key of the documents.

    Returns:
        An instance of the AsyncIndex with the updated information.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> updated_index = index.update()
    """
    payload = {"primaryKey": primary_key}
    response = self._http_requests.patch(self._base_url_with_uid, payload)
    wait_for_task(self.http_client, response.json()["taskUid"], timeout_in_ms=100000)
    index_response = self._http_requests.get(self._base_url_with_uid)
    self.primary_key = index_response.json()["primaryKey"]
    return self

update_displayed_attributes(body, *, compress=False)

Update displayed attributes of the index.

Parameters:

Name Type Description Default
body list[str]

List containing the displayed attributes.

required
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_displayed_attributes( >>> ["title", "description", "genre", "release_date"] >>> )

Source code in meilisearch_python_sdk/index.py
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
def update_displayed_attributes(self, body: list[str], *, compress: bool = False) -> TaskInfo:
    """Update displayed attributes of the index.

    Args:
        body: List containing the displayed attributes.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_displayed_attributes(
        >>>     ["title", "description", "genre", "release_date"]
        >>> )
    """
    response = self._http_requests.put(
        f"{self._settings_url}/displayed-attributes", body, compress=compress
    )

    return TaskInfo(**response.json())

update_distinct_attribute(body, *, compress=False)

Update distinct attribute of the index.

Parameters:

Name Type Description Default
body str

Distinct attribute.

required
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_distinct_attribute("url")

Source code in meilisearch_python_sdk/index.py
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
def update_distinct_attribute(self, body: str, *, compress: bool = False) -> TaskInfo:
    """Update distinct attribute of the index.

    Args:
        body: Distinct attribute.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_distinct_attribute("url")
    """
    response = self._http_requests.put(
        f"{self._settings_url}/distinct-attribute", body, compress=compress
    )

    return TaskInfo(**response.json())

update_documents(documents, primary_key=None, *, compress=False)

Update documents in the index.

Parameters:

Name Type Description Default
documents Sequence[JsonMapping]

List of documents.

required
primary_key str | None

The primary key of the documents. This will be ignored if already set. Defaults to None.

None
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

The details of the task.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> documents = [ >>> {"id": 1, "title": "Movie 1", "genre": "comedy"}, >>> {"id": 2, "title": "Movie 2", "genre": "drama"}, >>> ] >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_documents(documents)

Source code in meilisearch_python_sdk/index.py
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
def update_documents(
    self,
    documents: Sequence[JsonMapping],
    primary_key: str | None = None,
    *,
    compress: bool = False,
) -> TaskInfo:
    """Update documents in the index.

    Args:
        documents: List of documents.
        primary_key: The primary key of the documents. This will be ignored if already set.
            Defaults to None.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    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 Client
        >>> documents = [
        >>>     {"id": 1, "title": "Movie 1", "genre": "comedy"},
        >>>     {"id": 2, "title": "Movie 2", "genre": "drama"},
        >>> ]
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_documents(documents)
    """
    if primary_key:
        url = _build_encoded_url(self._documents_url, {"primaryKey": primary_key})
    else:
        url = self._documents_url

    if self._pre_update_documents_plugins:
        pre = Index._run_plugins(
            self._pre_update_documents_plugins,
            Event.PRE,
            documents=documents,
            primary_key=primary_key,
        )
        if pre.get("document_result"):
            documents = pre["document_result"]

    response = self._http_requests.put(url, documents, compress=compress)
    result = TaskInfo(**response.json())
    if self._post_update_documents_plugins:
        post = Index._run_plugins(
            self._post_update_documents_plugins, Event.POST, result=result
        )
        if isinstance(post.get("generic_result"), TaskInfo):
            result = post["generic_result"]

    return result

update_documents_from_directory(directory_path, *, primary_key=None, document_type='json', csv_delimiter=None, combine_documents=True, compress=False)

Load all json files from a directory and update the documents.

Parameters:

Name Type Description Default
directory_path Path | str

Path to the directory that contains the json files.

required
primary_key str | None

The primary key of the documents. This will be ignored if already set. Defaults to None.

None
document_type str

The type of document being added. Accepted types are json, csv, and ndjson. For csv files the first row of the document should be a header row contining the field names, and ever for should have a title.

'json'
csv_delimiter str | None

A single ASCII character to specify the delimiter for csv files. This can only be used if the file is a csv file. Defaults to comma.

None
combine_documents bool

If set to True this will combine the documents from all the files before indexing them. Defaults to True.

True
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
list[TaskInfo]

The details of the task status.

Raises:

Type Description
InvalidDocumentError

If the docucment is not a valid format for Meilisearch.

MeilisearchError

If the file path is not valid

MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from pathlib import Path >>> from meilisearch_python_sdk import Client >>> directory_path = Path("/path/to/directory/containing/files") >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_documents_from_directory(directory_path)

Source code in meilisearch_python_sdk/index.py
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
def update_documents_from_directory(
    self,
    directory_path: Path | str,
    *,
    primary_key: str | None = None,
    document_type: str = "json",
    csv_delimiter: str | None = None,
    combine_documents: bool = True,
    compress: bool = False,
) -> list[TaskInfo]:
    """Load all json files from a directory and update the documents.

    Args:
        directory_path: Path to the directory that contains the json files.
        primary_key: The primary key of the documents. This will be ignored if already set.
            Defaults to None.
        document_type: The type of document being added. Accepted types are json, csv, and
            ndjson. For csv files the first row of the document should be a header row contining
            the field names, and ever for should have a title.
        csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
            can only be used if the file is a csv file. Defaults to comma.
        combine_documents: If set to True this will combine the documents from all the files
            before indexing them. Defaults to True.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        The details of the task status.

    Raises:
        InvalidDocumentError: If the docucment is not a valid format for Meilisearch.
        MeilisearchError: If the file path is not valid
        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples
        >>> from pathlib import Path
        >>> from meilisearch_python_sdk import Client
        >>> directory_path = Path("/path/to/directory/containing/files")
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_documents_from_directory(directory_path)
    """
    directory = Path(directory_path) if isinstance(directory_path, str) else directory_path

    if combine_documents:
        all_documents = []
        for path in directory.iterdir():
            if path.suffix == f".{document_type}":
                documents = _load_documents_from_file(
                    path, csv_delimiter, json_handler=self._json_handler
                )
                all_documents.append(documents)

        _raise_on_no_documents(all_documents, document_type, directory_path)

        combined = _combine_documents(all_documents)

        response = self.update_documents(combined, primary_key, compress=compress)
        return [response]

    responses = []
    for path in directory.iterdir():
        if path.suffix == f".{document_type}":
            documents = _load_documents_from_file(
                path, csv_delimiter, json_handler=self._json_handler
            )
            responses.append(self.update_documents(documents, primary_key, compress=compress))

    _raise_on_no_documents(responses, document_type, directory_path)

    return responses

update_documents_from_directory_in_batches(directory_path, *, batch_size=1000, primary_key=None, document_type='json', csv_delimiter=None, combine_documents=True, compress=False)

Load all json files from a directory and update the documents.

Parameters:

Name Type Description Default
directory_path Path | str

Path to the directory that contains the json files.

required
batch_size int

The number of documents that should be included in each batch. Defaults to 1000.

1000
primary_key str | None

The primary key of the documents. This will be ignored if already set. Defaults to None.

None
document_type str

The type of document being added. Accepted types are json, csv, and ndjson. For csv files the first row of the document should be a header row contining the field names, and ever for should have a title.

'json'
csv_delimiter str | None

A single ASCII character to specify the delimiter for csv files. This can only be used if the file is a csv file. Defaults to comma.

None
combine_documents bool

If set to True this will combine the documents from all the files before indexing them. Defaults to True.

True
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
list[TaskInfo]

List of update ids to track the action.

Raises:

Type Description
InvalidDocumentError

If the docucment is not a valid format for Meilisearch.

MeilisearchError

If the file path is not valid

MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from pathlib import Path >>> from meilisearch_python_sdk import Client >>> directory_path = Path("/path/to/directory/containing/files") >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_documents_from_directory_in_batches(directory_path)

Source code in meilisearch_python_sdk/index.py
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
def update_documents_from_directory_in_batches(
    self,
    directory_path: Path | str,
    *,
    batch_size: int = 1000,
    primary_key: str | None = None,
    document_type: str = "json",
    csv_delimiter: str | None = None,
    combine_documents: bool = True,
    compress: bool = False,
) -> list[TaskInfo]:
    """Load all json files from a directory and update the documents.

    Args:
        directory_path: Path to the directory that contains the json files.
        batch_size: The number of documents that should be included in each batch.
            Defaults to 1000.
        primary_key: The primary key of the documents. This will be ignored if already set.
            Defaults to None.
        document_type: The type of document being added. Accepted types are json, csv, and
            ndjson. For csv files the first row of the document should be a header row contining
            the field names, and ever for should have a title.
        csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
            can only be used if the file is a csv file. Defaults to comma.
        combine_documents: If set to True this will combine the documents from all the files
            before indexing them. Defaults to True.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        List of update ids to track the action.

    Raises:
        InvalidDocumentError: If the docucment is not a valid format for Meilisearch.
        MeilisearchError: If the file path is not valid
        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples
        >>> from pathlib import Path
        >>> from meilisearch_python_sdk import Client
        >>> directory_path = Path("/path/to/directory/containing/files")
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_documents_from_directory_in_batches(directory_path)
    """
    directory = Path(directory_path) if isinstance(directory_path, str) else directory_path

    if combine_documents:
        all_documents = []
        for path in directory.iterdir():
            if path.suffix == f".{document_type}":
                documents = _load_documents_from_file(
                    path, csv_delimiter, json_handler=self._json_handler
                )
                all_documents.append(documents)

        _raise_on_no_documents(all_documents, document_type, directory_path)

        combined = _combine_documents(all_documents)

        return self.update_documents_in_batches(
            combined,
            batch_size=batch_size,
            primary_key=primary_key,
            compress=compress,
        )

    responses: list[TaskInfo] = []

    for path in directory.iterdir():
        if path.suffix == f".{document_type}":
            documents = _load_documents_from_file(
                path, csv_delimiter, json_handler=self._json_handler
            )
            responses.extend(
                self.update_documents_in_batches(
                    documents,
                    batch_size=batch_size,
                    primary_key=primary_key,
                    compress=compress,
                )
            )

    _raise_on_no_documents(responses, document_type, directory_path)

    return responses

update_documents_from_file(file_path, primary_key=None, csv_delimiter=None, *, compress=False)

Add documents in the index from a json file.

Parameters:

Name Type Description Default
file_path Path | str

Path to the json file.

required
primary_key str | None

The primary key of the documents. This will be ignored if already set. Defaults to None.

None
csv_delimiter str | None

A single ASCII character to specify the delimiter for csv files. This can only be used if the file is a csv file. Defaults to comma.

None
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from pathlib import Path >>> from meilisearch_python_sdk import Client >>> file_path = Path("/path/to/file.json") >>> client = Client("http://localhost.com", "masterKey") as client: >>> index = client.index("movies") >>> index.update_documents_from_file(file_path)

Source code in meilisearch_python_sdk/index.py
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
def update_documents_from_file(
    self,
    file_path: Path | str,
    primary_key: str | None = None,
    csv_delimiter: str | None = None,
    *,
    compress: bool = False,
) -> TaskInfo:
    """Add documents in the index from a json file.

    Args:
        file_path: Path to the json file.
        primary_key: The primary key of the documents. This will be ignored if already set.
            Defaults to None.
        csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
            can only be used if the file is a csv file. Defaults to comma.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        The details of the task status.

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

    Examples
        >>> from pathlib import Path
        >>> from meilisearch_python_sdk import Client
        >>> file_path = Path("/path/to/file.json")
        >>> client = Client("http://localhost.com", "masterKey") as client:
        >>> index = client.index("movies")
        >>> index.update_documents_from_file(file_path)
    """
    documents = _load_documents_from_file(
        file_path, csv_delimiter, json_handler=self._json_handler
    )

    return self.update_documents(documents, primary_key=primary_key, compress=compress)

update_documents_from_file_in_batches(file_path, *, batch_size=1000, primary_key=None, compress=False)

Updates documents form a json file in batches to reduce RAM usage with indexing.

Parameters:

Name Type Description Default
file_path Path | str

Path to the json file.

required
batch_size int

The number of documents that should be included in each batch. Defaults to 1000.

1000
primary_key str | None

The primary key of the documents. This will be ignored if already set. Defaults to None.

None
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
list[TaskInfo]

List of update ids to track the action.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from pathlib import Path >>> from meilisearch_python_sdk import Client >>> file_path = Path("/path/to/file.json") >>> client = Client("http://localhost.com", "masterKey") as client: >>> index = client.index("movies") >>> index.update_documents_from_file_in_batches(file_path)

Source code in meilisearch_python_sdk/index.py
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
def update_documents_from_file_in_batches(
    self,
    file_path: Path | str,
    *,
    batch_size: int = 1000,
    primary_key: str | None = None,
    compress: bool = False,
) -> list[TaskInfo]:
    """Updates documents form a json file in batches to reduce RAM usage with indexing.

    Args:
        file_path: Path to the json file.
        batch_size: The number of documents that should be included in each batch.
            Defaults to 1000.
        primary_key: The primary key of the documents. This will be ignored if already set.
            Defaults to None.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        List of update ids to track the action.

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

    Examples
        >>> from pathlib import Path
        >>> from meilisearch_python_sdk import Client
        >>> file_path = Path("/path/to/file.json")
        >>> client = Client("http://localhost.com", "masterKey") as client:
        >>> index = client.index("movies")
        >>> index.update_documents_from_file_in_batches(file_path)
    """
    documents = _load_documents_from_file(file_path, json_handler=self._json_handler)

    return self.update_documents_in_batches(
        documents,
        batch_size=batch_size,
        primary_key=primary_key,
        compress=compress,
    )

update_documents_from_raw_file(file_path, primary_key=None, csv_delimiter=None, *, compress=False)

Directly send csv or ndjson files to Meilisearch without pre-processing.

The can reduce RAM usage from Meilisearch during indexing, but does not include the option for batching.

Parameters:

Name Type Description Default
file_path Path | str

The path to the file to send to Meilisearch. Only csv and ndjson files are allowed.

required
primary_key str | None

The primary key of the documents. This will be ignored if already set. Defaults to None.

None
csv_delimiter str | None

A single ASCII character to specify the delimiter for csv files. This can only be used if the file is a csv file. Defaults to comma.

None
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
ValueError

If the file is not a csv or ndjson file, or if a csv_delimiter is sent for a non-csv file.

MeilisearchError

If the file path is not valid

MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from pathlib import Path >>> from meilisearch_python_sdk import Client >>> file_path = Path("/path/to/file.csv") >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_documents_from_raw_file(file_path)

Source code in meilisearch_python_sdk/index.py
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
def update_documents_from_raw_file(
    self,
    file_path: Path | str,
    primary_key: str | None = None,
    csv_delimiter: str | None = None,
    *,
    compress: bool = False,
) -> TaskInfo:
    """Directly send csv or ndjson files to Meilisearch without pre-processing.

    The can reduce RAM usage from Meilisearch during indexing, but does not include the option
    for batching.

    Args:
        file_path: The path to the file to send to Meilisearch. Only csv and ndjson files are
            allowed.
        primary_key: The primary key of the documents. This will be ignored if already set.
            Defaults to None.
        csv_delimiter: A single ASCII character to specify the delimiter for csv files. This
            can only be used if the file is a csv file. Defaults to comma.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        The details of the task status.

    Raises:
        ValueError: If the file is not a csv or ndjson file, or if a csv_delimiter is sent for
            a non-csv file.
        MeilisearchError: If the file path is not valid
        MeilisearchCommunicationError: If there was an error communicating with the server.
        MeilisearchApiError: If the Meilisearch API returned an error.

    Examples
        >>> from pathlib import Path
        >>> from meilisearch_python_sdk import Client
        >>> file_path = Path("/path/to/file.csv")
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_documents_from_raw_file(file_path)
    """
    upload_path = Path(file_path) if isinstance(file_path, str) else file_path
    if not upload_path.exists():
        raise MeilisearchError("No file found at the specified path")

    if upload_path.suffix not in (".csv", ".ndjson"):
        raise ValueError("Only csv and ndjson files can be sent as binary files")

    if csv_delimiter and upload_path.suffix != ".csv":
        raise ValueError("A csv_delimiter can only be used with csv files")

    if (
        csv_delimiter
        and len(csv_delimiter) != 1
        or csv_delimiter
        and not csv_delimiter.isascii()
    ):
        raise ValueError("csv_delimiter must be a single ascii character")

    content_type = "text/csv" if upload_path.suffix == ".csv" else "application/x-ndjson"
    parameters = {}

    if primary_key:
        parameters["primaryKey"] = primary_key
    if csv_delimiter:
        parameters["csvDelimiter"] = csv_delimiter

    if parameters:
        url = _build_encoded_url(self._documents_url, parameters)
    else:
        url = self._documents_url

    with open(upload_path) as f:
        data = f.read()

    response = self._http_requests.put(
        url, body=data, content_type=content_type, compress=compress
    )

    return TaskInfo(**response.json())

update_documents_in_batches(documents, *, batch_size=1000, primary_key=None, compress=False)

Update documents in batches to reduce RAM usage with indexing.

Each batch tries to fill the max_payload_size

Parameters:

Name Type Description Default
documents Sequence[JsonMapping]

List of documents.

required
batch_size int

The number of documents that should be included in each batch. Defaults to 1000.

1000
primary_key str | None

The primary key of the documents. This will be ignored if already set. Defaults to None.

None
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
list[TaskInfo]

List of update ids to track the action.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> documents = [ >>> {"id": 1, "title": "Movie 1", "genre": "comedy"}, >>> {"id": 2, "title": "Movie 2", "genre": "drama"}, >>> ] >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_documents_in_batches(documents)

Source code in meilisearch_python_sdk/index.py
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
def update_documents_in_batches(
    self,
    documents: Sequence[JsonMapping],
    *,
    batch_size: int = 1000,
    primary_key: str | None = None,
    compress: bool = False,
) -> list[TaskInfo]:
    """Update documents in batches to reduce RAM usage with indexing.

    Each batch tries to fill the max_payload_size

    Args:
        documents: List of documents.
        batch_size: The number of documents that should be included in each batch.
            Defaults to 1000.
        primary_key: The primary key of the documents. This will be ignored if already set.
            Defaults to None.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        List of update ids to track the action.

    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 Client
        >>> documents = [
        >>>     {"id": 1, "title": "Movie 1", "genre": "comedy"},
        >>>     {"id": 2, "title": "Movie 2", "genre": "drama"},
        >>> ]
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_documents_in_batches(documents)
    """
    return [
        self.update_documents(x, primary_key, compress=compress)
        for x in _batch(documents, batch_size)
    ]

update_embedders(embedders, *, compress=False)

Update the embedders settings for an index.

Parameters:

Name Type Description Default
embedders Embedders

The embedders value.

required
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

Task to track the action.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> from meilisearch_python_sdk.models.settings import Embedders, UserProvidedEmbedder >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_embedders( >>> Embedders(embedders={dimensions=512)}) >>> )

Source code in meilisearch_python_sdk/index.py
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
def update_embedders(self, embedders: Embedders, *, compress: bool = False) -> TaskInfo:
    """Update the embedders settings for an index.

    Args:
        embedders: The embedders value.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        Task to track the action.

    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 Client
        >>> from meilisearch_python_sdk.models.settings import Embedders, UserProvidedEmbedder
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_embedders(
        >>>     Embedders(embedders={dimensions=512)})
        >>> )
    """
    payload = {}
    for key, embedder in embedders.embedders.items():
        payload[key] = {
            k: v
            for k, v in embedder.model_dump(by_alias=True, exclude_none=True).items()
            if v is not None
        }

    response = self._http_requests.patch(
        f"{self._settings_url}/embedders", payload, compress=compress
    )

    return TaskInfo(**response.json())

update_faceting(faceting, *, compress=False)

Partially update the faceting settings for an index.

Parameters:

Name Type Description Default
faceting Faceting

Faceting values.

required
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

Task to track the action.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_faceting(faceting=Faceting(max_values_per_facet=100))

Source code in meilisearch_python_sdk/index.py
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
def update_faceting(self, faceting: Faceting, *, compress: bool = False) -> TaskInfo:
    """Partially update the faceting settings for an index.

    Args:
        faceting: Faceting values.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        Task to track the action.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_faceting(faceting=Faceting(max_values_per_facet=100))
    """
    response = self._http_requests.patch(
        f"{self._settings_url}/faceting",
        faceting.model_dump(by_alias=True),
        compress=compress,
    )

    return TaskInfo(**response.json())

update_filterable_attributes(body, *, compress=False)

Update filterable attributes of the index.

Parameters:

Name Type Description Default
body list[str]

List containing the filterable attributes of the index.

required
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_filterable_attributes(["genre", "director"])

Source code in meilisearch_python_sdk/index.py
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
def update_filterable_attributes(self, body: list[str], *, compress: bool = False) -> TaskInfo:
    """Update filterable attributes of the index.

    Args:
        body: List containing the filterable attributes of the index.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_filterable_attributes(["genre", "director"])
    """
    response = self._http_requests.put(
        f"{self._settings_url}/filterable-attributes", body, compress=compress
    )

    return TaskInfo(**response.json())

update_localized_attributes(localized_attributes, *, compress=False)

Update the localized attributes settings for an index.

Parameters:

Name Type Description Default
localized_attributes list[LocalizedAttributes]

The localized attributes value.

required
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

Task to track the action.

Raises:

Type Description
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.settings import LocalizedAttributes >>> >>> >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_localized_attributes([ >>> LocalizedAttributes(locales=["eng", "spa"], attribute_patterns=[""]), >>> LocalizedAttributes(locales=["ita"], attribute_patterns=["_it"]), >>> ])

Source code in meilisearch_python_sdk/index.py
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
def update_localized_attributes(
    self, localized_attributes: list[LocalizedAttributes], *, compress: bool = False
) -> TaskInfo:
    """Update the localized attributes settings for an index.

    Args:
        localized_attributes: The localized attributes value.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        Task to track the action.

    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.settings import LocalizedAttributes
        >>>
        >>>
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_localized_attributes([
        >>>     LocalizedAttributes(locales=["eng", "spa"], attribute_patterns=["*"]),
        >>>     LocalizedAttributes(locales=["ita"], attribute_patterns=["*_it"]),
        >>> ])
    """
    payload = [x.model_dump(by_alias=True) for x in localized_attributes]
    response = self._http_requests.put(
        f"{self._settings_url}/localized-attributes", payload, compress=compress
    )

    return TaskInfo(**response.json())

update_non_separator_tokens(non_separator_tokens, *, compress=False)

Update the non-separator tokens settings for an index.

Parameters:

Name Type Description Default
non_separator_tokens list[str]

List of non-separator tokens.

required
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

Task to track the action.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_non_separator_tokens(non_separator_tokens=["@", "#")

Source code in meilisearch_python_sdk/index.py
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
def update_non_separator_tokens(
    self, non_separator_tokens: list[str], *, compress: bool = False
) -> TaskInfo:
    """Update the non-separator tokens settings for an index.

    Args:
        non_separator_tokens: List of non-separator tokens.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        Task to track the action.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_non_separator_tokens(non_separator_tokens=["@", "#")
    """
    response = self._http_requests.put(
        f"{self._settings_url}/non-separator-tokens", non_separator_tokens, compress=compress
    )

    return TaskInfo(**response.json())

update_pagination(settings, *, compress=False)

Partially update the pagination settings for an index.

Parameters:

Name Type Description Default
settings Pagination

settings for pagination.

required
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

Task to track the action.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> from meilisearch_python_sdk.models.settings import Pagination >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_pagination(settings=Pagination(max_total_hits=123))

Source code in meilisearch_python_sdk/index.py
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
def update_pagination(self, settings: Pagination, *, compress: bool = False) -> TaskInfo:
    """Partially update the pagination settings for an index.

    Args:
        settings: settings for pagination.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        Task to track the action.

    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 Client
        >>> from meilisearch_python_sdk.models.settings import Pagination
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_pagination(settings=Pagination(max_total_hits=123))
    """
    response = self._http_requests.patch(
        f"{self._settings_url}/pagination",
        settings.model_dump(by_alias=True),
        compress=compress,
    )

    return TaskInfo(**response.json())

update_proximity_precision(proximity_precision, *, compress=False)

Update the proximity precision settings for an index.

Parameters:

Name Type Description Default
proximity_precision ProximityPrecision

The proximity precision value.

required
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

Task to track the action.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> from meilisearch_python_sdk.models.settings import ProximityPrecision >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_proximity_precision(ProximityPrecision.BY_ATTRIBUTE)

Source code in meilisearch_python_sdk/index.py
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
def update_proximity_precision(
    self, proximity_precision: ProximityPrecision, *, compress: bool = False
) -> TaskInfo:
    """Update the proximity precision settings for an index.

    Args:
        proximity_precision: The proximity precision value.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        Task to track the action.

    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 Client
        >>> from meilisearch_python_sdk.models.settings import ProximityPrecision
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_proximity_precision(ProximityPrecision.BY_ATTRIBUTE)
    """
    response = self._http_requests.put(
        f"{self._settings_url}/proximity-precision",
        proximity_precision.value,
        compress=compress,
    )

    return TaskInfo(**response.json())

update_ranking_rules(ranking_rules, *, compress=False)

Update ranking rules of the index.

Parameters:

Name Type Description Default
ranking_rules list[str]

List containing the ranking rules.

required
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> ranking_rules=[ >>> "words", >>> "typo", >>> "proximity", >>> "attribute", >>> "sort", >>> "exactness", >>> "release_date:desc", >>> "rank:desc", >>> ], >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_ranking_rules(ranking_rules)

Source code in meilisearch_python_sdk/index.py
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
def update_ranking_rules(self, ranking_rules: list[str], *, compress: bool = False) -> TaskInfo:
    """Update ranking rules of the index.

    Args:
        ranking_rules: List containing the ranking rules.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        The details of the task status.

    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 Client
        >>> ranking_rules=[
        >>>      "words",
        >>>      "typo",
        >>>      "proximity",
        >>>      "attribute",
        >>>      "sort",
        >>>      "exactness",
        >>>      "release_date:desc",
        >>>      "rank:desc",
        >>> ],
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_ranking_rules(ranking_rules)
    """
    response = self._http_requests.put(
        f"{self._settings_url}/ranking-rules", ranking_rules, compress=compress
    )

    return TaskInfo(**response.json())

update_search_cutoff_ms(search_cutoff_ms, *, compress=False)

Update the search cutoff for an index.

Parameters:

Name Type Description Default
search_cutoff_ms int

Integer value of the search cutoff time in ms.

required
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

Task to track the action.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_search_cutoff_ms(100)

Source code in meilisearch_python_sdk/index.py
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
def update_search_cutoff_ms(self, search_cutoff_ms: int, *, compress: bool = False) -> TaskInfo:
    """Update the search cutoff for an index.

    Args:
        search_cutoff_ms: Integer value of the search cutoff time in ms.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        Task to track the action.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_search_cutoff_ms(100)
    """
    response = self._http_requests.put(
        f"{self._settings_url}/search-cutoff-ms", search_cutoff_ms, compress=compress
    )

    return TaskInfo(**response.json())

update_searchable_attributes(body, *, compress=False)

Update searchable attributes of the index.

Parameters:

Name Type Description Default
body list[str]

List containing the searchable attributes.

required
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_searchable_attributes(["title", "description", "genre"])

Source code in meilisearch_python_sdk/index.py
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
def update_searchable_attributes(self, body: list[str], *, compress: bool = False) -> TaskInfo:
    """Update searchable attributes of the index.

    Args:
        body: List containing the searchable attributes.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_searchable_attributes(["title", "description", "genre"])
    """
    response = self._http_requests.put(
        f"{self._settings_url}/searchable-attributes", body, compress=compress
    )

    return TaskInfo(**response.json())

update_separator_tokens(separator_tokens, *, compress=False)

Update the separator tokens settings for an index.

Parameters:

Name Type Description Default
separator_tokens list[str]

List of separator tokens.

required
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

Task to track the action.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_separator_tokens(separator_tokenes=["|", "/")

Source code in meilisearch_python_sdk/index.py
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
def update_separator_tokens(
    self, separator_tokens: list[str], *, compress: bool = False
) -> TaskInfo:
    """Update the separator tokens settings for an index.

    Args:
        separator_tokens: List of separator tokens.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        Task to track the action.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_separator_tokens(separator_tokenes=["|", "/")
    """
    response = self._http_requests.put(
        f"{self._settings_url}/separator-tokens", separator_tokens, compress=compress
    )

    return TaskInfo(**response.json())

update_settings(body, *, compress=False)

Update settings of the index.

Parameters:

Name Type Description Default
body MeilisearchSettings

Settings of the index.

required
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> from meilisearch_python_sdk import MeilisearchSettings >>> new_settings = MeilisearchSettings( >>> synonyms={"wolverine": ["xmen", "logan"], "logan": ["wolverine"]}, >>> stop_words=["the", "a", "an"], >>> ranking_rules=[ >>> "words", >>> "typo", >>> "proximity", >>> "attribute", >>> "sort", >>> "exactness", >>> "release_date:desc", >>> "rank:desc", >>> ], >>> filterable_attributes=["genre", "director"], >>> distinct_attribute="url", >>> searchable_attributes=["title", "description", "genre"], >>> displayed_attributes=["title", "description", "genre", "release_date"], >>> sortable_attributes=["title", "release_date"], >>> ) >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_settings(new_settings)

Source code in meilisearch_python_sdk/index.py
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
def update_settings(self, body: MeilisearchSettings, *, compress: bool = False) -> TaskInfo:
    """Update settings of the index.

    Args:
        body: Settings of the index.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        The details of the task status.

    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 Client
        >>> from meilisearch_python_sdk import MeilisearchSettings
        >>> new_settings = MeilisearchSettings(
        >>>     synonyms={"wolverine": ["xmen", "logan"], "logan": ["wolverine"]},
        >>>     stop_words=["the", "a", "an"],
        >>>     ranking_rules=[
        >>>         "words",
        >>>         "typo",
        >>>         "proximity",
        >>>         "attribute",
        >>>         "sort",
        >>>         "exactness",
        >>>         "release_date:desc",
        >>>         "rank:desc",
        >>>    ],
        >>>    filterable_attributes=["genre", "director"],
        >>>    distinct_attribute="url",
        >>>    searchable_attributes=["title", "description", "genre"],
        >>>    displayed_attributes=["title", "description", "genre", "release_date"],
        >>>    sortable_attributes=["title", "release_date"],
        >>> )
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_settings(new_settings)
    """
    body_dict = {
        k: v
        for k, v in body.model_dump(by_alias=True, exclude_none=True).items()
        if v is not None
    }
    response = self._http_requests.patch(self._settings_url, body_dict, compress=compress)

    return TaskInfo(**response.json())

update_sortable_attributes(sortable_attributes, *, compress=False)

Get sortable attributes of the AsyncIndex.

Parameters:

Name Type Description Default
sortable_attributes list[str]

List of attributes for searching.

required
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_sortable_attributes(["title", "release_date"])

Source code in meilisearch_python_sdk/index.py
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
def update_sortable_attributes(
    self, sortable_attributes: list[str], *, compress: bool = False
) -> TaskInfo:
    """Get sortable attributes of the AsyncIndex.

    Args:
        sortable_attributes: List of attributes for searching.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_sortable_attributes(["title", "release_date"])
    """
    response = self._http_requests.put(
        f"{self._settings_url}/sortable-attributes", sortable_attributes, compress=compress
    )

    return TaskInfo(**response.json())

update_stop_words(body, *, compress=False)

Update stop words of the index.

Parameters:

Name Type Description Default
body list[str]

List containing the stop words of the index.

required
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_stop_words(["the", "a", "an"])

Source code in meilisearch_python_sdk/index.py
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
def update_stop_words(self, body: list[str], *, compress: bool = False) -> TaskInfo:
    """Update stop words of the index.

    Args:
        body: List containing the stop words of the index.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_stop_words(["the", "a", "an"])
    """
    response = self._http_requests.put(
        f"{self._settings_url}/stop-words", body, compress=compress
    )

    return TaskInfo(**response.json())

update_synonyms(body, *, compress=False)

Update synonyms of the index.

Parameters:

Name Type Description Default
body dict[str, list[str]]

The synonyms of the index.

required

Returns:

Type Description
TaskInfo

The details of the task status.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") as client: >>> index = client.index("movies") >>> index.update_synonyms( >>> {"wolverine": ["xmen", "logan"], "logan": ["wolverine"]} >>> )

Source code in meilisearch_python_sdk/index.py
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
def update_synonyms(self, body: dict[str, list[str]], *, compress: bool = False) -> TaskInfo:
    """Update synonyms of the index.

    Args:
        body: The synonyms of the index.

    Returns:
        The details of the task status.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey") as client:
        >>> index = client.index("movies")
        >>> index.update_synonyms(
        >>>     {"wolverine": ["xmen", "logan"], "logan": ["wolverine"]}
        >>> )
    """
    response = self._http_requests.put(
        f"{self._settings_url}/synonyms", body, compress=compress
    )

    return TaskInfo(**response.json())

update_typo_tolerance(typo_tolerance, *, compress=False)

Update typo tolerance.

Parameters:

Name Type Description Default
typo_tolerance TypoTolerance

Typo tolerance settings.

required
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

Task to track the action.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> TypoTolerance(enabled=False) >>> index.update_typo_tolerance()

Source code in meilisearch_python_sdk/index.py
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
def update_typo_tolerance(
    self, typo_tolerance: TypoTolerance, *, compress: bool = False
) -> TaskInfo:
    """Update typo tolerance.

    Args:
        typo_tolerance: Typo tolerance settings.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        Task to track the action.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> TypoTolerance(enabled=False)
        >>> index.update_typo_tolerance()
    """
    response = self._http_requests.patch(
        f"{self._settings_url}/typo-tolerance",
        typo_tolerance.model_dump(by_alias=True),
        compress=compress,
    )

    return TaskInfo(**response.json())

update_word_dictionary(dictionary, *, compress=False)

Update the word dictionary settings for an index.

Parameters:

Name Type Description Default
dictionary list[str]

List of dictionary values.

required
compress bool

If set to True the data will be sent in gzip format. Defaults to False.

False

Returns:

Type Description
TaskInfo

Task to track the action.

Raises:

Type Description
MeilisearchCommunicationError

If there was an error communicating with the server.

MeilisearchApiError

If the Meilisearch API returned an error.

Examples >>> from meilisearch_python_sdk import Client >>> client = Client("http://localhost.com", "masterKey") >>> index = client.index("movies") >>> index.update_word_dictionary(dictionary=["S.O.S", "S.O")

Source code in meilisearch_python_sdk/index.py
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
def update_word_dictionary(self, dictionary: list[str], *, compress: bool = False) -> TaskInfo:
    """Update the word dictionary settings for an index.

    Args:
        dictionary: List of dictionary values.
        compress: If set to True the data will be sent in gzip format. Defaults to False.

    Returns:
        Task to track the action.

    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 Client
        >>> client = Client("http://localhost.com", "masterKey")
        >>> index = client.index("movies")
        >>> index.update_word_dictionary(dictionary=["S.O.S", "S.O")
    """
    response = self._http_requests.put(
        f"{self._settings_url}/dictionary", dictionary, compress=compress
    )

    return TaskInfo(**response.json())