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 に置き換えます。
このプロジェクトへの貢献は大歓迎です。貢献に興味がある場合は、貢献ガイドをご覧ください。