Giter Site home page Giter Site logo

ameilisearch's Introduction

ameiliSearch

Asynchronous MeiliSearch API client that is 100% compatible with MeiliSearch Python

upstream commit hash: e665923efc9735fd09994b0f01395ceb29051c71

Getting Started

Add Documents

import asyncio
import ameilisearch


async def main():
    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'] },
    ]

    async with ameilisearch.Client("http://127.0.0.1:7700", 'masterKey') as client:
        async with client.index("movies") as index:
            # If the index 'movies' does not exist, MeiliSearch creates it when you first add the documents.
            await index.add_documents(documents) # => { "updateId": 0 }

asyncio.get_event_loop().run_until_complete(main())

Differences from synchronous clients

Existing API clients worked with requests.

ameilisearch works with aiohttp.

Users need to manage client sessions.

The http instance is in two places: Client and Index.

Use the async with syntax to close the session immediately after use, or must close the session using await :client_or_index_instance:.http.session.close() after using it all.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.