A Django-based web application that efficiently streams and displays CSV data in real-time using server-sent events (SSE). The application provides a smooth user experience by loading CSV data progressively without overwhelming the browser's memory.
- Real-time CSV data streaming
- Server-sent events (SSE) implementation
- Progressive data loading
- Responsive table display
- Error handling and validation
- Python 3.8 or higher
- Django 4.2.2
-
Clone the repository:
git clone <repository-url> cd <project-directory>
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: .\venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Run migrations:
python manage.py migrate
-
Start the development server:
python manage.py runserver
-
Access the application:
- Open your browser and navigate to
http://localhost:8000/stream/?file=your_file.csv - Replace
your_file.csvwith the name of your CSV file (must be placed in thedatadirectory)
- Open your browser and navigate to
├── csvstreamer/ # Project configuration
├── data/ # CSV files directory
├── streamer/ # Main application
│ ├── templates/ # HTML templates
│ └── views.py # Application views
├── manage.py # Django management script
└── requirements.txt # Project dependencies
- URL:
/stream/ - Method: GET
- Query Parameters:
file: Name of the CSV file to stream (required)
- Response: Server-sent events stream
- Content Type:
text/event-stream
- Returns 400 Bad Request if:
- CSV file parameter is missing
- Specified CSV file is not found
- Returns appropriate error message in the stream if:
- File reading encounters an error
- CSV parsing fails
- Place your CSV files in the
datadirectory - The application automatically detects CSV headers
- Data is streamed in chunks for optimal performance
- The application only serves files from the
datadirectory - File paths are validated to prevent directory traversal
- Debug mode should be disabled in production
This project is licensed under the MIT License - see the LICENSE file for details.