Package: meilisearch-python-sdk
Meilisearch Python SDKNOTE: This project was previously namedmeilisearch-python-async. Development on
that project continues here under the new name.Meilisearch Python SDK provides both an async and sync client for theMeilisearchAPI.Which client to use depends on your use case. If the code base you are working with uses asyncio,
for example if you are usingFastAPI, choose theAsyncClient,
otherwise choose the syncClient. The functionality of the two clients is the same, the difference
being that theAsyncClientprovides async methods and uses theAsyncIndexwith its own
additional async methods. On the other hand,Clientprovides blocking methods and uses theIndexwith its own blocking methods.InstallationUsing a virtual environment is recommended for installing this package. Once the virtual
environment is created and activated, install the package with:pipinstallmeilisearch-python-sdkRun MeilisearchThere are several ways torun Meilisearch.
Pick the one that works best for your use case and then start the server.As as example to use Docker:dockerpullgetmeili/meilisearch:latest
dockerrun-it--rm-p7700:7700getmeili/meilisearch:latest./meilisearch--master-key=masterKeyUsageAdd DocumentsAsyncClientNote: `client.index("books") creates an instance of an AsyncIndex object but does not make a
network call to send the data yet so it does not need to be awaited.frommeilisearch_python_sdkimportAsyncClientasyncwithAsyncClient('http://127.0.0.1:7700','masterKey')asclient:index=client.index("books")documents=[{"id":1,"title":"Ready Player One"},{"id":42,"title":"The Hitchhiker's Guide to the Galaxy"},]awaitindex.add_documents(documents)Clientfrommeilisearch_python_sdkimportClientclient=Client('http://127.0.0.1:7700','masterKey')index=client.index("books")documents=[{"id":1,"title":"Ready Player One"},{"id":42,"title":"The Hitchhiker's Guide to the Galaxy"},]index.add_documents(documents)The server will return an update id that can be used toget the statusof the updates. To do this you would save the result response from adding the documents to a
variable, this will be anUpdateIdobject, and use it to check the status of the updates.AsyncClientupdate=awaitindex.add_documents(documents)status=awaitclient.index('books').get_update_status(update.update_id)Clientupdate=index.add_documents(documents)status=client.index('books').get_update_status(update.update_id)Basic SearchingAsyncClientsearch_result=awaitindex.search("ready player")Clientsearch_result=index.search("ready player")Base Search Results: SearchResults object with valuesSearchResults(hits=[{"id":1,"title":"Ready Player One",},],offset=0,limit=20,nb_hits=1,exhaustive_nb_hits=bool,facets_distributionn=None,processing_time_ms=1,query="ready player",)Custom SearchInformation about the parameters can be found in thesearch parameterssection
of the documentation.AsyncClientawaitindex.search("guide",attributes_to_highlight=["title"],filters="book_id > 10")Clientindex.search("guide",attributes_to_highlight=["title"],filters="book_id > 10")Custom Search Results: SearchResults object with valuesSearchResults(hits=[{"id":42,"title":"The Hitchhiker's Guide to the Galaxy","_formatted":{"id":42,"title":"The Hitchhiker's Guide to the <em>Galaxy</em>"}},],offset=0,limit=20,nb_hits=1,exhaustive_nb_hits=bool,facets_distributionn=None,processing_time_ms=5,query="galaxy",)BenchmarkThe following benchmarks compare this library to the officialMeilisearch Pythonlibrary. Note that all
of the performance gains seen with theAsyncClientare achieved by taking advantage of asyncio.
This means that if your code is not taking advantage of asyncio or it does not block the event loop,
the gains here will not be seen and the performance between the clients will be very similar.Add Documents in BatchesThis test compares how long it takes to send 1 million documents in batches of 1 thousand to the
Meilisearch server for indexing (lower is better). The time does not take into account how long
Meilisearch takes to index the documents since that is outside of the library functionality.Muiltiple SearchesThis test compares how long it takes to complete 1000 searches (lower is better)Independent testingPrashanth Raodid some independent testing and found this async client
to be ~30% faster than the sync client for data ingestion. You can find a good write-up of the
results how he tested them in hisblog post.Testingpytest-meilisearchis a pytest plugin that can
help with testing your code. It provides a lot of the boiler plate code you will need.DocumentationSee ourdocsfor the full documentation.ContributingContributions to this project are welcome. If you are interested in contributing please see ourcontributing guide