MeiliSearch integration with FastAPI
Project description
MeiliSearch FastAPI
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 require 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 import 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 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.
MEILISEARCH_URL=http://localhost:7700 # This is the url for your instance of MeiliSearch
MEILISEARCH_API_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 fast api app and naviate to the docs http://127.0.0.1:8000/docs
replacing hte url with the correct url for your app.
Contributing
Contributions to this project are welcome. If you are interesting in contributing please see our contributing guide
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file meilisearch-fastapi-0.1.1.tar.gz
.
File metadata
- Download URL: meilisearch-fastapi-0.1.1.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.9.5 Linux/5.4.0-1047-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e79b70c48c3d4eeea93e853d5ea84dbefe1cb0ae3f12605be6a9a016b7193372 |
|
MD5 | dff5cf45f9fcf4f3f1a8271fd5c77199 |
|
BLAKE2b-256 | a83e0c05951d154a3dfaff2649debbb330248c7fe28dac5f61f1000a747973bc |
File details
Details for the file meilisearch_fastapi-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: meilisearch_fastapi-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.9.5 Linux/5.4.0-1047-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf2787912e443882a059f19db4d59f7fd3e49efa43ca84bc23edd82db0d422b4 |
|
MD5 | db1eca30327c9257db1cf3390b2c40a5 |
|
BLAKE2b-256 | 8032a692dfbafed843f55e27d3db6a1f3be8e0653311f2c5ca92069e56bf42ff |