meilisearch-python-sdk


Namemeilisearch-python-sdk JSON
Version 3.6.2 PyPI version JSON
download
home_pageNone
SummaryA Python client providing both async and sync support for the Meilisearch API
upload_time2024-11-27 20:54:36
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT License Copyright (c) 2021 Paul Sanders Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords async client meilisearch python sdk
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Meilisearch Python SDK

[![Tests Status](https://github.com/sanders41/meilisearch-python-sdk/workflows/Testing/badge.svg?branch=main&event=push)](https://github.com/sanders41/meilisearch-python-sdk/actions?query=workflow%3ATesting+branch%3Amain+event%3Apush)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/sanders41/meilisearch-python-sdk/main.svg)](https://results.pre-commit.ci/latest/github/sanders41/meilisearch-python-sdk/main)
[![Coverage](https://codecov.io/github/sanders41/meilisearch-python-sdk/coverage.svg?branch=main)](https://codecov.io/gh/sanders41/meilisearch-python-sdk)
[![PyPI version](https://badge.fury.io/py/meilisearch-python-sdk.svg)](https://badge.fury.io/py/meilisearch-python-sdk)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/meilisearch-python-sdk?color=5cc141)](https://github.com/sanders41/meilisearch-python-sdk)

Meilisearch Python SDK provides both an async and sync client for the
[Meilisearch](https://github.com/meilisearch/meilisearch) API.

Which client to use depends on your use case. If the code base you are working with uses asyncio,
for example if you are using [FastAPI](https://fastapi.tiangolo.com/), choose the `AsyncClient`,
otherwise choose the sync `Client`. The functionality of the two clients is the same, the difference
being that the `AsyncClient` provides async methods and uses the `AsyncIndex` with its own
additional async methods. On the other hand, `Client` provides blocking methods and uses the `Index`
with its own blocking methods.

## Installation

Using a virtual environment is recommended for installing this package. Once the virtual
environment is created and activated, install the package with:

```sh
pip install meilisearch-python-sdk
```

## Run Meilisearch

There are several ways to
[run Meilisearch](https://www.meilisearch.com/docs/learn/getting_started/installation).
Pick the one that works best for your use case and then start the server.

As as example to use Docker:

```sh
docker pull getmeili/meilisearch:latest
docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey
```

## Usage

### Add Documents

#### AsyncClient

- Note: `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.

```py
from meilisearch_python_sdk import AsyncClient

async with AsyncClient('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)
```

#### Client

```py
from meilisearch_python_sdk import Client

client = 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 to
[get the status](https://www.meilisearch.com/docs/reference/api/tasks#status)
of the updates. To do this you would save the result response from adding the documents to a
variable, this will be an `UpdateId` object, and use it to check the status of the updates.

#### AsyncClient

```py
update = await index.add_documents(documents)
status = await client.index('books').get_update_status(update.update_id)
```

#### Client

```py
update = index.add_documents(documents)
status = client.index('books').get_update_status(update.update_id)
```

### Basic Searching

#### AsyncClient

```py
search_result = await index.search("ready player")
```

#### Client

```py
search_result = index.search("ready player")
```

### Base Search Results: SearchResults object with values

```py
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](https://docs.meilisearch.com/reference/features/search_parameters.html) section
of the documentation.

#### AsyncClient

```py
await index.search(
    "guide",
    attributes_to_highlight=["title"],
    filters="book_id > 10"
)
```

#### Client

```py
index.search(
    "guide",
    attributes_to_highlight=["title"],
    filters="book_id > 10"
)
```

### Custom Search Results: SearchResults object with values

```py
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",
)
```

## Benchmark

The following benchmarks compare this library to the official
[Meilisearch Python](https://github.com/meilisearch/meilisearch-python) library. Note that all
of the performance gains seen with the `AsyncClient` are 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 Batches

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

![Add Documents in Batches](https://raw.githubusercontent.com/sanders41/meilisearch-python-sdk/main/assets/add_in_batches.png)

### Muiltiple Searches

This test compares how long it takes to complete 1000 searches (lower is better)

![Multiple Searches](https://raw.githubusercontent.com/sanders41/meilisearch-python-sdk/main/assets/searches.png)

### Independent testing

[Prashanth Rao](https://github.com/prrao87) did 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 his [blog post](https://thedataquarry.com/posts/meilisearch-async/).

## Testing

[pytest-meilisearch](https://github.com/sanders41/pytest-meilisearch) is a pytest plugin that can
help with testing your code. It provides a lot of the boiler plate code you will need.

## Documentation

See our [docs](https://meilisearch-python-sdk.paulsanders.dev) for the full documentation.

## Contributing

Contributions to this project are welcome. If you are interested in contributing please see our
[contributing guide](CONTRIBUTING.md)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "meilisearch-python-sdk",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "async, client, meilisearch, python, sdk",
    "author": null,
    "author_email": "Paul Sanders <paul@paulsanders.dev>",
    "download_url": "https://files.pythonhosted.org/packages/bc/c8/4374a0367adcc3b0db38d0b0c174df2c14434dc0ae72d1ceae3afbe3542e/meilisearch_python_sdk-3.6.2.tar.gz",
    "platform": null,
    "description": "# Meilisearch Python SDK\n\n[![Tests Status](https://github.com/sanders41/meilisearch-python-sdk/workflows/Testing/badge.svg?branch=main&event=push)](https://github.com/sanders41/meilisearch-python-sdk/actions?query=workflow%3ATesting+branch%3Amain+event%3Apush)\n[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/sanders41/meilisearch-python-sdk/main.svg)](https://results.pre-commit.ci/latest/github/sanders41/meilisearch-python-sdk/main)\n[![Coverage](https://codecov.io/github/sanders41/meilisearch-python-sdk/coverage.svg?branch=main)](https://codecov.io/gh/sanders41/meilisearch-python-sdk)\n[![PyPI version](https://badge.fury.io/py/meilisearch-python-sdk.svg)](https://badge.fury.io/py/meilisearch-python-sdk)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/meilisearch-python-sdk?color=5cc141)](https://github.com/sanders41/meilisearch-python-sdk)\n\nMeilisearch Python SDK provides both an async and sync client for the\n[Meilisearch](https://github.com/meilisearch/meilisearch) API.\n\nWhich client to use depends on your use case. If the code base you are working with uses asyncio,\nfor example if you are using [FastAPI](https://fastapi.tiangolo.com/), choose the `AsyncClient`,\notherwise choose the sync `Client`. The functionality of the two clients is the same, the difference\nbeing that the `AsyncClient` provides async methods and uses the `AsyncIndex` with its own\nadditional async methods. On the other hand, `Client` provides blocking methods and uses the `Index`\nwith its own blocking methods.\n\n## Installation\n\nUsing a virtual environment is recommended for installing this package. Once the virtual\nenvironment is created and activated, install the package with:\n\n```sh\npip install meilisearch-python-sdk\n```\n\n## Run Meilisearch\n\nThere are several ways to\n[run Meilisearch](https://www.meilisearch.com/docs/learn/getting_started/installation).\nPick the one that works best for your use case and then start the server.\n\nAs as example to use Docker:\n\n```sh\ndocker pull getmeili/meilisearch:latest\ndocker run -it --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey\n```\n\n## Usage\n\n### Add Documents\n\n#### AsyncClient\n\n- Note: `client.index(\"books\") creates an instance of an AsyncIndex object but does not make a\n  network call to send the data yet so it does not need to be awaited.\n\n```py\nfrom meilisearch_python_sdk import AsyncClient\n\nasync with AsyncClient('http://127.0.0.1:7700', 'masterKey') as client:\n    index = client.index(\"books\")\n\n    documents = [\n        {\"id\": 1, \"title\": \"Ready Player One\"},\n        {\"id\": 42, \"title\": \"The Hitchhiker's Guide to the Galaxy\"},\n    ]\n\n    await index.add_documents(documents)\n```\n\n#### Client\n\n```py\nfrom meilisearch_python_sdk import Client\n\nclient = Client('http://127.0.0.1:7700', 'masterKey')\nindex = client.index(\"books\")\n\ndocuments = [\n    {\"id\": 1, \"title\": \"Ready Player One\"},\n    {\"id\": 42, \"title\": \"The Hitchhiker's Guide to the Galaxy\"},\n]\n\nindex.add_documents(documents)\n```\n\nThe server will return an update id that can be used to\n[get the status](https://www.meilisearch.com/docs/reference/api/tasks#status)\nof the updates. To do this you would save the result response from adding the documents to a\nvariable, this will be an `UpdateId` object, and use it to check the status of the updates.\n\n#### AsyncClient\n\n```py\nupdate = await index.add_documents(documents)\nstatus = await client.index('books').get_update_status(update.update_id)\n```\n\n#### Client\n\n```py\nupdate = index.add_documents(documents)\nstatus = client.index('books').get_update_status(update.update_id)\n```\n\n### Basic Searching\n\n#### AsyncClient\n\n```py\nsearch_result = await index.search(\"ready player\")\n```\n\n#### Client\n\n```py\nsearch_result = index.search(\"ready player\")\n```\n\n### Base Search Results: SearchResults object with values\n\n```py\nSearchResults(\n    hits = [\n        {\n            \"id\": 1,\n            \"title\": \"Ready Player One\",\n        },\n    ],\n    offset = 0,\n    limit = 20,\n    nb_hits = 1,\n    exhaustive_nb_hits = bool,\n    facets_distributionn = None,\n    processing_time_ms = 1,\n    query = \"ready player\",\n)\n```\n\n### Custom Search\n\nInformation about the parameters can be found in the\n[search parameters](https://docs.meilisearch.com/reference/features/search_parameters.html) section\nof the documentation.\n\n#### AsyncClient\n\n```py\nawait index.search(\n    \"guide\",\n    attributes_to_highlight=[\"title\"],\n    filters=\"book_id > 10\"\n)\n```\n\n#### Client\n\n```py\nindex.search(\n    \"guide\",\n    attributes_to_highlight=[\"title\"],\n    filters=\"book_id > 10\"\n)\n```\n\n### Custom Search Results: SearchResults object with values\n\n```py\nSearchResults(\n    hits = [\n        {\n            \"id\": 42,\n            \"title\": \"The Hitchhiker's Guide to the Galaxy\",\n            \"_formatted\": {\n                \"id\": 42,\n                \"title\": \"The Hitchhiker's Guide to the <em>Galaxy</em>\"\n            }\n        },\n    ],\n    offset = 0,\n    limit = 20,\n    nb_hits = 1,\n    exhaustive_nb_hits = bool,\n    facets_distributionn = None,\n    processing_time_ms = 5,\n    query = \"galaxy\",\n)\n```\n\n## Benchmark\n\nThe following benchmarks compare this library to the official\n[Meilisearch Python](https://github.com/meilisearch/meilisearch-python) library. Note that all\nof the performance gains seen with the `AsyncClient` are achieved by taking advantage of asyncio.\nThis means that if your code is not taking advantage of asyncio or it does not block the event loop,\nthe gains here will not be seen and the performance between the clients will be very similar.\n\n### Add Documents in Batches\n\nThis test compares how long it takes to send 1 million documents in batches of 1 thousand to the\nMeilisearch server for indexing (lower is better). The time does not take into account how long\nMeilisearch takes to index the documents since that is outside of the library functionality.\n\n![Add Documents in Batches](https://raw.githubusercontent.com/sanders41/meilisearch-python-sdk/main/assets/add_in_batches.png)\n\n### Muiltiple Searches\n\nThis test compares how long it takes to complete 1000 searches (lower is better)\n\n![Multiple Searches](https://raw.githubusercontent.com/sanders41/meilisearch-python-sdk/main/assets/searches.png)\n\n### Independent testing\n\n[Prashanth Rao](https://github.com/prrao87) did some independent testing and found this async client\nto be ~30% faster than the sync client for data ingestion. You can find a good write-up of the\nresults how he tested them in his [blog post](https://thedataquarry.com/posts/meilisearch-async/).\n\n## Testing\n\n[pytest-meilisearch](https://github.com/sanders41/pytest-meilisearch) is a pytest plugin that can\nhelp with testing your code. It provides a lot of the boiler plate code you will need.\n\n## Documentation\n\nSee our [docs](https://meilisearch-python-sdk.paulsanders.dev) for the full documentation.\n\n## Contributing\n\nContributions to this project are welcome. If you are interested in contributing please see our\n[contributing guide](CONTRIBUTING.md)\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2021 Paul Sanders  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "A Python client providing both async and sync support for the Meilisearch API",
    "version": "3.6.2",
    "project_urls": {
        "documentation": "https://meilisearch-python-sdk.paulsanders.dev",
        "homepage": "https://github.com/sanders41/meilisearch-python-sdk",
        "repository": "https://github.com/sanders41/meilisearch-python-sdk"
    },
    "split_keywords": [
        "async",
        " client",
        " meilisearch",
        " python",
        " sdk"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "cd37e4a34da1e9723d4e23095b5109a174b152a171da6f48e469390f51110668",
                "md5": "0b21a6ea435dc8de34b2952399bf644a",
                "sha256": "9fda670b980d8288c06e835dcb7f5d336563c2556a37687f5b5b26bc181676a5"
            },
            "downloads": -1,
            "filename": "meilisearch_python_sdk-3.6.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0b21a6ea435dc8de34b2952399bf644a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 58170,
            "upload_time": "2024-11-27T20:54:35",
            "upload_time_iso_8601": "2024-11-27T20:54:35.175309Z",
            "url": "https://files.pythonhosted.org/packages/cd/37/e4a34da1e9723d4e23095b5109a174b152a171da6f48e469390f51110668/meilisearch_python_sdk-3.6.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "bcc84374a0367adcc3b0db38d0b0c174df2c14434dc0ae72d1ceae3afbe3542e",
                "md5": "34ab8c9f4bd10ec14f465f515c677bd4",
                "sha256": "565b7b83179db6f221692d780d83e396f9d77e9e5a6ce3623b543c161194141b"
            },
            "downloads": -1,
            "filename": "meilisearch_python_sdk-3.6.2.tar.gz",
            "has_sig": false,
            "md5_digest": "34ab8c9f4bd10ec14f465f515c677bd4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 224734,
            "upload_time": "2024-11-27T20:54:36",
            "upload_time_iso_8601": "2024-11-27T20:54:36.989457Z",
            "url": "https://files.pythonhosted.org/packages/bc/c8/4374a0367adcc3b0db38d0b0c174df2c14434dc0ae72d1ceae3afbe3542e/meilisearch_python_sdk-3.6.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-27 20:54:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sanders41",
    "github_project": "meilisearch-python-sdk",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "meilisearch-python-sdk"
}
        
Elapsed time: 0.88486s