Meilisearch FastAPI предоставляет маршруты FastAPI для взаимодействия с Meilisearch.
Для установки этого пакета рекомендуется использовать виртуальную среду. После создания и активации виртуальной среды установите пакет с помощью:
pip install meilisearch-fastapi
Маршруты разделены на группы, чтобы можно было вводить разные зависимости и, следовательно, разные уровни доступа к разным группам маршрутов.
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 )
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 )
URL-адрес Meilisearch, следует использовать адрес https и ключ API считываются из переменных среды. Поместив их в файл .env, вам не придется устанавливать эти переменные каждый раз при перезапуске терминала.
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
Теперь маршруты Meilisearch будут доступны в вашем приложении FastAPI. Документацию по маршрутам можно просмотреть в документации OpenAPI приложения FastAPI. Чтобы просмотреть это, запустите приложение FastAPI и перейдите к документации http://localhost:8000/docs
заменив URL-адрес правильным URL-адресом вашего приложения.
Вклад в этот проект приветствуется. Если вы заинтересованы в том, чтобы внести свой вклад, ознакомьтесь с нашим руководством по участию.