A Django service that accepts a CSV file, validates it against a PostgreSQL table's schema, and inserts the rows efficiently using PostgreSQL COPY.
This README explains how to run the project locally with Conda and via Docker Compose.
conda env create -f environment.yml
conda activate django-csvDJANGO_SECRET_KEY=dev-secret
DJANGO_DEBUG=True
DB_NAME=csv_demo
DB_USER=csv_user
DB_PASSWORD=csvpass
DB_HOST=127.0.0.1
DB_PORT=5432docker run -d --name pg \
-p 5432:5432 \
-e POSTGRES_USER=csv_user \
-e POSTGRES_PASSWORD=csvpass \
-e POSTGRES_DB=csv_demo \
postgres:16python manage.py migratepython manage.py runserverAPI is available at http://localhost:8000
docker-compose up --builddocker-compose downAPI is available at http://localhost:8000
Endpoint: POST /api/upload-csv/
| Field | Description |
|---|---|
table_name |
Name of target PostgreSQL table |
file |
CSV file |
strict |
true or false |
Example request:
curl -X POST http://localhost:8000/api/upload-csv/ \
-F "table_name=products" \
-F "strict=true" \
-F "[email protected]"To run tests navigate to home directory and run: python manage.py test