Demonstrates pagination of Algolia results in Streamlit and on-demand Algolia index updates right from the Streamlit app.
Tech Stack:
- Streamlit for Python-based UI
- Algolia for search functionality
- Supabase for database operations (can be replaced with any database)
Implements a book search interface using Streamlit for the UI, Algolia for search, and Supabase for data persistence. Search includes:
- Typo tolerance and instant results
- Pagination of search results
- Caching to reduce API calls
- Real-time index synchronization on data changes
- Error handling and edge cases
Dataset: 27,000+ book records from Kaggle's Books dataset
Before you begin, ensure you have:
- Python 3.10+ installed
- An Algolia account (Sign up for free)
- A Supabase project (Create one here)
# If you have git installed
git clone https://github.com/SiddhantSadangi/streamlit_algolia.git
cd algolia
# Or download and extract the project folderCreate a virtual environment (recommended):
# On Windows
python -m venv venv
venv\Scripts\activate
# On macOS/Linux
python3 -m venv venv
source venv/bin/activateInstall required packages:
pip install -r requirements.txt-
Sign up for Supabase at https://supabase.com/dashboard
-
Create a new project
-
Navigate to the Table Editor in Supabase dashboard
-
Create the books table by uploading the
books.csvfile. Use ISBN as the primary key. -
Get your Supabase credentials:
- Navigate to Project Settings β API
- Copy your Project URL
- Copy your anon/public key
-
Sign up for Algolia at https://www.algolia.com/users/sign_up
-
Create a new application in your Algolia dashboard
-
Note your credentials:
- Application ID
- Write API Key (needed for updating the index)
- In your Algolia dashboard, go to Data Sources
- Click Add a data source β Select Supabase
- Configure the connection:
- Trigger: On demand (or set up automatic triggers)
- Indexing strategy: Full record updates
- Source table:
books - Destination index:
books_dataset - Map fields from your books table to Algolia index. Use
ISBNas the ObjectID.
- Run the initial sync to populate your Algolia index
Create a .streamlit folder in your project root if it doesn't exist:
mkdir .streamlitCreate a secrets.toml file in the .streamlit folder:
# .streamlit/secrets.toml
# Supabase Configuration
SUPABASE_URL = "https://your-project.supabase.co"
SUPABASE_KEY = "your-anon-key-here"
# Algolia Configuration
ALGOLIA_APP_ID = "your-app-id-here"
ALGOLIA_API_KEY = "your-write-api-key-here"Replace the placeholders with your actual credentials from Steps 3 and 4.
Warning
Never commit secrets.toml to version control. It is already in .gitignore.
streamlit run app.pyThe app will open in your default browser at http://localhost:8501
- Enter a search query in the main search box (e.g., "Harry Potter", "Mystery", "Crichton")
- View results with pagination controls
- Use the pagination buttons to navigate through multiple pages
- Click "Raw results" to see the full API response
-
Add a Book:
- Enter ISBN and title in the sidebar
- Click "Add/Update Book"
- The book will be added to both Supabase and Algolia in real-time
-
Update a Book:
- Enter the ISBN of an existing book
- Enter a new title or year of publication
- Click "Add/Update Book" (uses upsert logic)
- Only this one record is updated in Algolia, not the entire index
-
Delete a Book:
- Enter the ISBN
- Click "Delete Book"
- The book will be removed from both systems immediately
-
View Current Books:
- Check the dataframe at the bottom of the sidebar
- Shows all books currently in the database