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 required 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.routes import (
    document_routes,
    index_routes,
    meilisearch_routes,
    search_routes,
    settings_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, weather an https address should be used, 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.

MEILI_HTTP_ADDR=localhost:7700  # This is the url for your instance of Meilisearch
MEILI_HTTPS_URL=true  # Setting this specifies the address should be https://. If false or not included the address will be http://
MEILI_MASTER_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.

Contributing

Contributions to this project are welcome. If you are interested 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.21.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

meilisearch_fastapi-0.21.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file meilisearch_fastapi-0.21.0.tar.gz.

File metadata

  • Download URL: meilisearch_fastapi-0.21.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.12 Linux/6.11.0-1014-azure

File hashes

Hashes for meilisearch_fastapi-0.21.0.tar.gz
Algorithm Hash digest
SHA256 22144be54e3b16d397be313ba55ede4658a9f9b803df7bd1e4a985d189ddb619
MD5 1969c548768576b545ac17b2f5ed50c4
BLAKE2b-256 2d3ec186f739ae807c983b475aa58d7efea403e192596563c8609d9c896287b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for meilisearch_fastapi-0.21.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c907f0bd970fcf490278f332d216c66a9f42dde3f6aab28852895dce52260508
MD5 e6676a10c8dc749be7800d8cd1c1c964
BLAKE2b-256 baa9c4c41ec0c642d869542340113fd554aeaa59545c2e4c51c9fbef2f0b78f1

See more details on using hashes here.

Supported by

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