CSV Editor App
This project is a web-based CSV editor built using FastHTML, HTMX, and SQLite.
Key Technologies and Techniques
- FastHTML: A Python-based framework for building web applications with a focus on web fundamentals.
- HTMX: Used to create dynamic server-side content updates that let you interact with the app without page reloads.
- SQLite: A lightweight, serverless database used to store and manage CSV data.
- FastSQL: A library that simplifies database operations and integrates well with FastHTML.
- httpx: An asynchronous HTTP client for Python, used to fetch example CSV data.
How It Works
Server-Side Logic
The app uses FastHTML to define routes and handle CSV operations. Key routes include:
GET /
: The main page that renders the CSV upload interface.
GET /get_test_file
: Provides an example CSV file for download.
POST /upload
: Handles CSV file uploads and displays the data.
POST /update
: Updates individual CSV rows.
DELETE /remove
: Deletes specific rows from the CSV data.
GET /download
: Allows downloading the current CSV data.
Data Management
CSV data is stored in an SQLite database:
- A unique table is created for each session, storing the CSV data with an 'id' column as the primary key.
Dynamic Content
HTMX is used to create a dynamic user interface:
hx-post
attribute on the upload button triggers a POST request to upload and display CSV data.
hx-delete
and hx-post
attributes on row buttons handle row deletion and updates.
hx-target
specifies where the response from the server should be inserted.
hx-swap
determines how the new content should be added or replaced.
hx-include
is used to include specific form data in requests.
Key Features
- CSV Upload: Users can upload CSV files to view and edit the data.
- Example CSV: An example CSV file is provided for download.
- Data Display: Uploaded CSV data is displayed in an editable table format.
- Row Editing: Each row can be updated or deleted individually.
- Data Download: The current state of the CSV data can be downloaded at any time.
- Session Management: Each user session has its own unique data storage.
- File Size Limit: Only the first 50 rows of a CSV file are processed and displayed.
This CSV Editor app demonstrates how FastHTML and HTMX can be combined to create a responsive, server-side web application for data manipulation tasks.