meilisearch fastapi
v0.20.0
Meilisearch FastAPI 提供與Meilisearch 互動的FastAPI 路由。
建議使用虛擬環境來安裝此軟體包。創建並啟動虛擬環境後,使用以下命令安裝軟體包:
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 )
Meilisearch 的 url、是否應使用 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 應用程式中可用。可以在 FastAPI 應用程式的 OpenAPI 文件中查看路由的文件。要查看此內容,請啟動 FastAPI 應用程式並導航至文件http://localhost:8000/docs
將 url 替換為應用程式的正確 url。
歡迎對此項目做出貢獻。如果您有興趣貢獻,請參閱我們的貢獻指南