A Python async client for the Meilisearch API
Project description
Meilisearch Python Async
Meilisearch Python Async is a Python async client for the Meilisearch API. Meilisearch also has an official Python client.
Which of the two clients to use comes down to your particular use case. The purpose for this async client is to allow for non-blocking calls when working in async frameworks such as FastAPI, or if your own code base you are working in is async. If this does not match your use case then the official client will be a better choice.
Installation
Using a virtual environmnet is recommended for installing this package. Once the virtual environment is created and activated install the package with:
pip install meilisearch-python-async
Run Meilisearch
There are several ways to run Meilisearch. Pick the one that works best for your use case and then start the server.
As as example to use Docker:
docker pull getmeili/meilisearch:latest
docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey
Useage
Add Documents
- Note: `client.index("books") creates an instance of an Index object but does not make a network call to send the data yet so it does not need to be awaited.
from meilisearch_python_async import Client
async with Client('http://127.0.0.1:7700', 'masterKey') as client:
index = client.index("books")
documents = [
{"id": 1, "title": "Ready Player One"},
{"id": 42, "title": "The Hitchhiker's Guide to the Galaxy"},
]
await index.add_documents(documents)
The server will return an update id that can be used to get the status of the updates. To do this you would save the result response from adding the documets to a variable, this will be a UpdateId object, and use it to check the status of the updates.
update = await index.add_documents(documents)
status = await client.index('books').get_update_status(update.update_id)
Basic Searching
search_result = await index.search("ready player")
Base Search Results: SearchResults object with values
SearchResults(
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 Search
Information about the parameters can be found in the search parameters section of the documentation.
index.search(
"guide",
attributes_to_highlight=["title"],
filters="book_id > 10"
)
Custom Search Results: SearchResults object with values
SearchResults(
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",
)
Documentation
See our docs for the full documentation.
Contributing
Contributions to this project are welcome. If you are interesting in contributing please see our contributing guide
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for meilisearch_python_async-1.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | afea7951e581f95b6d8ab6a73ef4f5abfd3d1699f3fea33cef652062ccfbdad6 |
|
MD5 | 773c39abece7bd0980c861015bbbd10b |
|
BLAKE2b-256 | f2f771d71f390ffd125f3753421d33fef7879acebdeb0d17e5e1c9af49ebc04a |
Hashes for meilisearch_python_async-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 107f3dad7c4b7a9aca05704f36e59580616802a7104ea44d80e299bff320b514 |
|
MD5 | 39ff9ae4412bff01324f0f787453c247 |
|
BLAKE2b-256 | 3eb89d51f7e9ee642b25b54658d1e4cb63442001c6b5aa7ef50ede33c4554368 |