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。
欢迎对此项目做出贡献。如果您有兴趣贡献,请参阅我们的贡献指南