Skip to main content

MeiliSearch integration with FastAPI

Project description

MeiliSearch FastAPI

CI Status pre-commit.ci status Coverage PyPI version PyPI - Python Version

MeiliSearch FastAPI provides FastAPI routes for interacting with MeiliSearch.

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-fastapi

Useage

Routes are split in groups so that different dependencies can be injected, and therefore different levels of access, can be given to different groups of routes.

Example with no authentication require for routes

from fastapi import APIRouter, FastAPI
from meilisearch_fastapi.routes import (
    document_routes,
    index_routes,
    meilisearch_routes,
    search_routes,
    settings_routes,
)

app = FastAPI()
api_router = APIRouter()
api_router.include_router(document_routes.router, prefix="/documents")
api_router.include_router(index_routes.router, prefix="/indexes")
api_router.include_router(meilisearch_routes.router, prefix="/meilisearch")
api_router.include_router(search_routes.router, prefix="/search")
api_router.include_router(settings_routes.router, prefix="/settings")

app.include_router(api_router)

Example with routes requiring authentication

from fastapi import APIRouter, FastAPI
from meilisearch_fastapi import routes

from my_app import my_authentication

app = FastAPI()
api_router = APIRouter()
api_router.include_router(document_routes.router, prefix="/documents", dependeincies=[Depends(my_authentication)])
api_router.include_router(index_routes.router, prefix="/indexes", dependeincies=[Depends(my_authentication)])
api_router.include_router(meilisearch_routes.router, prefix="/meilisearch", dependeincies=[Depends(my_authentication)])
api_router.include_router(search_routes.router, prefix="/search", dependeincies=[Depends(my_authentication)])
api_router.include_router(settings_routes.router, prefix="/settings", dependeincies=[Depends(my_authentication)])

app.include_router(api_router)

The url for MeiliSearch and API key are read from environment variables. Putting these into a .env file will keep you from having to set these variables each time the terminal is restarted.

MEILISEARCH_URL=http://localhost:7700  # This is the url for your instance of MeiliSearch
MEILISEARCH_API_KEY=masterKey  # This is the API key for your MeiliSearch instance

Now the MeiliSearch routes will be available in your FastAPI app. Documentation for the routes can be viewed in the OpenAPI documentation of the FastAPI app. To view this start your FastAPI app and naviate to the docs http://localhost:8000/docs replacing the url with the correct url for your app.

Compatibility with MeiliSearch

This package only guarantees the compatibility with version v0.20.0 of MeiliSearch.

Contributing

Contributions to this project are welcome. If you are interesting in contributing please see our contributing guide

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

meilisearch-fastapi-0.5.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

meilisearch_fastapi-0.5.1-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file meilisearch-fastapi-0.5.1.tar.gz.

File metadata

  • Download URL: meilisearch-fastapi-0.5.1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.9.5 Linux/5.8.0-1036-azure

File hashes

Hashes for meilisearch-fastapi-0.5.1.tar.gz
Algorithm Hash digest
SHA256 91c3198e6f442f35a4e94933ed2d0d323154b45129e55e149158c5a0abfcad42
MD5 41a0484ffe0a82fa8e3807cf3dc680e1
BLAKE2b-256 04dc6fe6e65c1998e5ae368e677790dd85ee655d2d858da6a7f5b9908b0e1266

See more details on using hashes here.

File details

Details for the file meilisearch_fastapi-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for meilisearch_fastapi-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a6608b4b693e6b36a5fd764ae3d307b12ebcaf4761f0d05501fb83799569530d
MD5 7ebc2fada7d1d88b938e3081b3789b60
BLAKE2b-256 90fab8b31a862e799f5b8f201b7f51838af6df7e3e8c79b1bea44b0425dfca2e

See more details on using hashes here.

Supported by

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