Skip to main content

The MeiliSearch API asyncio client for Python

Project description

AioMeiliSearch

The MeiliSearch API asyncio client for Python

Introduction

AioMeilisearch is a asynchronous python client for MeiliSearch.

MeiliSearch is an open source, blazingly fast and hyper relevant search-engine. For more information about features in this documentation.

Summary

MeiliSearch's API is a standard RESTful HTTP API, so it comes with SDKs for all kinds of programing languages. One official python client is called meilisearch-python, it does a good job, with a great python http library called requests.

async/await is new feature of python3.4+. In some cases we need to support this feature, so here we are.

AioMeilisearch supprts async/await, writed with aiohttp.

Any python api in the MeiliSearch officia document has a awaitable version by AioMeilisearch.

Feature

  • async/await

Requirements

  • python3.6+
  • aiohttp

Installation

pip3 install aiomeilisearch

Usage

Index

import aiomeilisearch

client = aiomeilisearch.Client('http://127.0.0.1:7700', 'masterKey')

async def create_index():
    # create a index, with primaryKey "id"
    # An index is where the documents are stored.
    return await client.create_index('movies', {'primaryKey': 'id'})

index = await create_index()

Documents

async def add_documents():
    # add documents to index
    documents = [
          { 'id': 1, 'title': 'Carol', 'genres': ['Romance', 'Drama'] },
          { 'id': 2, 'title': 'Wonder Woman', 'genres': ['Action', 'Adventure'] },
          { 'id': 3, 'title': 'Life of Pi', 'genres': ['Adventure', 'Drama'] },
          { 'id': 4, 'title': 'Mad Max: Fury Road', 'genres': ['Adventure', 'Science Fiction'] },
          { 'id': 5, 'title': 'Moana', 'genres': ['Fantasy', 'Action']},
          { 'id': 6, 'title': 'Philadelphia', 'genres': ['Drama'] },
    ]
    await index.add_documents(documents) 

Get a document

await index.get_document(1)

Search documents

await client.index("movies").search('飞天大盗')
await client.index("movies").search('The Great Gatsby', filter=["is_tv=True", ["year=1925", "year=2013"]])

settings

await client.index('movies').get_settings()
await client.index('movies').update_displayed_attributes(["id", 'title', 'year'])
await client.index('movies').update_filterable_attributes(["year", 'is_tv'])
await client.index('movies').update_searchable_attributes(['title', 'original_title', ])
...

Demos

https://github.com/ziyoubaba/aiomeilisearch/tree/main/demos

Documentation

  • MeiliSearch all the python apis here. Don't forget 'await'.
  • AioMeilisearch, Maybe later...

License

Under MIT license.

Changelog

version 1.0.0

welcom contribution

Source code

The latest developer version is available in a GitHub repository: https://github.com/ziyoubaba/aiomeilisearch

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page