Skip to content

tofran/fastapi-htmx-full-text-search-demo

Repository files navigation

Python FastAPI HTMX full-text-search demo

This project is a demo full-text-search application that compares the results from SQLite FT5 and Algolia Search platform.

Conceived as an experimental venture, this project serves as a demonstration of an unconventional monolith tech stack. It features an interactive front-end, using a mix of traditional Server Side Rendering (SSR) declarative web framework with zero custom JS:

  • FastAPI the server framework;
  • Jinja for the SSR templating;
  • HTMX to enable front-end interactivity declaratively directly in the HTML.

Description and demo

Live demo (the server goes to sleep, give at least 30s for a cold start)

app-preview.mp4

The outcome of this project is something very simple and minimal. The served content is tiny and fast. There's no initial loading, everything is pre-rendered on the server, and each API request renders HTML that is injected into the DOM - no need for Hydration, Resumability nor even data serialization. It is compatible with most browsers, all the way back to IE11, where it struggles a little with style, but works.

OpenAPI spec (swagger)

The application works by serving a full rendered Jinja HTML template when the user navigates to a Front-End route. These templates are composed via smaller reusable templates (using include). And then the templates (components) are also served, de-coupled from the whole page in the HTML API (/html-api/...). HTMX handles the rest, listens to DOM events and updates it when when necessary.

Example HTML API request/response

Development

  • Create a .env file based on the .env.template.
    You will need an Algolia account, more info in their Quick start guide.
    More information about the env vars can be found in ./text_search_app/config.py

  • Setup a local environment with make setup-venv, activate it with source ./venv/bin/activate (or with your favourite tool).

  • Install dependencies: make install-dev.

  • Start the development server: make dev.

Deployment

For deployment one would use the ./Dockerfile and set the required environment variables.

For running locally a production like build, install the dependencies with make install and run the application with make start. That's it.

Uploading a dataset

To keep this repository clean, no sample data is provided. You can upload your own data via the /index/upload-csv endpoint. Information about the supported CSV columns available in the Swagger UI (/docs).

Recommended datasets (adapt column names when needed):

License

MIT

About

🔎 Python FastAPI HTMX full-text-search demo using SQLite FTS5 and Algolia search.

Topics

Resources

License

Stars

Watchers

Forks